This question is related to this one or this one. There is a tutorial here that shows some filtering examples but it doesn't get into transaction level granularity. Can we query the block chain by transaction and process specific transactions asynchronously?
For example, this code goes through blocks starting and ending with a given block number and displays each transaction to or from a given address:
function getTransactionsByAccounts(myaccount, startBlockNumber, endBlockNumber) {
console.log("Searching for transactions to/from account \"" + myaccount + "\" within blocks " + startBlockNumber + " and " + endBlockNumber + "\"");
for (var i = startBlockNumber; i <= endBlockNumber; i++) {
var block = eth.getBlock(i, true);
if (block != null && block.transactions != null) {
block.transactions.forEach( function(e) {
if (myaccount == "*" || myaccount == e.from || myaccount == e.to) {
console.log(" tx hash : " + e.hash + "\n"
+ " nonce : " + e.nonce + "\n"
+ " blockHash : " + e.blockHash + "\n"
+ " blockNumber : " + e.blockNumber + "\n"
+ " transactionIndex: " + e.transactionIndex + "\n"
+ " from : " + e.from + "\n"
+ " to : " + e.to + "\n"
+ " value : " + e.value + "\n"
+ " gasPrice : " + e.gasPrice + "\n"
+ " gas : " + e.gas + "\n"
+ " input : " + e.input);
// Do something asynchronously with the transaction:
call_async_method(e); // <== HOW CAN WE ADD THIS AS A PROMISE?
}
})
}
}
}
How can we process a transaction asynchronously (as shown in the code)? possibly using promises and the filters defined in web3.js.