diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2012-08-26 22:43:42 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-08-26 22:43:42 +0000 |
commit | 01cc7bf0c5f7ebe0a3cde208edf5fceac9d2e1fb (patch) | |
tree | e190a87befb898f295f0b9a53e9000ce48d7eb7f /src | |
parent | bfd2ddfc47dc9157f919b3c21ce985121af1c61b (diff) |
Support sending to script (P2SH) addresses
Upstream partials from 9e470585b35a84fcb7f6aa41ac0216c117e2a5e1, e679ec969c8b22c676ebb10bea1038f6c8f13b33, and 922e8e2929a2e78270868385aa46f96002fbcff3.
Diffstat (limited to 'src')
-rw-r--r-- | src/base58.h | 18 | ||||
-rw-r--r-- | src/script.h | 5 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/base58.h b/src/base58.h index af1022dfc0..9fe80781bd 100644 --- a/src/base58.h +++ b/src/base58.h @@ -242,6 +242,14 @@ public: class CBitcoinAddress : public CBase58Data { public: + enum + { + PUBKEY_ADDRESS = 0, + SCRIPT_ADDRESS = 5, + PUBKEY_ADDRESS_TEST = 111, + SCRIPT_ADDRESS_TEST = 196, + }; + bool SetHash160(const uint160& hash160) { SetData(fTestNet ? 111 : 0, &hash160, 20); @@ -260,9 +268,11 @@ public: switch(nVersion) { case 0: + case SCRIPT_ADDRESS: break; case 111: + case SCRIPT_ADDRESS_TEST: fExpectTestNet = true; break; @@ -271,6 +281,14 @@ public: } return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize; } + bool IsScript() const + { + if (!IsValid()) + return false; + if (fTestNet) + return nVersion == SCRIPT_ADDRESS_TEST; + return nVersion == SCRIPT_ADDRESS; + } CBitcoinAddress() { diff --git a/src/script.h b/src/script.h index 8dddb893f4..7f4aaae2d5 100644 --- a/src/script.h +++ b/src/script.h @@ -654,7 +654,10 @@ public: void SetBitcoinAddress(const CBitcoinAddress& address) { this->clear(); - *this << OP_DUP << OP_HASH160 << address.GetHash160() << OP_EQUALVERIFY << OP_CHECKSIG; + if (address.IsScript()) + *this << OP_HASH160 << address.GetHash160() << OP_EQUAL; + else + *this << OP_DUP << OP_HASH160 << address.GetHash160() << OP_EQUALVERIFY << OP_CHECKSIG; } void SetBitcoinAddress(const std::vector<unsigned char>& vchPubKey) |