mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-25 19:15:10 +00:00
Fix addBlockListener callback function
This commit is contained in:
parent
89f1354e2b
commit
709346ffa7
1 changed files with 6 additions and 9 deletions
|
|
@ -16,7 +16,7 @@ Configuration is stored in config.json:
|
||||||
"peer_name": "peer0.org1.example.com",
|
"peer_name": "peer0.org1.example.com",
|
||||||
"channelid": "mychannel",
|
"channelid": "mychannel",
|
||||||
"use_couchdb":false,
|
"use_couchdb":false,
|
||||||
"couchdb_address": "http://localhost:5990"
|
"couchdb_address": "http://admin:adminpw@localhost:5990"
|
||||||
}
|
}
|
||||||
|
|
||||||
peer_name: target peer for the listener
|
peer_name: target peer for the listener
|
||||||
|
|
@ -117,12 +117,10 @@ async function main() {
|
||||||
const network = await gateway.getNetwork('mychannel');
|
const network = await gateway.getNetwork('mychannel');
|
||||||
|
|
||||||
const listener = await network.addBlockListener(
|
const listener = await network.addBlockListener(
|
||||||
async (err, blockNum, block) => {
|
async (event) => {
|
||||||
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
|
||||||
|
const blockNum = event.blockNumber.low;
|
||||||
|
const block = event.blockData;
|
||||||
await ProcessingMap.set(block.header.number, block);
|
await ProcessingMap.set(block.header.number, block);
|
||||||
|
|
||||||
console.log(`Added block ${blockNum} to ProcessingMap`)
|
console.log(`Added block ${blockNum} to ProcessingMap`)
|
||||||
|
|
@ -144,7 +142,6 @@ async function main() {
|
||||||
|
|
||||||
// listener function to check for blocks in the ProcessingMap
|
// listener function to check for blocks in the ProcessingMap
|
||||||
async function processPendingBlocks(ProcessingMap) {
|
async function processPendingBlocks(ProcessingMap) {
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
|
|
||||||
// get the next block number from nextblock.txt
|
// get the next block number from nextblock.txt
|
||||||
|
|
@ -155,11 +152,11 @@ async function processPendingBlocks(ProcessingMap) {
|
||||||
|
|
||||||
// get the next block to process from the ProcessingMap
|
// get the next block to process from the ProcessingMap
|
||||||
processBlock = ProcessingMap.get(nextBlockNumber)
|
processBlock = ProcessingMap.get(nextBlockNumber)
|
||||||
|
|
||||||
if (processBlock == undefined) {
|
if (processBlock == undefined) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("call block processing event")
|
||||||
try {
|
try {
|
||||||
await blockProcessing.processBlockEvent(channelid, processBlock, use_couchdb, nano)
|
await blockProcessing.processBlockEvent(channelid, processBlock, use_couchdb, nano)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue