簡體   English   中英

使用節點SDK在Hyperledger Fabric上升級Chaincode

[英]Upgrade Chaincode on hyperledger fabric using node sdk

我正在嘗試使用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: ??????? <----------------------------------
});

我想念什么?

為了將來參考,我缺少了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);

每當升級鏈碼時,都需要更改其版本。 我看到您對兩個命令都使用了相同的版本0.0.2 請更改並檢查。

對等鏈代碼升級-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')“

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM