From 3d301fd1fcc49e8af44301780c94eeac440e6f69 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 15 Mar 2011 13:55:47 +0000 Subject: [PATCH] Scan coinbase transaction outputs when receiving a block, in case generated blocks send coins to an address we have in the wallet. --- src/com/google/bitcoin/core/BlockChain.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/com/google/bitcoin/core/BlockChain.java b/src/com/google/bitcoin/core/BlockChain.java index 5675a001..d8963528 100644 --- a/src/com/google/bitcoin/core/BlockChain.java +++ b/src/com/google/bitcoin/core/BlockChain.java @@ -199,8 +199,8 @@ public class BlockChain { } private void scanTransaction(Transaction tx) throws ScriptException, VerificationException { - if (tx.isCoinBase()) return; for (TransactionOutput i : tx.outputs) { + // TODO: Handle more types of outputs, not just regular to address outputs. if (i.getScriptPubKey().isSentToIP()) return; byte[] pubKeyHash; pubKeyHash = i.getScriptPubKey().getPubKeyHash(); @@ -208,12 +208,18 @@ public class BlockChain { for (ECKey key : wallet.keychain) { if (Arrays.equals(pubKeyHash, key.getPubKeyHash())) { // We found a transaction that sends us money. - if (!wallet.isTransactionPresent(tx)) + if (!wallet.isTransactionPresent(tx)) { wallet.receive(tx); + } } } } } + + // Coinbase transactions don't have anything useful in their inputs (as they create coins out of thin air), + // so we can stop scanning at this point. + if (tx.isCoinBase()) return; + for (TransactionInput i : tx.inputs) { byte[] pubkey = i.getScriptSig().getPubKey(); synchronized (wallet) {