Merge branch 'features1.4/wallet' into develop-1.4
This commit is contained in:
commit
7ccee4168f
|
@ -35,6 +35,11 @@ public class ChannelClientWrapper {
|
||||||
this.fabricClientWrapper=fabricClientWrapper;
|
this.fabricClientWrapper=fabricClientWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<ProposalResponse> queryByChainCode(QueryByChaincodeRequest queryByChaincodeRequest) throws InvalidArgumentException, ProposalException {
|
||||||
|
return channel.queryByChaincode(queryByChaincodeRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Collection<ProposalResponse> queryByChainCode(String chaincodeName,String fuctionName, String[] args) throws InvalidArgumentException, ProposalException {
|
public Collection<ProposalResponse> queryByChainCode(String chaincodeName,String fuctionName, String[] args) throws InvalidArgumentException, ProposalException {
|
||||||
QueryByChaincodeRequest request = fabricClientWrapper.getClient().newQueryProposalRequest();
|
QueryByChaincodeRequest request = fabricClientWrapper.getClient().newQueryProposalRequest();
|
||||||
ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(chaincodeName).build();
|
ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(chaincodeName).build();
|
||||||
|
|
|
@ -39,5 +39,4 @@ public class FabricClientWrapper {
|
||||||
Peer peer = client.newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
Peer peer = client.newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||||
return client.queryChannels(peer);
|
return client.queryChannels(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,49 +5,54 @@ import blockchain.client.FabricClientWrapper;
|
||||||
import blockchain.configuration.Config;
|
import blockchain.configuration.Config;
|
||||||
import blockchain.user.UserContext;
|
import blockchain.user.UserContext;
|
||||||
import blockchain.utility.Util;
|
import blockchain.utility.Util;
|
||||||
|
import org.apache.log4j.BasicConfigurator;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.hyperledger.fabric.sdk.ChaincodeID;
|
||||||
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
||||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
import org.hyperledger.fabric.sdk.ProposalResponse;
|
||||||
|
import org.hyperledger.fabric.sdk.QueryByChaincodeRequest;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class QueryWrapper {
|
public class QueryWrapper {
|
||||||
|
private static Logger logger = Logger.getLogger(QueryWrapper.class);
|
||||||
|
|
||||||
public String getUserBalance(String userHashId){
|
public String sendQuery(String functionName,String[] args) {
|
||||||
|
BasicConfigurator.configure();
|
||||||
|
UserContext user = Util.readUserContext(Config.ORG1, "admin");
|
||||||
String response = null;
|
String response = null;
|
||||||
try{
|
|
||||||
UserContext userContext = Util.readUserContext(Config.ORG1,"User-org1");
|
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
||||||
|
|
||||||
String[] args = {userHashId};
|
ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||||
|
QueryByChaincodeRequest queryByChaincodeRequest = fabricClientWrapper.getClient().newQueryProposalRequest();
|
||||||
|
queryByChaincodeRequest.setArgs(args);
|
||||||
|
queryByChaincodeRequest.setFcn(functionName);
|
||||||
|
queryByChaincodeRequest.setChaincodeID(chaincodeID);
|
||||||
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"query",args);
|
Collection<ProposalResponse> queryProposals;
|
||||||
for(ProposalResponse pres : responseQuery){
|
|
||||||
ChaincodeResponse.Status status = pres.getStatus();
|
try {
|
||||||
if(status.getStatus()!=200){
|
queryProposals = channelClientWrapper.queryByChainCode(queryByChaincodeRequest);
|
||||||
throw new Exception(pres.getMessage());
|
} catch (Exception e) {
|
||||||
|
throw new Exception(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
response = new String(pres.getChaincodeActionResponsePayload());
|
for (ProposalResponse proposalResponse : queryProposals) {
|
||||||
|
if (!proposalResponse.isVerified() || proposalResponse.getStatus() != ChaincodeResponse.Status.SUCCESS) {
|
||||||
|
logger.error("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status : " + proposalResponse.getStatus() +
|
||||||
|
". Message : " + proposalResponse.getMessage() + ". Was verified : " + proposalResponse.isVerified());
|
||||||
|
} else {
|
||||||
|
response = new String(proposalResponse.getChaincodeActionResponsePayload());
|
||||||
|
logger.info("Query payload : " + response + " from peer : " + proposalResponse.getPeer().getName());
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(response==null) response = "Error";
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUser(String userHashId){
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getUserLastTransactions(String userHashId){
|
|
||||||
List<String> transactions = new ArrayList<>();
|
|
||||||
return transactions;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,36 +5,65 @@ import blockchain.client.FabricClientWrapper;
|
||||||
import blockchain.configuration.Config;
|
import blockchain.configuration.Config;
|
||||||
import blockchain.user.UserContext;
|
import blockchain.user.UserContext;
|
||||||
import blockchain.utility.Util;
|
import blockchain.utility.Util;
|
||||||
import org.hyperledger.fabric.sdk.BlockEvent;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.hyperledger.fabric.sdk.ChaincodeID;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
import org.hyperledger.fabric.sdk.*;
|
||||||
import org.hyperledger.fabric.sdk.TransactionProposalRequest;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class TransactionWrapper {
|
public class TransactionWrapper {
|
||||||
|
private static Logger logger = Logger.getLogger(TransactionWrapper.class);
|
||||||
|
|
||||||
|
public BlockEvent.TransactionEvent sendTransaction(String functionName, String[] args){
|
||||||
|
BasicConfigurator.configure();
|
||||||
|
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
||||||
|
|
||||||
public String sendTransaction(String from, String to, String amount){
|
|
||||||
try{
|
try{
|
||||||
UserContext userContext = Util.readUserContext(Config.ORG1,"User-org1");
|
Collection<ProposalResponse> successful = new LinkedList<>();
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
Collection<ProposalResponse> failed = new LinkedList<>();
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
FabricClientWrapper fabricClientWrapper;
|
||||||
|
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
if(user != null){
|
||||||
|
fabricClientWrapper = new FabricClientWrapper(user);
|
||||||
|
} else {
|
||||||
|
throw new Exception("No UserContext");
|
||||||
|
}
|
||||||
|
|
||||||
|
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
||||||
|
|
||||||
|
//INIT CHANNEL FOR QUERY
|
||||||
|
Channel channel = channelClientWrapper.getChannel();
|
||||||
|
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
||||||
|
channel.addOrderer(orderer);
|
||||||
|
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
||||||
|
channel.addPeer(peer);
|
||||||
|
channel.initialize();
|
||||||
|
//
|
||||||
|
|
||||||
|
//Prepare transaction
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
||||||
tpr.setChaincodeID(cid);
|
tpr.setChaincodeID(cid);
|
||||||
tpr.setFcn("invoke");
|
tpr.setFcn(functionName);
|
||||||
tpr.setArgs(new String[]{from,to,amount});
|
tpr.setArgs(args);
|
||||||
|
tpr.setProposalWaitTime(120000);
|
||||||
|
|
||||||
Collection<ProposalResponse> responses = channelClientWrapper.sendTransactionProposal(tpr);
|
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr); //Send proposal transaction
|
||||||
System.out.println("VERIFY HERE, TRY TO SEND TRANSACTION");
|
for(ProposalResponse response : invokePropResp){
|
||||||
BlockEvent.TransactionEvent event = channelClientWrapper.sendTransaction(responses);
|
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
||||||
|
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
||||||
|
successful.add(response);
|
||||||
|
} else {
|
||||||
|
failed.add(response);
|
||||||
|
logger.info("Failed transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return event.getTransactionID();
|
|
||||||
|
|
||||||
}catch (Exception e){
|
return channelClientWrapper.sendTransaction(successful); //Send successful transaction to orderer
|
||||||
|
|
||||||
|
} catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,12 @@ import blockchain.query.QueryWrapper;
|
||||||
|
|
||||||
public class BlockchainQueryImplementation {
|
public class BlockchainQueryImplementation {
|
||||||
|
|
||||||
|
/*
|
||||||
public Double getUserBalance(String userHash){
|
public Double getUserBalance(String userHash){
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
String result = queryWrapper.getUserBalance(userHash);
|
String result = queryWrapper.getUserBalance(userHash);
|
||||||
Double balance = Double.parseDouble(result);
|
Double balance = Double.parseDouble(result);
|
||||||
return balance;
|
return balance;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import restImplementation.BlockchainQueryImplementation;
|
||||||
@RequestMapping(value = "/api/rest/query")
|
@RequestMapping(value = "/api/rest/query")
|
||||||
public class BlockchainQueryResource {
|
public class BlockchainQueryResource {
|
||||||
|
|
||||||
|
/*
|
||||||
@RequestMapping(value = "/balance", method = RequestMethod.GET ,params = {"userHash"},produces = "application/json")
|
@RequestMapping(value = "/balance", method = RequestMethod.GET ,params = {"userHash"},produces = "application/json")
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public ResponseEntity<StringResponse> getUserBalance(@RequestParam(value = "userHash") String userHash){
|
public ResponseEntity<StringResponse> getUserBalance(@RequestParam(value = "userHash") String userHash){
|
||||||
|
@ -23,6 +24,7 @@ public class BlockchainQueryResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
package blockchain.query;
|
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.hyperledger.fabric.sdk.*;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
//Test for transaction
|
|
||||||
@Ignore
|
|
||||||
public class ChaincodeTransactionTest {
|
|
||||||
private static Logger logger = Logger.getLogger(ChaincodeTransactionTest.class);
|
|
||||||
@Test
|
|
||||||
public void TestATransaction(){
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
|
|
||||||
//UserContext user = Util.readUserContext(Config.ORG1,"User-org1");
|
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
|
||||||
|
|
||||||
try{
|
|
||||||
|
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
//OLD PEER
|
|
||||||
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
|
|
||||||
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
|
|
||||||
//Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
channel.addPeer(peer);
|
|
||||||
channel.addEventHub(eventHub);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("invoke");
|
|
||||||
tpr.setArgs(new String[]{"b","a","25"}); //send 20 from a to b
|
|
||||||
|
|
||||||
Collection<ProposalResponse> responses = channel.sendTransactionProposal(tpr);
|
|
||||||
List<ProposalResponse> invalid = responses.stream().filter(r -> r.isInvalid()).collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (!invalid.isEmpty()) {
|
|
||||||
invalid.forEach(response -> {
|
|
||||||
logger.error(response.getMessage());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
logger.info("SEND TRANSACTION");
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(responses).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
package blockchain.query;
|
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.hyperledger.fabric.sdk.*;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
//Test to create user on chaincode -> don't work, can't use function "Init"
|
|
||||||
@Ignore
|
|
||||||
public class CreateChaincodeUserTest {
|
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestCreateUser(){
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
|
||||||
|
|
||||||
try{
|
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
//OLD
|
|
||||||
//Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG_PEER,Config.ORG_PEER_URL);
|
|
||||||
//EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", Config.ORG_PEER_EVENT_URL);
|
|
||||||
//Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
EventHub eventHub = fabricClientWrapper.getClient().newEventHub("eventhub01", "grpc://vps577432.ovh.net:8053");
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
|
|
||||||
channel.addPeer(peer);
|
|
||||||
channel.addEventHub(eventHub);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
String[] args = {"user1","200","user2","180"};
|
|
||||||
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"init",args);
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
|
||||||
ChaincodeResponse.Status status = pres.getStatus();
|
|
||||||
if(status.getStatus()!=200){
|
|
||||||
throw new Exception(pres.getMessage());
|
|
||||||
}
|
|
||||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
||||||
logger.info("RESPONSE : "+stringResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +1,32 @@
|
||||||
package blockchain.query;
|
package blockchain.query;
|
||||||
|
|
||||||
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.client.FabricClientWrapper;
|
||||||
import blockchain.configuration.Config;
|
import blockchain.configuration.Config;
|
||||||
import blockchain.user.UserContext;
|
import blockchain.user.UserContext;
|
||||||
import blockchain.utility.Util;
|
import blockchain.utility.Util;
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.Peer;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
//Test to show channels on a node
|
//Test to show channels on a node
|
||||||
@Ignore
|
@Ignore
|
||||||
public class QueryChannelTest {
|
public class QueryChannelTest {
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
private static Logger logger = Logger.getLogger(QueryChannelTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQ(){
|
public void TestQueryForChannels(){
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext userContext = Util.readUserContext(Config.ORG1,"admin");
|
UserContext userContext = Util.readUserContext(Config.ORG1,"admin");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(userContext);
|
||||||
Set<String> channels = fabricClientWrapper.queryForChannels();
|
Set<String> channels = fabricClientWrapper.queryForChannels();
|
||||||
|
|
||||||
logger.info("CHANNELS : "+channels);
|
logger.info("CHANNELS : "+channels);
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
package blockchain.query;
|
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.hyperledger.fabric.sdk.*;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
|
|
||||||
//Test to get balance of a User
|
|
||||||
@Ignore
|
|
||||||
public class QueryTest {
|
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestAQuery() {
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
|
|
||||||
//UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
|
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
|
||||||
|
|
||||||
//String[] args1 = {"a"};
|
|
||||||
String[] args1 = {"chef"};
|
|
||||||
//String[] args1 = {"bitman"};
|
|
||||||
//String[] args1 = {"user_test"};
|
|
||||||
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"query",args1);
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
|
||||||
ChaincodeResponse.Status status = pres.getStatus();
|
|
||||||
if(status.getStatus()!=200){
|
|
||||||
throw new Exception(pres.getMessage());
|
|
||||||
}
|
|
||||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
||||||
logger.info("RESPONSE : "+stringResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,79 +1,27 @@
|
||||||
package blockchain.query.Transaction;
|
package blockchain.query.Transaction;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.TransactionWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.*;
|
import org.hyperledger.fabric.sdk.*;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class TransactionTest {
|
public class TransactionTest {
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
private static Logger logger = Logger.getLogger(TransactionTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestQueryWalletHistory() {
|
public void TestTransaction() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
String functionName = "transaction";
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
String[] args = new String[]{"qerh654d5f5h46q4fdh6h65fh00","qerh654d5f5hdsf1515","200"};
|
||||||
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
logger.info("userContext : "+user.getName());
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
channel.addPeer(peer);
|
|
||||||
|
|
||||||
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
//CONTROL
|
|
||||||
logger.info("channel INIT : "+channel.isInitialized());
|
|
||||||
for(Peer p : channel.getPeers()){
|
|
||||||
Set<String> channels = fabricClientWrapper.getClient().queryChannels(peer);
|
|
||||||
logger.info("channels "+channels);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("transaction");
|
|
||||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00","qerh654d5f5h46q4fdh6h65fh01","200"}); //1 foutre to bitman
|
|
||||||
tpr.setProposalWaitTime(120000);
|
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
|
||||||
for(ProposalResponse response : invokePropResp){
|
|
||||||
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
|
||||||
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
|
||||||
successful.add(response);
|
|
||||||
} else {
|
|
||||||
failed.add(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
|
||||||
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
package blockchain.query.User;
|
package blockchain.query.User;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.TransactionWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.*;
|
import org.hyperledger.fabric.sdk.*;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class DeleteUserTest {
|
public class DeleteUserTest {
|
||||||
|
@ -22,57 +16,12 @@ public class DeleteUserTest {
|
||||||
@Test
|
@Test
|
||||||
public void TestDeleteUser() {
|
public void TestDeleteUser() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
String functionName = "deleteUser";
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
String[] args = new String[]{"usera"};
|
||||||
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
logger.info("userContext : "+user.getName());
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
channel.addPeer(peer);
|
|
||||||
|
|
||||||
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
//CONTROL
|
|
||||||
logger.info("channel INIT : "+channel.isInitialized());
|
|
||||||
for(Peer p : channel.getPeers()){
|
|
||||||
Set<String> channels = fabricClientWrapper.getClient().queryChannels(peer);
|
|
||||||
logger.info("channels "+channels);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("deleteUser");
|
|
||||||
tpr.setArgs(new String[]{"UserA"});
|
|
||||||
tpr.setProposalWaitTime(120000);
|
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
|
||||||
for(ProposalResponse response : invokePropResp){
|
|
||||||
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
|
||||||
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
|
||||||
successful.add(response);
|
|
||||||
} else {
|
|
||||||
failed.add(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
|
||||||
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,70 +1,39 @@
|
||||||
package blockchain.query.User;
|
package blockchain.query.User;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.QueryWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
|
||||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.json.Json;
|
import javax.json.Json;
|
||||||
import javax.json.JsonObject;
|
import javax.json.JsonObject;
|
||||||
import javax.json.JsonReader;
|
import javax.json.JsonReader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class ReadUserTest {
|
public class ReadUserTest {
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
private static Logger logger = Logger.getLogger(ReadUserTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestQueryReadUser() {
|
public void TestQueryReadUser() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
String functionName = "readUser";
|
||||||
|
String[] args = new String[]{"usera"};
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
String response = queryWrapper.sendQuery(functionName,args);
|
||||||
|
if(response != null){
|
||||||
//String[] args1 = {"chef"}
|
|
||||||
//String[] args1 = {"bitman"};
|
|
||||||
//String[] args1 = {"foutre"};
|
|
||||||
String[] args1 = {"usera"};
|
|
||||||
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readUser",args1);
|
|
||||||
logger.info("RESPONSE : "+responseQuery);
|
|
||||||
logger.info("RESPONSE : "+responseQuery.size());
|
|
||||||
|
|
||||||
String response = null;
|
|
||||||
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
|
||||||
ChaincodeResponse.Status status = pres.getStatus();
|
|
||||||
|
|
||||||
if(status.getStatus()!=200){
|
|
||||||
throw new Exception(pres.getMessage());
|
|
||||||
}
|
|
||||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
||||||
response = stringResponse;
|
|
||||||
logger.info("RESPONSE : "+stringResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonReader reader = Json.createReader(new StringReader(response));
|
JsonReader reader = Json.createReader(new StringReader(response));
|
||||||
JsonObject userInfo = reader.readObject();
|
JsonObject userInfo = reader.readObject();
|
||||||
logger.info("userAssociation : "+userInfo.getString("userAssociation"));
|
logger.info("userAssociation : "+userInfo.getString("userAssociation"));
|
||||||
logger.info("userFirstName : "+userInfo.getString("userFirstName"));
|
logger.info("userFirstName : "+userInfo.getString("userFirstName"));
|
||||||
|
} else {
|
||||||
|
throw new Exception("Response is null");
|
||||||
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,75 +1,28 @@
|
||||||
package blockchain.query.User;
|
package blockchain.query.User;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.TransactionWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.*;
|
import org.hyperledger.fabric.sdk.*;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class RegisterUserTest {
|
public class RegisterUserTest {
|
||||||
|
private static Logger logger = Logger.getLogger(RegisterUserTest.class);
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestRegisterUser() {
|
public void TestRegisterUser() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,Config.ADMIN);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
String functionName = "registerUser";
|
||||||
|
String[] args = new String[]{"usera","Thomas","MEUNIER","0000000000","gonette"};
|
||||||
logger.info("userContext : "+user.getName());
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
channel.addPeer(peer);
|
|
||||||
|
|
||||||
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("registerUser");
|
|
||||||
tpr.setArgs(new String[]{"usera","Thomas","MEUNIER","0000000000","gonette"});
|
|
||||||
tpr.setProposalWaitTime(120000);
|
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
|
||||||
for(ProposalResponse response : invokePropResp){
|
|
||||||
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
|
||||||
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
|
||||||
successful.add(response);
|
|
||||||
} else {
|
|
||||||
failed.add(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
|
||||||
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
package blockchain.query.User;
|
package blockchain.query.User;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.TransactionWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.*;
|
import org.hyperledger.fabric.sdk.*;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class UserPermissionTest {
|
public class UserPermissionTest {
|
||||||
|
@ -23,60 +16,14 @@ public class UserPermissionTest {
|
||||||
@Test
|
@Test
|
||||||
public void TestUserPermission() {
|
public void TestUserPermission() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
String functionName = "setUserPermission";
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
String[] args = new String[]{"usera"};
|
||||||
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
logger.info("userContext : "+user.getName());
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
channel.addPeer(peer);
|
|
||||||
|
|
||||||
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
//CONTROL
|
|
||||||
logger.info("channel INIT : "+channel.isInitialized());
|
|
||||||
for(Peer p : channel.getPeers()){
|
|
||||||
Set<String> channels = fabricClientWrapper.getClient().queryChannels(peer);
|
|
||||||
logger.info("channels "+channels);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("setUserPermission");
|
|
||||||
tpr.setArgs(new String[]{"UserA"});
|
|
||||||
tpr.setProposalWaitTime(120000);
|
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
|
||||||
for(ProposalResponse response : invokePropResp){
|
|
||||||
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
|
||||||
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
|
||||||
successful.add(response);
|
|
||||||
} else {
|
|
||||||
failed.add(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
|
||||||
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
package blockchain.query.Wallet;
|
package blockchain.query.Wallet;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.TransactionWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.*;
|
import org.hyperledger.fabric.sdk.*;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class DeleteWalletTest {
|
public class DeleteWalletTest {
|
||||||
|
@ -22,64 +16,14 @@ public class DeleteWalletTest {
|
||||||
@Test
|
@Test
|
||||||
public void TestDeleteWallet() {
|
public void TestDeleteWallet() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
|
String functionName = "deleteWallet";
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
String[] args = new String[]{"qerh654d5f5hdsf1515"};
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
|
|
||||||
logger.info("userContext : "+user.getName());
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
channel.addPeer(peer);
|
|
||||||
|
|
||||||
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
//CONTROL
|
|
||||||
logger.info("channel INIT : "+channel.isInitialized());
|
|
||||||
for(Peer p : channel.getPeers()){
|
|
||||||
Set<String> channels = fabricClientWrapper.getClient().queryChannels(peer);
|
|
||||||
logger.info("channels "+channels);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("deleteWallet");
|
|
||||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00"});
|
|
||||||
tpr.setProposalWaitTime(120000);
|
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
|
||||||
for(ProposalResponse response : invokePropResp){
|
|
||||||
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
|
||||||
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
|
||||||
successful.add(response);
|
|
||||||
} else {
|
|
||||||
failed.add(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
|
||||||
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
package blockchain.query.Wallet;
|
package blockchain.query.Wallet;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.TransactionWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.query.User.UserPermissionTest;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.*;
|
import org.hyperledger.fabric.sdk.BlockEvent;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class InitWalletTest {
|
public class InitWalletTest {
|
||||||
|
@ -23,60 +16,12 @@ public class InitWalletTest {
|
||||||
@Test
|
@Test
|
||||||
public void TestInitWallet() {
|
public void TestInitWallet() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
String functionName = "initWallet";
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
String[] args = new String[]{"qerh654d5f5hdsf1515","client","usera"};
|
||||||
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
logger.info("userContext : "+user.getName());
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
channel.addPeer(peer);
|
|
||||||
|
|
||||||
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
//CONTROL
|
|
||||||
logger.info("channel INIT : "+channel.isInitialized());
|
|
||||||
for(Peer p : channel.getPeers()){
|
|
||||||
Set<String> channels = fabricClientWrapper.getClient().queryChannels(peer);
|
|
||||||
logger.info("channels "+channels);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("initWallet");
|
|
||||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00","client","bitman"});
|
|
||||||
//tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh01","client","foutre"});
|
|
||||||
tpr.setProposalWaitTime(120000);
|
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
|
||||||
for(ProposalResponse response : invokePropResp){
|
|
||||||
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
|
||||||
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
|
||||||
successful.add(response);
|
|
||||||
} else {
|
|
||||||
failed.add(response);
|
|
||||||
logger.info("failed "+response.getChaincodeActionResponsePayload());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
|
||||||
|
|
||||||
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,51 +1,29 @@
|
||||||
package blockchain.query.Wallet;
|
package blockchain.query.Wallet;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.QueryWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
|
||||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class QueryWalletByOwnerTest {
|
public class QueryWalletByOwnerTest {
|
||||||
private static Logger logger = Logger.getLogger(QueryWalletByOwnerTest.class);
|
private static Logger logger = Logger.getLogger(QueryWalletByOwnerTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestQueryWallet() {
|
public void TestQueryWalletByOwnerTest() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
String functionName = "queryWalletsByOwner";
|
||||||
|
String[] args = new String[]{"usera"};
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
//String[] args = new String[]{"bitman"};
|
||||||
|
String response = queryWrapper.sendQuery(functionName,args);
|
||||||
String[] args1 = {"bitman"};
|
logger.info("response : "+response);
|
||||||
//String[] args1 = {"usera"};
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"queryWalletsByOwner",args1);
|
|
||||||
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
|
||||||
ChaincodeResponse.Status status = pres.getStatus();
|
|
||||||
if(status.getStatus()!=200){
|
|
||||||
throw new Exception(pres.getMessage());
|
|
||||||
}
|
|
||||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
||||||
logger.info("RESPONSE : "+stringResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +1,26 @@
|
||||||
package blockchain.query.Wallet;
|
package blockchain.query.Wallet;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.QueryWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
|
||||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class QueryWalletByTypeTest {
|
public class QueryWalletByTypeTest {
|
||||||
private static Logger logger = Logger.getLogger(QueryWalletByTypeTest.class);
|
private static Logger logger = Logger.getLogger(QueryWalletByTypeTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestQueryWallet() {
|
public void TestQueryWalletByTypeTest() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
String functionName = "queryWalletsByType";
|
||||||
|
String[] args = new String[]{"client"};
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
String response = queryWrapper.sendQuery(functionName,args);
|
||||||
|
logger.info("response : "+response);
|
||||||
String[] args1 = {"client"};
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"queryWalletsByType",args1);
|
|
||||||
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
|
||||||
ChaincodeResponse.Status status = pres.getStatus();
|
|
||||||
if(status.getStatus()!=200){
|
|
||||||
throw new Exception(pres.getMessage());
|
|
||||||
}
|
|
||||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
||||||
logger.info("RESPONSE : "+stringResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +1,28 @@
|
||||||
package blockchain.query.Wallet;
|
package blockchain.query.Wallet;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.QueryWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
|
||||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class QueryWalletHistory {
|
public class QueryWalletHistory {
|
||||||
private static Logger logger = Logger.getLogger(QueryTest.class);
|
private static Logger logger = Logger.getLogger(QueryWalletHistory.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestQueryWalletHistory() {
|
public void TestQueryWalletHistory() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
String functionName = "getHistoryForWallet";
|
||||||
|
String[] args = new String[]{"qerh654d5f5hdsf1515"};
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
String response = queryWrapper.sendQuery(functionName,args);
|
||||||
|
logger.info("response : "+response);
|
||||||
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh2"};
|
|
||||||
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh"};
|
|
||||||
String[] args1 = {"qerh654d5f5h46q4fdh6h65fh00"};
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"getHistoryForWallet",args1);
|
|
||||||
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
|
||||||
ChaincodeResponse.Status status = pres.getStatus();
|
|
||||||
if(status.getStatus()!=200){
|
|
||||||
throw new Exception(pres.getMessage());
|
|
||||||
}
|
|
||||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
||||||
logger.info("RESPONSE : "+stringResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +1,28 @@
|
||||||
package blockchain.query.Wallet;
|
package blockchain.query.Wallet;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.QueryWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.query.QueryTest;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.ChaincodeResponse;
|
|
||||||
import org.hyperledger.fabric.sdk.ProposalResponse;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class ReadWalletTest {
|
public class ReadWalletTest {
|
||||||
private static Logger logger = Logger.getLogger(ReadWalletTest.class);
|
private static Logger logger = Logger.getLogger(ReadWalletTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestQueryWallet() {
|
public void TestReadWalletTest() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
String functionName = "readWallet";
|
||||||
|
String[] args = new String[]{"qerh654d5f5hdsf1515"};
|
||||||
ChannelClientWrapper channelClientWrapper = ChannelClientWrapper.setupChannel(fabricClientWrapper);
|
String response = queryWrapper.sendQuery(functionName,args);
|
||||||
|
logger.info("response : "+response);
|
||||||
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh2"};
|
|
||||||
String[] args1 = {"qerh654d5f5h46q4fdh6h65fh00"};
|
|
||||||
//String[] args1 = {"qerh654d5f5h46q4fdh6h65fh01"};
|
|
||||||
Collection<ProposalResponse> responseQuery = channelClientWrapper.queryByChainCode(chaincode,"readWallet",args1);
|
|
||||||
|
|
||||||
for(ProposalResponse pres : responseQuery){
|
|
||||||
ChaincodeResponse.Status status = pres.getStatus();
|
|
||||||
if(status.getStatus()!=200){
|
|
||||||
throw new Exception(pres.getMessage());
|
|
||||||
}
|
|
||||||
String stringResponse = new String(pres.getChaincodeActionResponsePayload());
|
|
||||||
logger.info("RESPONSE : "+stringResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
package blockchain.query.Wallet;
|
package blockchain.query.Wallet;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.TransactionWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.*;
|
import org.hyperledger.fabric.sdk.*;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class SetWalletSoldTest {
|
public class SetWalletSoldTest {
|
||||||
|
@ -22,59 +16,12 @@ public class SetWalletSoldTest {
|
||||||
@Test
|
@Test
|
||||||
public void TestSetWalletSold() {
|
public void TestSetWalletSold() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
String functionName = "setSoldOnWallet";
|
||||||
|
String[] args = new String[]{"qerh654d5f5hdsf1515","500"};
|
||||||
logger.info("userContext : "+user.getName());
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
channel.addPeer(peer);
|
|
||||||
|
|
||||||
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
//CONTROL
|
|
||||||
logger.info("channel INIT : "+channel.isInitialized());
|
|
||||||
for(Peer p : channel.getPeers()){
|
|
||||||
Set<String> channels = fabricClientWrapper.getClient().queryChannels(peer);
|
|
||||||
logger.info("channels "+channels);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("setSoldOnWallet");
|
|
||||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00","3000"});
|
|
||||||
//tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh01","100"});
|
|
||||||
tpr.setProposalWaitTime(120000);
|
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
|
||||||
for(ProposalResponse response : invokePropResp){
|
|
||||||
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
|
||||||
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
|
||||||
successful.add(response);
|
|
||||||
} else {
|
|
||||||
failed.add(response);
|
|
||||||
logger.info("failed "+response.getChaincodeActionResponsePayload());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
|
||||||
|
|
||||||
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,83 +1,30 @@
|
||||||
package blockchain.query.Wallet;
|
package blockchain.query.Wallet;
|
||||||
|
|
||||||
import blockchain.client.ChannelClientWrapper;
|
|
||||||
import blockchain.client.FabricClientWrapper;
|
import blockchain.query.TransactionWrapper;
|
||||||
import blockchain.configuration.Config;
|
|
||||||
import blockchain.user.UserContext;
|
|
||||||
import blockchain.utility.Util;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.hyperledger.fabric.sdk.*;
|
import org.hyperledger.fabric.sdk.*;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public class TransferWalletTest {
|
public class TransferWalletTest {
|
||||||
private static Logger logger = Logger.getLogger(DeleteWalletTest.class);
|
private static Logger logger = Logger.getLogger(TransferWalletTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestTransfertWallet() {
|
public void TestTransfertWallet() {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
UserContext user = Util.readUserContext(Config.ORG1,"admin");
|
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
|
String functionName = "transferWallet";
|
||||||
String chaincode = Config.CHAINCODE_NAME;
|
String[] args = new String[]{"qerh654d5f5h46q4fdh6h65fh00","bitman"};
|
||||||
Collection<ProposalResponse> successful = new LinkedList<>();
|
//String[] args = new String[]{"qerh654d5f5h46q4fdh6h65fh00","usera"};
|
||||||
Collection<ProposalResponse> failed = new LinkedList<>();
|
BlockEvent.TransactionEvent responseEvent = transactionWrapper.sendTransaction(functionName,args);
|
||||||
|
logger.info("Event transaction id : "+responseEvent.getTransactionID()); //print transaction id
|
||||||
logger.info("userContext : "+user.getName());
|
|
||||||
FabricClientWrapper fabricClientWrapper = new FabricClientWrapper(user);
|
|
||||||
ChannelClientWrapper channelClientWrapper = fabricClientWrapper.createChannelClient(Config.CHANNEL_NAME);
|
|
||||||
|
|
||||||
Channel channel = channelClientWrapper.getChannel();
|
|
||||||
Orderer orderer = fabricClientWrapper.getClient().newOrderer(Config.ORDERER_NAME,Config.ORDERER_URL);
|
|
||||||
channel.addOrderer(orderer);
|
|
||||||
Peer peer = fabricClientWrapper.getClient().newPeer(Config.ORG1_PEER_0,Config.ORG1_PEER_0_URL);
|
|
||||||
channel.addPeer(peer);
|
|
||||||
|
|
||||||
|
|
||||||
channel.initialize();
|
|
||||||
|
|
||||||
//CONTROL
|
|
||||||
logger.info("channel INIT : "+channel.isInitialized());
|
|
||||||
for(Peer p : channel.getPeers()){
|
|
||||||
Set<String> channels = fabricClientWrapper.getClient().queryChannels(peer);
|
|
||||||
logger.info("channels "+channels);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
|
|
||||||
TransactionProposalRequest tpr = fabricClientWrapper.getClient().newTransactionProposalRequest();
|
|
||||||
ChaincodeID cid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_NAME).build();
|
|
||||||
tpr.setChaincodeID(cid);
|
|
||||||
tpr.setFcn("transferWallet");
|
|
||||||
tpr.setArgs(new String[]{"qerh654d5f5h46q4fdh6h65fh00","bitman"});
|
|
||||||
tpr.setProposalWaitTime(120000);
|
|
||||||
|
|
||||||
Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(tpr);
|
|
||||||
for(ProposalResponse response : invokePropResp){
|
|
||||||
if (response.getStatus() == ChaincodeResponse.Status.SUCCESS) {
|
|
||||||
logger.info("Successful transaction proposal response Txid: "+response.getTransactionID()+" from peer "+response.getPeer().getName());
|
|
||||||
successful.add(response);
|
|
||||||
} else {
|
|
||||||
failed.add(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Received "+invokePropResp.size()+" transaction proposal responses. Successful+verified: "+successful.size()+". Failed: "+failed.size());
|
|
||||||
|
|
||||||
BlockEvent.TransactionEvent event = channel.sendTransaction(successful).get();
|
|
||||||
logger.info("Event transaction id : "+event.getTransactionID()); //print transaction id
|
|
||||||
|
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package blockchain.queryWrapper;
|
|
||||||
|
|
||||||
import blockchain.query.QueryWrapper;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public class QueryWrapperTest {
|
|
||||||
private static Logger logger = Logger.getLogger(QueryWrapperTest.class);
|
|
||||||
@Test
|
|
||||||
public void TestGerUserBalance() {
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
|
||||||
String response = queryWrapper.getUserBalance("a");
|
|
||||||
logger.info(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package blockchain.queryWrapper;
|
|
||||||
|
|
||||||
import blockchain.query.QueryWrapper;
|
|
||||||
import blockchain.query.TransactionWrapper;
|
|
||||||
import org.apache.log4j.BasicConfigurator;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public class TransactionWrapperTest {
|
|
||||||
private static Logger logger = Logger.getLogger(TransactionWrapperTest.class);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestTransaction() {
|
|
||||||
BasicConfigurator.configure();
|
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
|
||||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
|
||||||
String responseTransaction = transactionWrapper.sendTransaction("b","a","150"); //do transaction
|
|
||||||
logger.info("TRANSACTION ID : "+responseTransaction);
|
|
||||||
|
|
||||||
String responseUserB = queryWrapper.getUserBalance("b"); //check new balance of user b
|
|
||||||
logger.info("BALANCE USER B : "+responseUserB);
|
|
||||||
|
|
||||||
String responseUserA = queryWrapper.getUserBalance("a"); //check new balance of user a
|
|
||||||
logger.info("BALANCE USER A :"+responseUserA);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue