Support sending to script (P2SH) addresses

Upstream partials from 9e470585b3, e679ec969c, and 922e8e2929.
This commit is contained in:
Luke Dashjr
2012-08-26 22:43:42 +00:00
parent bfd2ddfc47
commit 01cc7bf0c5
2 changed files with 22 additions and 1 deletions

View File

@@ -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()
{

View File

@@ -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)