fabric学习笔记8

fabric学习笔记8

20201303张奕博 2023.1.19

具体结构:

Wallet中的X.509数字证书将组织和持有者联系起来,使得持有者能够有权限连接到网络,不同的持有者身份拥有不同的权限,并且智能合约可以在执行期间通过transaction context获得这个身份。wallet中不存放任何现金或代币,只存放身份。

应用程序使用FileSystemWallet和Gateway类连接到区块链网络,在issue.js的最上面可以看到包括了这两个类。

const { FileSystemWallet, Gateway } = require('fabric-network');
应用程序使用Wallet类:

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

Gateway
issue.js连接到它的的网关:

await gateway.connect(connectionProfile, connectionOptions);
gateway.connect()有两个重要参数:

connectionProfile:标识了一系列对等节点网关的connection profile文件的系统位置。为了方便读使用了YAML,通过下面的代码加载转换为JSON对象。

let connectionProfile = yaml.safeLoad(file.readFileSync('./gateway/connectionProfile.yaml', 'utf8'));
connectionOptions:一系列用来控制issue.js(应用程序代码)如何连接到区块链网络的设置。它指定了连接到网关需要的了身份,userName和wallet,还可以通过SDK实现一些智能的行为。

let connectionOptions = {
identity: userName,
wallet: wallet,
eventHandlerOptions: {
commitTimeout: 100,
strategy: EventStrategies.MSPID_SCOPE_ANYFORTX
},
}
网关负责使用connect profile和connection options将transaction提议发送到正确的对等节点上。

posted @ 2023-01-19 20:04  20201303张奕博  阅读(43)  评论(0编辑  收藏  举报