使用节点SDK在Hyperledger Fabric上升级Chaincode

时间:2019-03-13 10:59:45

标签: node.js hyperledger-fabric hyperledger

我正在尝试使用超级账本结构中的node-sdk安装和升级Chaincode。但是我似乎丢失了一些东西。

我能够在对等节点上正确安装链码,但是我无法对其进行升级。我缺少某种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: ??????? <----------------------------------
});

我想念什么?

2 个答案:

答案 0 :(得分:2)

为了以后的参考,我错过了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);

答案 1 :(得分:-1)

无论何时升级链码,都需要更改其版本。我看到您对两个命令都使用相同的版本$File = Get-Content File.txt $NumberOfBadLines = 5 $FirstBadLine = $File.IndexOf("other text") $file[0..($firstbadline-1)+($firstbadline+$NumberOfBadLines)..$file.count] | Set-Content File.txt 。请更改并检查。

  

对等链码升级-o orderer.example.com:7050 --tls --cafile   $ ORDERER_CA -C mychannel -n mycc -v 0.0.3 -c   '{“ Args”:[“ init”,“ a”,“ 100”,“ b”,“ 200”,“ c”,“ 300”]}'-P“ AND   (“ Org1MSP.peer”,“ Org2MSP.peer”)”