diff --git a/README.md b/README.md index b3062f7..3cebc64 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,56 @@ -# BMXHyperledgerFabricJSDKIntegrationSample +This document shows how to integrate the IBM hyperledger Java SDK with IBM bluemix blockchain. To use Bluemix IBM Blockchain Service, follow https://github.com/IBM-Blockchain/marbles/blob/v4.0/docs/use_bluemix_hyperledger.md to create a Blockchain Network in IBM Bluemix, peers (up to 3) and a channel. ## Hyperledger Fabric Java SDK Version - This code is dependent on a 1.1.0-SNAPSHOT + Requires Hyperledger Fabric Java SDK 1.1.0-SNAPSHOT - To reference this snapshot repository update your Maven settings .m2/settings.xml file with the below profile: - - - ``` - - - - - allow-snapshots - - true - - - - snapshots-repo - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - - -``` +## Down load the repository +git clone https://github.com/IBM-Blockchain/JSDKIntegrationSample + +## Obtain "Service Credential" from bluemix +From your bluemix dashboard Overview, click on "Service Credentials", copy and paste all the information to a file named "bmxServiceCredentials.json". Save this file to the location where you download the repository + +![serviceCredentials](images/serviceCredential.png) + +## Modify BMXHyperledgerFabricJSDKIntegrationSample.java +Two places need to be changed: +NETWORK_CONFIG_PEERORG_CA: get network ca information from bmxServiceCredentials.json + +TEST_CHANNEL: update with your own channel name. + +![javeSampleCode](images/javaSampleCode.png) ## Installing Run command: ```mvn install``` + + Issue “mvn install” from your download folder, confirm with “BUILD SUCCESS” message + + ![installBuild](images/installBuild.png) ## Running -The code can not be run until a BlueMix Block Chain network has been created. See video for details. - Run command: ```mvn exec:java -Dexec.mainClass="org.cr22rc.BMXHyperledgerFabricJSDKIntegrationSample"``` +It will generate the cert for user "admin" at the first time run, the credential info will be saved to "bmxBlockChainSampleStore.properties". + +![installBuild](images/execution.png) + +## Upload the certification to bluemix + +Copy and paste CERTFICATE from java test case output to bluemix web GUI + +![memberView](images/member.png) +![addCert](images/addCert.png) + +Tip: if the submit button is disabled, just add CR to ------END CERTIFICATE----- + +## Running it again + +We should able to see invoke transaction and query runs are successful. + +![runTest](images/runTest.png) + ## Introduction Video An introduction video is in Videos/bmxJSDKIntro.webm diff --git a/images/addCert.png b/images/addCert.png new file mode 100644 index 0000000..9fa286c Binary files /dev/null and b/images/addCert.png differ diff --git a/images/buildSuccess.png b/images/buildSuccess.png new file mode 100644 index 0000000..3011310 Binary files /dev/null and b/images/buildSuccess.png differ diff --git a/images/execution.png b/images/execution.png new file mode 100644 index 0000000..544a541 Binary files /dev/null and b/images/execution.png differ diff --git a/images/installBuild.png b/images/installBuild.png new file mode 100644 index 0000000..3011310 Binary files /dev/null and b/images/installBuild.png differ diff --git a/images/javaSampleCode.png b/images/javaSampleCode.png new file mode 100644 index 0000000..884f66b Binary files /dev/null and b/images/javaSampleCode.png differ diff --git a/images/member.png b/images/member.png new file mode 100644 index 0000000..f477313 Binary files /dev/null and b/images/member.png differ diff --git a/images/runTest.png b/images/runTest.png new file mode 100644 index 0000000..cc8c728 Binary files /dev/null and b/images/runTest.png differ diff --git a/images/serviceCredential.png b/images/serviceCredential.png new file mode 100644 index 0000000..e9ed717 Binary files /dev/null and b/images/serviceCredential.png differ diff --git a/src/main/java/org/cr22rc/BMXHyperledgerFabricJSDKIntegrationSample.java b/src/main/java/org/cr22rc/BMXHyperledgerFabricJSDKIntegrationSample.java index 2a7ef43..a13f86d 100644 --- a/src/main/java/org/cr22rc/BMXHyperledgerFabricJSDKIntegrationSample.java +++ b/src/main/java/org/cr22rc/BMXHyperledgerFabricJSDKIntegrationSample.java @@ -64,11 +64,11 @@ public class BMXHyperledgerFabricJSDKIntegrationSample { - public static final String NETWORK_CONFIG_PEERORG_CA = "fabric-ca-peerorg1-23033a"; //Only test with this CA + public static final String NETWORK_CONFIG_PEERORG_CA = "fabric-ca-peerorg1-20621a"; //Only test with this CA public static final String NETWORK_CONFIG_PEERORG = "PeerOrg1"; //Only test with this peer org - public static final String TEST_CHANNEL = "ricks-test-channel"; + public static final String TEST_CHANNEL = "java-test-channel"; static final SampleStore SAMPLE_STORE = new SampleStore(new File("bmxBlockChainSampleStore.properties")); @@ -108,7 +108,8 @@ private void run(String[] args) throws Exception { NetworkConfig.NetworkConfigUser networkConfigRegistrar = certificateAuthority.getRegistrar(PEER_ADMIN_NAME); admin = SAMPLE_STORE.getMember(PEER_ADMIN_NAME, NETWORK_CONFIG_PEERORG); admin.setEnrollmentSecret(networkConfigRegistrar.getEnrollSecret()); - admin.setAffiliation(networkConfigRegistrar.getAffiliation()); + if(networkConfigRegistrar.getAffiliation() != null) + admin.setAffiliation(networkConfigRegistrar.getAffiliation()); admin.setMspId(networkConfigRegistrar.getMspId()); } diff --git a/src/main/java/org/cr22rc/NetworkConfig.java b/src/main/java/org/cr22rc/NetworkConfig.java index 41447d7..205bad1 100644 --- a/src/main/java/org/cr22rc/NetworkConfig.java +++ b/src/main/java/org/cr22rc/NetworkConfig.java @@ -171,6 +171,7 @@ String getName() { } String getMspid() { + return value.getString("mspid"); } @@ -210,7 +211,7 @@ private CertificateAuthorityConfig(String name, JsonObject value, String mspid) } public String getCAName() { - return value.getString("caName"); + return value.getString("caName"); } NetworkConfigUser getRegistrar(String name) { @@ -232,7 +233,8 @@ public Map getRegistrars() { NetworkConfigUser networkConfigUser = new NetworkConfigUser(registrar.getEnrollId(), OrganizationConfig.this.getMspid(), registrar.getEnrollSecret()); - networkConfigUser.affiliation = registrar.getAffiliation(); + if(registrar.getAffiliation() != null) + networkConfigUser.affiliation = registrar.getAffiliation(); ret.put(registrar.getEnrollId(), networkConfigUser); @@ -292,15 +294,21 @@ class Registrar { } public String getEnrollId() { - return value.getString("enrollId"); + if(value.containsKey("enrollId")) + return value.getString("enrollId"); + return null; } public String getAffiliation() { - return value.getString("affiliation"); + if(value.containsKey("affiliation")) + return value.getString("affiliation"); + return null; } public String getEnrollSecret() { - return value.getString("enrollSecret"); + if(value.containsKey("enrollSecret")) + return value.getString("enrollSecret"); + return null; } } @@ -316,7 +324,10 @@ class EndPoint { } public String getURL() { - return value.getString("url"); + if(value.containsKey("url")) + return value.getString("url"); + return null; + } public String getName() { @@ -324,7 +335,9 @@ public String getName() { } public String getTLSCerts() { - return value.getJsonObject("tlsCACerts").getString("pem"); + if(value.containsKey("tlsCACerts")) + return value.getJsonObject("tlsCACerts").getString("pem"); + return null; }