From da2e3e6c98281f251d46272cdfc717c4e34f3b0c Mon Sep 17 00:00:00 2001 From: Devrandom Date: Wed, 13 Nov 2013 11:36:42 -0800 Subject: [PATCH] Support watching of scripts/addresses in wallet --- core/src/bitcoin.proto | 11 +- .../core/AbstractWalletEventListener.java | 7 + .../bitcoin/core/PeerFilterProvider.java | 2 + .../com/google/bitcoin/core/PeerGroup.java | 8 +- .../com/google/bitcoin/core/Transaction.java | 8 +- .../bitcoin/core/TransactionOutput.java | 21 + .../java/com/google/bitcoin/core/Wallet.java | 203 ++- .../bitcoin/core/WalletEventListener.java | 5 + .../jni/NativeWalletEventListener.java | 4 + .../com/google/bitcoin/script/Script.java | 48 +- .../store/WalletProtobufSerializer.java | 29 +- .../main/java/org/bitcoinj/wallet/Protos.java | 1121 +++++++++++++++-- .../bitcoin/core/BitcoindComparisonTool.java | 5 + .../com/google/bitcoin/core/WalletTest.java | 87 +- .../store/WalletProtobufSerializerTest.java | 12 + 15 files changed, 1451 insertions(+), 120 deletions(-) diff --git a/core/src/bitcoin.proto b/core/src/bitcoin.proto index 4223513e..5fac069d 100644 --- a/core/src/bitcoin.proto +++ b/core/src/bitcoin.proto @@ -77,6 +77,14 @@ message Key { optional int64 creation_timestamp = 5; } +message Script { + required bytes program = 1; + + // Timestamp stored as millis since epoch. Useful for skipping block bodies before this point + // when watching for scripts on the blockchain. + required int64 creation_timestamp = 2; +} + message TransactionInput { // Hash of the transaction this input is using. required bytes transaction_out_point_hash = 1; @@ -257,6 +265,7 @@ message Wallet { repeated Key key = 3; repeated Transaction transaction = 4; + repeated Script watched_script = 15; optional EncryptionType encryption_type = 5 [default=UNENCRYPTED]; optional ScryptParameters encryption_parameters = 6; @@ -280,5 +289,5 @@ message Wallet { // can be used to recover a compromised wallet, or just as part of preventative defence-in-depth measures. optional uint64 key_rotation_time = 13; - // Next tag: 15 + // Next tag: 16 } diff --git a/core/src/main/java/com/google/bitcoin/core/AbstractWalletEventListener.java b/core/src/main/java/com/google/bitcoin/core/AbstractWalletEventListener.java index af7a5701..60cf24aa 100644 --- a/core/src/main/java/com/google/bitcoin/core/AbstractWalletEventListener.java +++ b/core/src/main/java/com/google/bitcoin/core/AbstractWalletEventListener.java @@ -16,6 +16,8 @@ package com.google.bitcoin.core; +import com.google.bitcoin.script.Script; + import java.math.BigInteger; import java.util.List; @@ -48,6 +50,11 @@ public abstract class AbstractWalletEventListener implements WalletEventListener onChange(); } + @Override + public void onScriptsAdded(Wallet wallet, List