Documente Academic
Documente Profesional
Documente Cultură
Andrew Coleman
Simon Stone
Mark Lewis
Transaction: Move
Transaction: Redeem
Wallet
© 2019 IBM Corporation 6
Example client application – JavaScript
• IBM issues a commercial paper, face value $1M, redemption date 2019-10-31
• IBM sells paper to ACME Inc. for $900,000
const gateway = new Gateway();
const wallet = new FileSystemWallet('./WALLETS/wallet');
try {
await gateway.connect(ccp, {
identity: 'admin',
wallet: wallet
});
} catch(error) {
console.log(error);
} finally {
gateway.disconnect();
}
© 2019 IBM Corporation 7
Example client application – Java
• IBM issues a commercial paper, face value $1M, redemption date 2019-10-31
• IBM sells paper to ACME Inc. for $900,000
// Create a new file system based wallet for managing identities.
Path walletPath = Paths.get("wallet");
Wallet wallet = Wallet.createFileSystemWallet(walletPath);
// load a CCP
Path networkConfigPath = Paths.get("..", "..", "paper-network", "connection.json");
NetworkConfig networkConfig = NetworkConfig.fromJsonFile(networkConfigPath.toFile());
• The gateway gets configured with predefined 'strategies' that specify the behavior of low-level
interactions
– E.g. what conditions define successful transaction commitment
– E.g. how to share out queries amongst available peers
• In Java, we adopt the 'builder' design pattern to configure the gateway options
Gateway.Builder builder = Gateway.createBuilder();
builder.identity(wallet, "admin").networkConfig(networkConfig);
builder.commitHandler(DefaultCommitHandlers.MSPID_SCOPE_ALLFORTX);
• Typically done by a more 'advanced' fabric developer and implemented using lower-level APIs
• Compatible wallet format between Node.js and Java (as well as future CLI utilities)
• Extra options can be associated with this transaction before it is evaluated or summited to the ledger
– E.g. transient data
• In the base SDK, this transient data is passed as a property in the transaction request object
• In the new programming model, there is a setTransient() method in the Transaction interface
– Passes a Map of name/value pairs to subsequent invocation of submit() & evaluate()
• This provides API symmetry between the existing smart contract (shim) API and the application SDK
• The Gateway object can also be instantiated from an existing HFClient object
– Allows existing client code to start using the new submitTransaction() function
without rewriting
• Fabcar sample updated with Javascript and Typescript implementations using the new
fabric-network API
– https://github.com/hyperledger/fabric-samples/tree/release-1.4/fabcar/javascript
– https://github.com/hyperledger/fabric-samples/tree/release-1.4/fabcar/typescript