使用节点sdk在超级边缘结构上升级Chaincode

问题描述 投票:0回答:2

我正在尝试使用来自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: ??????? <----------------------------------
});

我错过了什么?

node.js hyperledger-fabric hyperledger
2个回答
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
投票

无论何时升级链码,您都需要更改其版本。我看到你使用相同版本的0.0.2这两个命令。 Plz改变并检查。

peer chaincode upgrade -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')“

© www.soinside.com 2019 - 2024. All rights reserved.