M prefix added for script addresses
This commit is contained in:
parent
347f110153
commit
3b03f2cc30
@ -212,12 +212,18 @@ class CBitcoinAddressVisitor : public boost::static_visitor<bool>
|
||||
{
|
||||
private:
|
||||
CBitcoinAddress* addr;
|
||||
CChainParams::Base58Type script_type_;
|
||||
|
||||
public:
|
||||
CBitcoinAddressVisitor(CBitcoinAddress* addrIn) : addr(addrIn) {}
|
||||
CBitcoinAddressVisitor(CBitcoinAddress* addrIn, CChainParams::Base58Type script_type)
|
||||
: addr(addrIn), script_type_(script_type)
|
||||
{
|
||||
assert(script_type == CChainParams::SCRIPT_ADDRESS ||
|
||||
script_type == CChainParams::SCRIPT_ADDRESS2);
|
||||
}
|
||||
|
||||
bool operator()(const CKeyID& id) const { return addr->Set(id); }
|
||||
bool operator()(const CScriptID& id) const { return addr->Set(id); }
|
||||
bool operator()(const CScriptID& id) const { return addr->Set(id, script_type_); }
|
||||
bool operator()(const CNoDestination& no) const { return false; }
|
||||
};
|
||||
|
||||
@ -229,15 +235,17 @@ bool CBitcoinAddress::Set(const CKeyID& id)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBitcoinAddress::Set(const CScriptID& id)
|
||||
bool CBitcoinAddress::Set(const CScriptID& id, CChainParams::Base58Type type)
|
||||
{
|
||||
SetData(Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS), &id, 20);
|
||||
assert(type == CChainParams::SCRIPT_ADDRESS || type == CChainParams::SCRIPT_ADDRESS2);
|
||||
SetData(Params().Base58Prefix(type), &id, 20);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBitcoinAddress::Set(const CTxDestination& dest)
|
||||
bool CBitcoinAddress::Set(const CTxDestination& dest, CChainParams::Base58Type type)
|
||||
{
|
||||
return boost::apply_visitor(CBitcoinAddressVisitor(this), dest);
|
||||
assert(type == CChainParams::SCRIPT_ADDRESS || type == CChainParams::SCRIPT_ADDRESS2);
|
||||
return boost::apply_visitor(CBitcoinAddressVisitor(this, type), dest);
|
||||
}
|
||||
|
||||
bool CBitcoinAddress::IsValid() const
|
||||
@ -249,7 +257,8 @@ bool CBitcoinAddress::IsValid(const CChainParams& params) const
|
||||
{
|
||||
bool fCorrectSize = vchData.size() == 20;
|
||||
bool fKnownVersion = vchVersion == params.Base58Prefix(CChainParams::PUBKEY_ADDRESS) ||
|
||||
vchVersion == params.Base58Prefix(CChainParams::SCRIPT_ADDRESS);
|
||||
vchVersion == params.Base58Prefix(CChainParams::SCRIPT_ADDRESS) ||
|
||||
vchVersion == params.Base58Prefix(CChainParams::SCRIPT_ADDRESS2);
|
||||
return fCorrectSize && fKnownVersion;
|
||||
}
|
||||
|
||||
@ -261,7 +270,8 @@ CTxDestination CBitcoinAddress::Get() const
|
||||
memcpy(&id, &vchData[0], 20);
|
||||
if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))
|
||||
return CKeyID(id);
|
||||
else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS))
|
||||
else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS) ||
|
||||
vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS2))
|
||||
return CScriptID(id);
|
||||
else
|
||||
return CNoDestination();
|
||||
@ -279,7 +289,8 @@ bool CBitcoinAddress::GetKeyID(CKeyID& keyID) const
|
||||
|
||||
bool CBitcoinAddress::IsScript() const
|
||||
{
|
||||
return IsValid() && vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS);
|
||||
return IsValid() && (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS) ||
|
||||
vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS2));
|
||||
}
|
||||
|
||||
void CBitcoinSecret::SetKey(const CKey& vchSecret)
|
||||
|
||||
@ -104,8 +104,8 @@ public:
|
||||
class CBitcoinAddress : public CBase58Data {
|
||||
public:
|
||||
bool Set(const CKeyID &id);
|
||||
bool Set(const CScriptID &id);
|
||||
bool Set(const CTxDestination &dest);
|
||||
bool Set(const CScriptID &id, CChainParams::Base58Type type=CChainParams::SCRIPT_ADDRESS2);
|
||||
bool Set(const CTxDestination &dest, CChainParams::Base58Type type=CChainParams::SCRIPT_ADDRESS2);
|
||||
bool IsValid() const;
|
||||
bool IsValid(const CChainParams ¶ms) const;
|
||||
|
||||
|
||||
@ -126,6 +126,7 @@ public:
|
||||
|
||||
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,48);
|
||||
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
|
||||
base58Prefixes[SCRIPT_ADDRESS2] = std::vector<unsigned char>(1,50);
|
||||
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,176);
|
||||
base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container<std::vector<unsigned char> >();
|
||||
base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container<std::vector<unsigned char> >();
|
||||
|
||||
@ -46,6 +46,7 @@ public:
|
||||
enum Base58Type {
|
||||
PUBKEY_ADDRESS,
|
||||
SCRIPT_ADDRESS,
|
||||
SCRIPT_ADDRESS2,
|
||||
SECRET_KEY,
|
||||
EXT_PUBLIC_KEY,
|
||||
EXT_SECRET_KEY,
|
||||
|
||||
@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
|
||||
continue;
|
||||
}
|
||||
CBitcoinAddress addrOut;
|
||||
BOOST_CHECK_MESSAGE(addrOut.Set(dest), "encode dest: " + strTest);
|
||||
BOOST_CHECK_MESSAGE(addrOut.Set(dest, CChainParams::SCRIPT_ADDRESS), "encode dest: " + strTest);
|
||||
BOOST_CHECK_MESSAGE(addrOut.ToString() == exp_base58string, "mismatch: " + strTest);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user