mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 07:25:10 +00:00
[FAB-16390] Added filter for invalid transactions
Signed-off-by: Varun Agarwal <varunagarwal315@gmail.com>
Change-Id: Idb6c57e047bba9a176b312f86d05c2ee21aeb175
(cherry picked from commit f86ec95726)
This commit is contained in:
parent
1d3e267bbd
commit
91c720a7ff
1 changed files with 21 additions and 6 deletions
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright IBM Corp. All Rights Reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
|
@ -35,20 +35,35 @@ exports.processBlockEvent = async function (channelname, block, use_couchdb, nan
|
|||
|
||||
const dataArray = block.data.data;
|
||||
|
||||
// transaction filter for each transaction in dataArray
|
||||
const txSuccess = block.metadata.metadata[2];
|
||||
|
||||
for (var dataItem in dataArray) {
|
||||
|
||||
// reject if a timestamp is not set
|
||||
if (dataArray[dataItem].payload.header.channel_header.timestamp == undefined) {
|
||||
reject(new Error('Block timestamp is not defined'));
|
||||
reject(new Error('Transaction timestamp is not defined'));
|
||||
}
|
||||
|
||||
// tx may be rejected at commit stage by peers
|
||||
// only valid transactions (code=0) update the word state and off-chain db
|
||||
// filter through valid tx, refer below for list of error codes
|
||||
// https://github.com/hyperledger/fabric-sdk-node/blob/release-1.4/fabric-client/lib/protos/peer/transaction.proto
|
||||
if (txSuccess[dataItem] !== 0) {
|
||||
continue();
|
||||
}
|
||||
|
||||
const timestamp = dataArray[dataItem].payload.header.channel_header.timestamp;
|
||||
|
||||
// reject if no actions are set
|
||||
// continue to next tx if no actions are set
|
||||
if (dataArray[dataItem].payload.data.actions == undefined) {
|
||||
break;
|
||||
continue();
|
||||
}
|
||||
|
||||
// actions are stored as an array. In Fabric 1.4.3 only one
|
||||
// action exists per tx so we may simply use actions[0]
|
||||
// in case Fabric adds support for multiple actions
|
||||
// a for loop is used for demonstration
|
||||
const actions = dataArray[dataItem].payload.data.actions;
|
||||
|
||||
// iterate through all actions
|
||||
|
|
@ -79,7 +94,7 @@ exports.processBlockEvent = async function (channelname, block, use_couchdb, nan
|
|||
writeObject.timestamp = timestamp;
|
||||
writeObject.values = rwSet[record].rwset.writes;
|
||||
|
||||
console.log(`Block Timestamp: ${writeObject.timestamp}`);
|
||||
console.log(`Transaction Timestamp: ${writeObject.timestamp}`);
|
||||
console.log(`ChaincodeID: ${writeObject.chaincodeid}`);
|
||||
console.log(writeObject.values);
|
||||
|
||||
|
|
@ -198,4 +213,4 @@ function isJSON(value) {
|
|||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue