mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 17:45:10 +00:00
making commercial-paper application-java to fit 2.0.0 (#160)
Signed-off-by: linqili <charlielin06@gmail.com> Co-authored-by: linqili <charlielin06@gmail.com>
This commit is contained in:
parent
11e4c23a35
commit
40db5d649a
11 changed files with 326 additions and 441 deletions
|
|
@ -1,20 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" output="target/classes" path="src">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
|
||||||
</classpath>
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>commercial-paper</groupId>
|
|
||||||
<artifactId>commercial-paper</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<build>
|
|
||||||
<sourceDirectory>src</sourceDirectory>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.2.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<excludes>
|
|
||||||
<exclude>META-INF/*.SF</exclude>
|
|
||||||
<exclude>META-INF/*.DSA</exclude>
|
|
||||||
<exclude>META-INF/*.RSA</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>hyperledger</id>
|
|
||||||
<name>Hyperledger Artifactory</name>
|
|
||||||
<url>https://hyperledger.jfrog.io/hyperledger/fabric-maven</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>jitpack.io</id>
|
|
||||||
<url>https://jitpack.io</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
<properties>
|
|
||||||
<fabric-chaincode-java.version>1.4.2</fabric-chaincode-java.version>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
</project>
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
<!-- fabric-chaincode-java -->
|
<!-- fabric-chaincode-java -->
|
||||||
<fabric-chaincode-java.version>[2.0,3.0)</fabric-chaincode-java.version>
|
<fabric-chaincode-java.version>[2.0,3.0)</fabric-chaincode-java.version>
|
||||||
|
<!-- fabric-gateway-java -->
|
||||||
|
<fabric-gateway-java.version>2.0.0</fabric-gateway-java.version>
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
@ -44,6 +46,7 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<filters>
|
<filters>
|
||||||
<filter>
|
<filter>
|
||||||
<artifact>*:*</artifact>
|
<artifact>*:*</artifact>
|
||||||
|
|
@ -61,12 +64,6 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>hyperledger</id>
|
|
||||||
<name>Hyperledger Nexus</name>
|
|
||||||
<url>https://hyperledger.jfrog.io/hyperledger/fabric-maven</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
|
|
@ -75,9 +72,9 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hyperledger.fabric-gateway-java</groupId>
|
<groupId>org.hyperledger.fabric</groupId>
|
||||||
<artifactId>fabric-gateway-java</artifactId>
|
<artifactId>fabric-gateway-java</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>${fabric-gateway-java.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Used for datatype annotations only -->
|
<!-- Used for datatype annotations only -->
|
||||||
|
|
|
||||||
|
|
@ -5,37 +5,61 @@ SPDX-License-Identifier: Apache-2.0
|
||||||
package org.digibank;
|
package org.digibank;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
import org.hyperledger.fabric.gateway.GatewayException;
|
import java.security.PrivateKey;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import org.hyperledger.fabric.gateway.Identities;
|
||||||
|
import org.hyperledger.fabric.gateway.Identity;
|
||||||
import org.hyperledger.fabric.gateway.Wallet;
|
import org.hyperledger.fabric.gateway.Wallet;
|
||||||
import org.hyperledger.fabric.gateway.Wallet.Identity;
|
import org.hyperledger.fabric.gateway.Wallets;
|
||||||
|
|
||||||
public class AddToWallet {
|
public class AddToWallet {
|
||||||
|
|
||||||
|
private static X509Certificate readX509Certificate(final Path certificatePath) throws IOException, CertificateException {
|
||||||
|
try (Reader certificateReader = Files.newBufferedReader(certificatePath, StandardCharsets.UTF_8)) {
|
||||||
|
return Identities.readX509Certificate(certificateReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrivateKey getPrivateKey(final Path privateKeyPath) throws IOException, InvalidKeyException {
|
||||||
|
try (Reader privateKeyReader = Files.newBufferedReader(privateKeyPath, StandardCharsets.UTF_8)) {
|
||||||
|
return Identities.readPrivateKey(privateKeyReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
// A wallet stores a collection of identities
|
// A wallet stores a collection of identities
|
||||||
Path walletPath = Paths.get("..", "identity", "user", "balaji", "wallet");
|
Path walletPath = Paths.get(".", "wallet");
|
||||||
Wallet wallet = Wallet.createFileSystemWallet(walletPath);
|
Wallet wallet = Wallets.newFileSystemWallet(walletPath);
|
||||||
|
|
||||||
// Location of credentials to be stored in the wallet
|
Path credentialPath = Paths.get("..", "..", "..",".." ,"test-network", "organizations",
|
||||||
Path credentialPath = Paths.get("..", "..", "..", "..","basic-network", "crypto-config",
|
"peerOrganizations", "org1.example.com", "users", "User1@org1.example.com", "msp");
|
||||||
"peerOrganizations", "org1.example.com", "users", "Admin@org1.example.com", "msp");
|
System.out.println("credentialPath: " + credentialPath.toString());
|
||||||
Path certificatePem = credentialPath.resolve(Paths.get("signcerts",
|
Path certificatePath = credentialPath.resolve(Paths.get("signcerts",
|
||||||
"Admin@org1.example.com-cert.pem"));
|
"User1@org1.example.com-cert.pem"));
|
||||||
Path privateKey = credentialPath.resolve(Paths.get("keystore",
|
System.out.println("certificatePem: " + certificatePath.toString());
|
||||||
"cd96d5260ad4757551ed4a5a991e62130f8008a0bf996e4e4b84cd097a747fec_sk"));
|
Path privateKeyPath = credentialPath.resolve(Paths.get("keystore",
|
||||||
|
"priv_sk"));
|
||||||
|
|
||||||
// Load credentials into wallet
|
X509Certificate certificate = readX509Certificate(certificatePath);
|
||||||
String identityLabel = "Admin@org1.example.com";
|
PrivateKey privateKey = getPrivateKey(privateKeyPath);
|
||||||
Identity identity = Identity.createIdentity("Org1MSP", Files.newBufferedReader(certificatePem), Files.newBufferedReader(privateKey));
|
|
||||||
|
|
||||||
|
Identity identity = Identities.newX509Identity("Org1MSP", certificate, privateKey);
|
||||||
|
|
||||||
|
|
||||||
|
String identityLabel = "User1@org1.example.com";
|
||||||
wallet.put(identityLabel, identity);
|
wallet.put(identityLabel, identity);
|
||||||
|
|
||||||
} catch (IOException e) {
|
System.out.println("Write wallet info into " + walletPath.toString() + " successfully.");
|
||||||
|
|
||||||
|
} catch (IOException | CertificateException | InvalidKeyException e) {
|
||||||
System.err.println("Error adding to wallet");
|
System.err.println("Error adding to wallet");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import org.hyperledger.fabric.gateway.Gateway;
|
||||||
import org.hyperledger.fabric.gateway.GatewayException;
|
import org.hyperledger.fabric.gateway.GatewayException;
|
||||||
import org.hyperledger.fabric.gateway.Network;
|
import org.hyperledger.fabric.gateway.Network;
|
||||||
import org.hyperledger.fabric.gateway.Wallet;
|
import org.hyperledger.fabric.gateway.Wallet;
|
||||||
|
import org.hyperledger.fabric.gateway.Wallets;
|
||||||
import org.papernet.CommercialPaper;
|
import org.papernet.CommercialPaper;
|
||||||
|
|
||||||
public class Buy {
|
public class Buy {
|
||||||
|
|
@ -33,12 +34,13 @@ public class Buy {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// A wallet stores a collection of identities
|
// A wallet stores a collection of identities
|
||||||
Path walletPath = Paths.get("..", "identity", "user", "balaji", "wallet");
|
Path walletPath = Paths.get(".", "wallet");
|
||||||
Wallet wallet = Wallet.createFileSystemWallet(walletPath);
|
Wallet wallet = Wallets.newFileSystemWallet(walletPath);
|
||||||
|
System.out.println("Read wallet info from: " + walletPath);
|
||||||
|
|
||||||
String userName = "Admin@org1.example.com";
|
String userName = "User1@org1.example.com";
|
||||||
|
|
||||||
Path connectionProfile = Paths.get("..", "gateway", "networkConnection.yaml");
|
Path connectionProfile = Paths.get("..", "gateway", "connection-org1.yaml");
|
||||||
|
|
||||||
// Set connection options on the gateway builder
|
// Set connection options on the gateway builder
|
||||||
builder.identity(wallet, userName).networkConfig(connectionProfile).discovery(false);
|
builder.identity(wallet, userName).networkConfig(connectionProfile).discovery(false);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import org.hyperledger.fabric.gateway.Gateway;
|
||||||
import org.hyperledger.fabric.gateway.GatewayException;
|
import org.hyperledger.fabric.gateway.GatewayException;
|
||||||
import org.hyperledger.fabric.gateway.Network;
|
import org.hyperledger.fabric.gateway.Network;
|
||||||
import org.hyperledger.fabric.gateway.Wallet;
|
import org.hyperledger.fabric.gateway.Wallet;
|
||||||
|
import org.hyperledger.fabric.gateway.Wallets;
|
||||||
import org.papernet.CommercialPaper;
|
import org.papernet.CommercialPaper;
|
||||||
|
|
||||||
public class Redeem {
|
public class Redeem {
|
||||||
|
|
@ -33,12 +34,12 @@ public class Redeem {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// A wallet stores a collection of identities
|
// A wallet stores a collection of identities
|
||||||
Path walletPath = Paths.get("..", "identity", "user", "balaji", "wallet");
|
Path walletPath = Paths.get(".", "wallet");
|
||||||
Wallet wallet = Wallet.createFileSystemWallet(walletPath);
|
Wallet wallet = Wallets.newFileSystemWallet(walletPath);
|
||||||
|
|
||||||
String userName = "Admin@org1.example.com";
|
String userName = "User1@org1.example.com";
|
||||||
|
|
||||||
Path connectionProfile = Paths.get("..", "gateway", "networkConnection.yaml");
|
Path connectionProfile = Paths.get("..", "gateway", "connection-org1.yaml");
|
||||||
|
|
||||||
// Set connection options on the gateway builder
|
// Set connection options on the gateway builder
|
||||||
builder.identity(wallet, userName).networkConfig(connectionProfile).discovery(false);
|
builder.identity(wallet, userName).networkConfig(connectionProfile).discovery(false);
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<classpath>
|
|
||||||
<classpathentry kind="src" output="target/classes" path="src">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
|
||||||
</classpath>
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>commercial-paper</groupId>
|
|
||||||
<artifactId>commercial-paper</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<build>
|
|
||||||
<sourceDirectory>src</sourceDirectory>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>3.2.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<excludes>
|
|
||||||
<exclude>META-INF/*.SF</exclude>
|
|
||||||
<exclude>META-INF/*.DSA</exclude>
|
|
||||||
<exclude>META-INF/*.RSA</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>hyperledger</id>
|
|
||||||
<name>Hyperledger Artifactory</name>
|
|
||||||
<url>https://hyperledger.jfrog.io/hyperledger/fabric-maven</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>jitpack.io</id>
|
|
||||||
<url>https://jitpack.io</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
<properties>
|
|
||||||
<fabric-chaincode-java.version>1.4.2</fabric-chaincode-java.version>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
</project>
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
<!-- fabric-chaincode-java -->
|
<!-- fabric-chaincode-java -->
|
||||||
<fabric-chaincode-java.version>[2.0,3.0)</fabric-chaincode-java.version>
|
<fabric-chaincode-java.version>[2.0,3.0)</fabric-chaincode-java.version>
|
||||||
|
<!-- fabric-gateway-java -->
|
||||||
|
<fabric-gateway-java.version>2.0.0</fabric-gateway-java.version>
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
@ -44,6 +46,7 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<filters>
|
<filters>
|
||||||
<filter>
|
<filter>
|
||||||
<artifact>*:*</artifact>
|
<artifact>*:*</artifact>
|
||||||
|
|
@ -61,12 +64,6 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>hyperledger</id>
|
|
||||||
<name>Hyperledger Artifactory</name>
|
|
||||||
<url>https://hyperledger.jfrog.io/hyperledger/fabric-maven</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
|
|
@ -75,9 +72,9 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hyperledger</groupId>
|
<groupId>org.hyperledger.fabric</groupId>
|
||||||
<artifactId>fabric-gateway-java</artifactId>
|
<artifactId>fabric-gateway-java</artifactId>
|
||||||
<version>1.4.0-SNAPSHOT</version>
|
<version>${fabric-gateway-java.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Used for datatype annotations only -->
|
<!-- Used for datatype annotations only -->
|
||||||
|
|
|
||||||
|
|
@ -5,37 +5,61 @@ SPDX-License-Identifier: Apache-2.0
|
||||||
package org.magnetocorp;
|
package org.magnetocorp;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
import org.hyperledger.fabric.gateway.GatewayException;
|
import java.security.PrivateKey;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import org.hyperledger.fabric.gateway.Identities;
|
||||||
import org.hyperledger.fabric.gateway.Wallet;
|
import org.hyperledger.fabric.gateway.Wallet;
|
||||||
import org.hyperledger.fabric.gateway.Wallet.Identity;
|
import org.hyperledger.fabric.gateway.Wallets;
|
||||||
|
import org.hyperledger.fabric.gateway.Identity;
|
||||||
|
|
||||||
public class AddToWallet {
|
public class AddToWallet {
|
||||||
|
|
||||||
|
private static X509Certificate readX509Certificate(final Path certificatePath) throws IOException, CertificateException {
|
||||||
|
try (Reader certificateReader = Files.newBufferedReader(certificatePath, StandardCharsets.UTF_8)) {
|
||||||
|
return Identities.readX509Certificate(certificateReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PrivateKey getPrivateKey(final Path privateKeyPath) throws IOException, InvalidKeyException {
|
||||||
|
try (Reader privateKeyReader = Files.newBufferedReader(privateKeyPath, StandardCharsets.UTF_8)) {
|
||||||
|
return Identities.readPrivateKey(privateKeyReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
// A wallet stores a collection of identities
|
// A wallet stores a collection of identities
|
||||||
Path walletPath = Paths.get("..", "identity", "user", "isabella", "wallet");
|
Path walletPath = Paths.get(".", "wallet");
|
||||||
Wallet wallet = Wallet.createFileSystemWallet(walletPath);
|
Wallet wallet = Wallets.newFileSystemWallet(walletPath);
|
||||||
|
|
||||||
// Location of credentials to be stored in the wallet
|
Path credentialPath = Paths.get("..", "..", "..",".." ,"test-network", "organizations",
|
||||||
Path credentialPath = Paths.get("..", "..",".." ,".." ,"basic-network", "crypto-config",
|
"peerOrganizations", "org2.example.com", "users", "User1@org2.example.com", "msp");
|
||||||
"peerOrganizations", "org1.example.com", "users", "User1@org1.example.com", "msp");
|
System.out.println("credentialPath: " + credentialPath.toString());
|
||||||
Path certificatePem = credentialPath.resolve(Paths.get("signcerts",
|
Path certificatePath = credentialPath.resolve(Paths.get("signcerts",
|
||||||
"User1@org1.example.com-cert.pem"));
|
"User1@org2.example.com-cert.pem"));
|
||||||
Path privateKey = credentialPath.resolve(Paths.get("keystore",
|
System.out.println("certificatePem: " + certificatePath.toString());
|
||||||
"c75bd6911aca808941c3557ee7c97e90f3952e379497dc55eb903f31b50abc83_sk"));
|
Path privateKeyPath = credentialPath.resolve(Paths.get("keystore",
|
||||||
|
"priv_sk"));
|
||||||
|
|
||||||
// Load credentials into wallet
|
X509Certificate certificate = readX509Certificate(certificatePath);
|
||||||
String identityLabel = "User1@org1.example.com";
|
PrivateKey privateKey = getPrivateKey(privateKeyPath);
|
||||||
Identity identity = Identity.createIdentity("Org1MSP", Files.newBufferedReader(certificatePem), Files.newBufferedReader(privateKey));
|
|
||||||
|
|
||||||
|
Identity identity = Identities.newX509Identity("Org2MSP", certificate, privateKey);
|
||||||
|
|
||||||
|
|
||||||
|
String identityLabel = "User1@org2.example.com";
|
||||||
wallet.put(identityLabel, identity);
|
wallet.put(identityLabel, identity);
|
||||||
|
|
||||||
} catch (IOException e) {
|
System.out.println("Write wallet info into " + walletPath.toString() + " successfully.");
|
||||||
|
|
||||||
|
} catch (IOException | CertificateException | InvalidKeyException e) {
|
||||||
System.err.println("Error adding to wallet");
|
System.err.println("Error adding to wallet");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import org.hyperledger.fabric.gateway.Gateway;
|
||||||
import org.hyperledger.fabric.gateway.GatewayException;
|
import org.hyperledger.fabric.gateway.GatewayException;
|
||||||
import org.hyperledger.fabric.gateway.Network;
|
import org.hyperledger.fabric.gateway.Network;
|
||||||
import org.hyperledger.fabric.gateway.Wallet;
|
import org.hyperledger.fabric.gateway.Wallet;
|
||||||
|
import org.hyperledger.fabric.gateway.Wallets;
|
||||||
import org.papernet.CommercialPaper;
|
import org.papernet.CommercialPaper;
|
||||||
|
|
||||||
public class Issue {
|
public class Issue {
|
||||||
|
|
@ -34,12 +35,13 @@ public class Issue {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// A wallet stores a collection of identities
|
// A wallet stores a collection of identities
|
||||||
Path walletPath = Paths.get("..", "identity", "user", "isabella", "wallet");
|
Path walletPath = Paths.get(".", "wallet");
|
||||||
Wallet wallet = Wallet.createFileSystemWallet(walletPath);
|
Wallet wallet = Wallets.newFileSystemWallet(walletPath);
|
||||||
|
System.out.println("Read wallet info from: " + walletPath.toString());
|
||||||
|
|
||||||
String userName = "User1@org1.example.com";
|
String userName = "User1@org2.example.com";
|
||||||
|
|
||||||
Path connectionProfile = Paths.get("..", "gateway", "networkConnection.yaml");
|
Path connectionProfile = Paths.get("..", "gateway", "connection-org2.yaml");
|
||||||
|
|
||||||
// Set connection options on the gateway builder
|
// Set connection options on the gateway builder
|
||||||
builder.identity(wallet, userName).networkConfig(connectionProfile).discovery(false);
|
builder.identity(wallet, userName).networkConfig(connectionProfile).discovery(false);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue