use of org.hyperledger.fabric.sdk.HFClient in project fabric-sdk-java by hyperledger.
the class NetworkConfigIT method deployChaincodeIfRequired.
// Determines whether or not the chaincode has been deployed and deploys it if necessary
private static void deployChaincodeIfRequired() throws Exception {
// //////////////////////////
// Setup client
HFClient client = getTheClient();
Channel channel = constructChannel(client, FOO_CHANNEL_NAME);
// Use any old peer...
Peer peer = channel.getPeers().iterator().next();
if (!checkInstantiatedChaincode(channel, peer, CHAIN_CODE_NAME, CHAIN_CODE_PATH, CHAIN_CODE_VERSION)) {
// The chaincode we require does not exist, so deploy it...
deployChaincode(client, channel, CHAIN_CODE_NAME, CHAIN_CODE_PATH, CHAIN_CODE_VERSION);
}
}
use of org.hyperledger.fabric.sdk.HFClient in project fabric-sdk-java by hyperledger.
the class NetworkConfigIT method getTheClient.
// Returns a new client instance
private static HFClient getTheClient() throws Exception {
HFClient client = HFClient.createNewInstance();
client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());
User peerAdmin = getAdminUser(TEST_ORG);
client.setUserContext(peerAdmin);
return client;
}
use of org.hyperledger.fabric.sdk.HFClient in project fabric-sdk-java by hyperledger.
the class NetworkConfigIT method testUpdate1.
@Test
public void testUpdate1() throws Exception {
// Setup client and channel instances
HFClient client = getTheClient();
Channel channel = constructChannel(client, FOO_CHANNEL_NAME);
final ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(CHAIN_CODE_NAME).setVersion(CHAIN_CODE_VERSION).setPath(CHAIN_CODE_PATH).build();
final String channelName = channel.getName();
out("Running testUpdate1 - Channel %s", channelName);
int moveAmount = 5;
String originalVal = queryChaincodeForCurrentValue(client, channel, chaincodeID);
String newVal = "" + (Integer.parseInt(originalVal) + moveAmount);
out("Original value = %s", originalVal);
// Move some assets
moveAmount(client, channel, chaincodeID, "a", "b", "" + moveAmount, null).thenApply(transactionEvent -> {
// Check that they were moved
queryChaincodeForExpectedValue(client, channel, newVal, chaincodeID);
return null;
}).thenApply(transactionEvent -> {
// Move them back
try {
return moveAmount(client, channel, chaincodeID, "b", "a", "" + moveAmount, null).get(testConfig.getTransactionWaitTime(), TimeUnit.SECONDS);
} catch (Exception e) {
throw new RuntimeException(e);
}
}).thenApply(transactionEvent -> {
// Check that they were moved back
queryChaincodeForExpectedValue(client, channel, originalVal, chaincodeID);
return null;
}).exceptionally(e -> {
if (e instanceof CompletionException && e.getCause() != null) {
e = e.getCause();
}
if (e instanceof TransactionEventException) {
BlockEvent.TransactionEvent te = ((TransactionEventException) e).getTransactionEvent();
if (te != null) {
e.printStackTrace(System.err);
fail(format("Transaction with txid %s failed. %s", te.getTransactionID(), e.getMessage()));
}
}
e.printStackTrace(System.err);
fail(format("Test failed with %s exception %s", e.getClass().getName(), e.getMessage()));
return null;
}).get(testConfig.getTransactionWaitTime(), TimeUnit.SECONDS);
// Force channel to shutdown clean up resources.
channel.shutdown(true);
out("testUpdate1 - done");
}
Aggregations