Skip to content
This repository has been archived by the owner on Aug 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3 from SandySun2000/master
Browse files Browse the repository at this point in the history
change affiliation field from mandatory to optional
  • Loading branch information
georgeanu authored Nov 15, 2017
2 parents 22cdf40 + beb1700 commit 21e8e47
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 44 deletions.
74 changes: 40 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:


```
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>allow-snapshots</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
```
## 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

Expand Down
Binary file added images/addCert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/buildSuccess.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/execution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/installBuild.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/javaSampleCode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/member.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/runTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/serviceCredential.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down Expand Up @@ -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());

}
Expand Down
27 changes: 20 additions & 7 deletions src/main/java/org/cr22rc/NetworkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ String getName() {
}

String getMspid() {

return value.getString("mspid");
}

Expand Down Expand Up @@ -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) {
Expand All @@ -232,7 +233,8 @@ public Map<String, NetworkConfigUser> 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);

Expand Down Expand Up @@ -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;
}

}
Expand All @@ -316,15 +324,20 @@ class EndPoint {
}

public String getURL() {
return value.getString("url");
if(value.containsKey("url"))
return value.getString("url");
return null;

}

public String getName() {
return name;
}

public String getTLSCerts() {
return value.getJsonObject("tlsCACerts").getString("pem");
if(value.containsKey("tlsCACerts"))
return value.getJsonObject("tlsCACerts").getString("pem");
return null;

}

Expand Down

0 comments on commit 21e8e47

Please sign in to comment.