diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-06-09 21:11:59 +0200 |
---|---|---|
committer | JaSK <temp@temp.temp> | 2014-07-02 15:48:39 +0200 |
commit | d5087d1ba08142bdf135333a0da08ef0f5fc7ef0 (patch) | |
tree | 42c945e1a21db1c7b9bfe9a91f8ee47f9eb7b49a /src/rpcdump.cpp | |
parent | 0fa2f8899adf8f9f0ead29ba5d708ead6c5d4eaf (diff) |
Use script matching rather than destination matching for watch-only.
This changes the keystore data format, wallet format and IsMine logic
to detect watch-only outputs based on direct script matching rather
than first trying to convert outputs to destinations (addresses).
The reason is that we don't know how the software that has the spending
keys works. It may support the same types of scripts as us, but that is
not guaranteed. Furthermore, it removes the ambiguity between addresses
used as identifiers for output scripts or identifiers for public keys.
One practical implication is that adding a normal pay-to-pubkey-hash
address via importaddress will not cause payments to the corresponding
full public key to be detected as IsMine. If that is wanted, add those
scripts directly (importaddress now also accepts any hex-encoded script).
Conflicts:
src/wallet.cpp
Diffstat (limited to 'src/rpcdump.cpp')
-rw-r--r-- | src/rpcdump.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index 98af4695d6..e505d84b40 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -138,13 +138,19 @@ Value importaddress(const Array& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 3) throw runtime_error( "importaddress <address> [label] [rescan=true]\n" - "Adds an address that can be watched as if it were in your wallet but cannot be used to spend."); + "Adds an address or script (in hex) that can be watched as if it were in your wallet but cannot be used to spend."); + + CScript script; CBitcoinAddress address(params[0].get_str()); - if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); - CTxDestination dest; - dest = address.Get(); + if (address.IsValid()) { + script.SetDestination(address.Get()); + } else if (IsHex(params[0].get_str())) { + std::vector<unsigned char> data(ParseHex(params[0].get_str())); + script = CScript(data.begin(), data.end()); + } else { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address or script"); + } string strLabel = ""; if (params.size() > 1) @@ -159,15 +165,16 @@ Value importaddress(const Array& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); // add to address book or update label - pwalletMain->SetAddressBook(dest, strLabel, "receive"); + if (address.IsValid()) + pwalletMain->SetAddressBook(address.Get(), strLabel, "receive"); // Don't throw error in case an address is already there - if (pwalletMain->HaveWatchOnly(dest)) + if (pwalletMain->HaveWatchOnly(script)) return Value::null; pwalletMain->MarkDirty(); - if (!pwalletMain->AddWatchOnly(dest)) + if (!pwalletMain->AddWatchOnly(script)) throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet"); if (fRescan) |