node.js - 使用节点 sdk 在超级账本结构上升级链码
问题描述
我正在尝试使用来自 hyperledger 结构的 node-sdk 安装和升级链代码。但是我似乎遗漏了一些东西。
我能够在对等方上正确安装链代码,但是我无法升级它。我缺少某种 transactionId
基本上,我想使用 sdk 能够执行以下操作:
peer chaincode install -n mychaincode -p /path/to/chaincode -l node -v 0.0.2
peer chaincode upgrade -C mychannel -n mychaincode -l node -v 0.0.2 -c '{"Args": ["instantiate", "test"]}'
使用 SDK:
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccp, { wallet, identity: 'xxxx' });
const client = gateway.getClient();
const peers = client.getPeersForOrg('PeerMSP');
let installResponse = await client.installChaincode({
targets: peers,
chaincodePath: '/path/to/chaincode',
chaincodeId: 'mychaincode',
chaincodeVersion: '0.0.2',
chaincodeType: 'node',
channelNames: ['mychannel']
});
let channel = client.getChannel('mychannel');
let upgradeResponnse = await channel.sendUpgradeProposal({
targets: peers,
chaincodeType: 'node',
chaincodeId: 'mychaincode',
chaincodeVersion: '0.0.2',
args: ['instantiate', 'test'],
txId: ??????? <----------------------------------
});
我错过了什么?
解决方案
为了将来参考,我失踪了client.newTransactionID()
。
完整示例
// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccp, { wallet, identity: 'xxxx' });
const client = gateway.getClient();
const peers = client.getPeersForOrg('PeerMSP');
let installResponse = await client.installChaincode({
targets: peers,
chaincodePath: '/path/to/chaincode',
chaincodeId: 'chaincode',
chaincodeVersion: '0.0.2',
chaincodeType: 'node',
channelNames: ['mychannel']
});
let channel = client.getChannel('mychannel');
let proposalResponse = await channel.sendUpgradeProposal({
targets: peers,
chaincodeType: 'node',
chaincodeId: 'chaincode',
chaincodeVersion: '0.0.2',
args: ['test'],
fcn: 'instantiate',
txId: client.newTransactionID()
});
console.log(proposalResponse);
console.log('Sending the Transaction ..');
const transactionResponse = await channel.sendTransaction({
proposalResponses: proposalResponse[0],
proposal: proposalResponse[1]
});
console.log(transactionResponse);
推荐阅读
- authentication - 如何在烧瓶中使身份验证令牌/标头更易于访问
- mysql - mysql 在尝试使用 case 选择两个不同的内容时返回混合排序规则
- pandas - 有趣的熊猫 groupby 困惑
- jakarta-ee - CDI 事件和 EJB 观察者的安全上下文
- python - 按每个主题的唯一值移动日期
- r - 多个动态选项卡创建中的条件面板
- python - 使用 databricks-connect 的 Azure 数据块连接
- python - matplotlib 中所有子图的相同 x-ticks
- amazon-web-services - 如何使用 Systems Manager `运行命令`
- reactjs - React.js,如何使用带有 setState 回调的 map 和 async 函数?