根据Fabric SDK 文档,Channel.queryBlock 返回一个块的 Promise。可以查询返回的 Block 对象以提取各种字段,例如
channel = client.getChannel(channelName);
return channel.queryBlock(blockNumber);
}).then((block) => {
console.log('Block Number: ' + block.header.number);
console.log('Previous Hash: ' + block.header.previous_hash);
console.log('Data Hash: ' + block.header.data_hash);
console.log('Transactions: ' + block.data.data.length);
block.data.data.forEach(transaction => {
console.log('Transaction ID: ' + transaction.payload.header.channel_header.tx_id);
console.log('Creator ID: ' + transaction.payload.header.signature_header.creator.Mspid);
console.log('Data: ');
console.log(JSON.stringify(transaction.payload.data));
});
});
一些示例输出:
Block Number: 4
Previous Hash: b794ee910514f989c0bcb54c2d26d907fca65eb9dd60e86047b3c3c78b96cb96
Data Hash: 1e267340a5f57ea687bfd6b57aec51b5e16420921fb50f980d08f1302bd289be
Transactions: 1
Transaction ID: 49c1333402977a53ec2532a4d425ef8bd6e3efa546358d3d2e3be645ee32b6c0
Creator ID: Org1MSP
Data:
{"actions":[{"header":{"creator":{"Mspid":"Org1MSP","IdBytes":"-----BEGIN CERTIFICATE-----...
Block 对象的结构在此处完整记录。