mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 17:45:10 +00:00
Fix off_chain_data to put data to off-chain database (#457)
The off_chain_data sample fails to put data to the off-chain database. The application does not read fetched blocks because it uses the old interface of `addBlockListener()` to handle block events. This PR fixes the application to use the latest block listener and build the off-chain database. Signed-off-by: Yuki Kondo <yuki.kondo.ob@hitachi.com>
This commit is contained in:
parent
0d64a1b70c
commit
d5d8ff1539
1 changed files with 7 additions and 14 deletions
|
|
@ -116,20 +116,13 @@ async function main() {
|
||||||
// Get the network (channel) our contract is deployed to.
|
// Get the network (channel) our contract is deployed to.
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
||||||
const listener = await network.addBlockListener(
|
const listener = async (event) => {
|
||||||
async (err, blockNum, block) => {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Add the block to the processing map by block number
|
// Add the block to the processing map by block number
|
||||||
await ProcessingMap.set(block.header.number, block);
|
await ProcessingMap.set(event.blockNumber, event.blockData);
|
||||||
|
console.log(`Added block ${event.blockNumber} to ProcessingMap`);
|
||||||
console.log(`Added block ${blockNum} to ProcessingMap`)
|
};
|
||||||
},
|
const options = { filtered: false, startBlock: parseInt(nextBlock, 10) };
|
||||||
// set the starting block for the listener
|
await network.addBlockListener(listener, options);
|
||||||
{ filtered: false, startBlock: parseInt(nextBlock, 10) }
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log(`Listening for block events, nextblock: ${nextBlock}`);
|
console.log(`Listening for block events, nextblock: ${nextBlock}`);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue