下面的函数:
async function getPendingTransactions(address){
var pendingBlock = await web3.eth.getBlock('pending');
var i = 0;
var pendingTransactions = await pendingBlock.transactions.filter(async function(txHash) {
var tx = await web3.eth.getTransaction(txHash);
console.log(tx);
if(tx != null) {
return tx.from==address && tx.to == CONTRACT_ADDRESS;
}
});
console.log(pendingTransactions);
return pendingTransactions;
}
过滤器不起作用,所有交易都显示出来(console.log),并且过滤器循环似乎是在之后处理的。我猜这是一个async/await问题。如何保持过滤器同步?