mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-21 17:15: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
|
|
@ -35,20 +35,35 @@ exports.processBlockEvent = async function (channelname, block, use_couchdb, nan
|
||||||
|
|
||||||
const dataArray = block.data.data;
|
const dataArray = block.data.data;
|
||||||
|
|
||||||
|
// transaction filter for each transaction in dataArray
|
||||||
|
const txSuccess = block.metadata.metadata[2];
|
||||||
|
|
||||||
for (var dataItem in dataArray) {
|
for (var dataItem in dataArray) {
|
||||||
|
|
||||||
// reject if a timestamp is not set
|
// reject if a timestamp is not set
|
||||||
if (dataArray[dataItem].payload.header.channel_header.timestamp == undefined) {
|
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;
|
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) {
|
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;
|
const actions = dataArray[dataItem].payload.data.actions;
|
||||||
|
|
||||||
// iterate through all actions
|
// iterate through all actions
|
||||||
|
|
@ -79,7 +94,7 @@ exports.processBlockEvent = async function (channelname, block, use_couchdb, nan
|
||||||
writeObject.timestamp = timestamp;
|
writeObject.timestamp = timestamp;
|
||||||
writeObject.values = rwSet[record].rwset.writes;
|
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(`ChaincodeID: ${writeObject.chaincodeid}`);
|
||||||
console.log(writeObject.values);
|
console.log(writeObject.values);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue