Hyperledger Fabric study notes - Applications

1, the basic process

The following diagram illustrates the process is simply a smart application calls the commercial paper contract by the SDK:

2、Wallet

Wallet X.509 digital certificate holders in the organization and linking gives the holder permission to connect to the network to have a different identity of the holder have different permissions, and intelligence during the execution of the contract can be obtained through the transaction context this identity. wallet does not deposit any cash or tokens, stored only identity.

Gateway and the application uses FileSystemWallet block chain class to connect to a network, at the top issue.js can be seen include two classes.

const { FileSystemWallet, Gateway } = require('fabric-network');

Application uses the Wallet category:

const wallet = new FileSystemWallet('../identity/user/isabella/wallet');

3、Gateway

issue.js gateways connected to it:

await gateway.connect(connectionProfile, connectionOptions);

gateway.connect () has two important parameters:

connectionProfile: identifies the file system location of connection profile of a series of peer gateway. In order to facilitate the use of the read YAML, JSON object loading is converted to the following code.

let connectionProfile = yaml.safeLoad(file.readFileSync('./gateway/connectionProfile.yaml', 'utf8'));

connectionOptions: series for controlling issue.js (application code) how the block chain connected to a network. It specifies the identity, userName and wallet connected to the gateway needs, but also to achieve some intelligent behavior through the SDK.

let connectionOptions = {
  identity: userName,
  wallet: wallet,
  eventHandlerOptions: {
    commitTimeout: 100,
    strategy: EventStrategies.MSPID_SCOPE_ANYFORTX
  },
}

Gateway responsible for the use connect profile and connection options proposed transaction will be sent to the correct peer nodes.

4、Network channel

connectionProfile.yaml gateway peers defined in the configuration file provides a way issue.js access PaperNet because these peers can join a plurality of network channels, so actually the gateway provides access to a plurality of application route network channels slightly .

Select a specific application of a channel:

const network = await gateway.getNetwork('PaperNet');

Applications may be added in a sub-network of network, by connecting to multiple gateway peers. Each peer is added to a plurality of network channels, according to their different applications have different permissions wallet identities in different channels.

5, a proposal to build

Application directly connected to CommercialPaperContract this intelligent contracts:

const contract = await network.getContract('papercontract', 'org.papernet.commercialpaper');

papercontract.js is a chain code file that contains multiple intelligence contracts, papercontract is the chain code files are installed and deployed on the channel's name, select the required intelligence contracts from papercontract.js chain code by the name of intelligence contracts. getContract () method uses the first contract on the intelligent chain code it finds a default, so when the chain code is only a smart contract, the contract can be omitted names.

6, to submit proposed transaction

The proposed transaction is a call to submit a separate method SDK:

const issueResponse = await contract.submitTransaction('issue', 'MagnetoCorp', '00001', '2020-05-31', '2020-11-30', '5000000');

Looks like a smart contract after the application calls submitTransaction () quickly gained control, but that is not the case. Behind the scenes, SDK using connectionOptions and connectionProfile to the proposed transaction is sent to the correct network node. However, the application does not use these tubes, just launched submitTransaction SDK and then complete the rest of all operations.

Note, submitTransactionAPI includes a monitor transaction submission process, which is necessary, because if not you can not know whether the transaction has been successfully completed sort, verify and submit to its books.

7, in response to the processing

And the transaction as proposed, may seem intelligent application after the contract calls quickly gained control, but the fact is not the case, the same consensus behind the other processes done by the SDK.

Published 23 original articles · won praise 0 · Views 1256

Guess you like

Origin blog.csdn.net/Nemoosi/article/details/104708877