private void ScanTransactions(Block block, IDictionary<Wallet, List<Transaction>> walletToTxMap)
{
foreach (var tx in block.Transactions)
{
try
{
foreach (var wallet in _wallets)
{
var shouldReceive = false;
foreach (var output in tx.Outputs)
{
// TODO: Handle more types of outputs, not just regular to address outputs.
if (output.ScriptPubKey.IsSentToIp) continue;
// This is not thread safe as a key could be removed between the call to isMine and receive.
if (output.IsMine(wallet))
{
shouldReceive = true;
break;
}
}
// Coinbase transactions don't have anything useful in their inputs (as they create coins out of thin air).
if (!shouldReceive && !tx.IsCoinBase)
{
foreach (var i in tx.Inputs)
{
var pubkey = i.ScriptSig.PubKey;
// This is not thread safe as a key could be removed between the call to isPubKeyMine and receive.
if (wallet.IsPubKeyMine(pubkey))
{
shouldReceive = true;
}
}
}
if (!shouldReceive) continue;
List<Transaction> txList;
if (!walletToTxMap.TryGetValue(wallet, out txList))
{
txList = new List<Transaction>();
walletToTxMap[wallet] = txList;
}
txList.Add(tx);
}
}
catch (ScriptException e)
{
// We don't want scripts we don't understand to break the block chain so just note that this tx was
// not scanned here and continue.
_log.Warn("Failed to parse a script: " + e);
}
}
}