Auto merge of #4360 - oxarbitrage:issue3235, r=str4d
Add destination wrapper functions Closes #3235.
This commit is contained in:
commit
3f270a2afa
|
@ -616,7 +616,7 @@ CScript CChainParams::GetFoundersRewardScriptAtHeight(int nHeight) const {
|
|||
|
||||
CTxDestination address = DecodeDestination(GetFoundersRewardAddressAtHeight(nHeight).c_str());
|
||||
assert(IsValidDestination(address));
|
||||
assert(boost::get<CScriptID>(&address) != nullptr);
|
||||
assert(IsScriptDestination(address));
|
||||
CScriptID scriptID = boost::get<CScriptID>(address); // address is a boost variant
|
||||
CScript script = CScript() << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
|
||||
return script;
|
||||
|
|
|
@ -506,13 +506,13 @@ static bool getIndexKey(
|
|||
if (!IsValidDestination(dest)) {
|
||||
return false;
|
||||
}
|
||||
if (dest.type() == typeid(CKeyID)) {
|
||||
if (IsKeyDestination(dest)) {
|
||||
auto x = boost::get<CKeyID>(&dest);
|
||||
memcpy(&hashBytes, x->begin(), 20);
|
||||
type = CScript::P2PKH;
|
||||
return true;
|
||||
}
|
||||
if (dest.type() == typeid(CScriptID)) {
|
||||
if (IsScriptDestination(dest)) {
|
||||
auto x = boost::get<CScriptID>(&dest);
|
||||
memcpy(&hashBytes, x->begin(), 20);
|
||||
type = CScript::P2SH;
|
||||
|
|
|
@ -280,6 +280,14 @@ bool IsValidDestination(const CTxDestination& dest) {
|
|||
return dest.which() != 0;
|
||||
}
|
||||
|
||||
bool IsKeyDestination(const CTxDestination& dest) {
|
||||
return dest.which() == 1;
|
||||
}
|
||||
|
||||
bool IsScriptDestination(const CTxDestination& dest) {
|
||||
return dest.which() == 2;
|
||||
}
|
||||
|
||||
// insightexplorer
|
||||
CTxDestination DestFromAddressHash(int scriptType, uint160& addressHash)
|
||||
{
|
||||
|
|
|
@ -81,6 +81,12 @@ typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
|
|||
/** Check whether a CTxDestination is a CNoDestination. */
|
||||
bool IsValidDestination(const CTxDestination& dest);
|
||||
|
||||
/** Check whether a CTxDestination is a CKeyID. */
|
||||
bool IsKeyDestination(const CTxDestination& dest);
|
||||
|
||||
/** Check whether a CTxDestination is a CScriptID. */
|
||||
bool IsScriptDestination(const CTxDestination& dest);
|
||||
|
||||
/** Get the name of a txnouttype as a C string, or nullptr if unknown. */
|
||||
const char* GetTxnOutputType(txnouttype t);
|
||||
|
||||
|
|
|
@ -72,15 +72,15 @@ BOOST_AUTO_TEST_CASE(rpc_addmultisig)
|
|||
CTxDestination address;
|
||||
BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex), false));
|
||||
address = DecodeDestination(v.get_str());
|
||||
BOOST_CHECK(IsValidDestination(address) && boost::get<CScriptID>(&address) != nullptr);
|
||||
BOOST_CHECK(IsValidDestination(address) && IsScriptDestination(address));
|
||||
|
||||
BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(1, address1Hex, address2Hex), false));
|
||||
address = DecodeDestination(v.get_str());
|
||||
BOOST_CHECK(IsValidDestination(address) && boost::get<CScriptID>(&address) != nullptr);
|
||||
BOOST_CHECK(IsValidDestination(address) && IsScriptDestination(address));
|
||||
|
||||
BOOST_CHECK_NO_THROW(v = addmultisig(createArgs(2, address1Hex, address2Hex), false));
|
||||
address = DecodeDestination(v.get_str());
|
||||
BOOST_CHECK(IsValidDestination(address) && boost::get<CScriptID>(&address) != nullptr);
|
||||
BOOST_CHECK(IsValidDestination(address) && IsScriptDestination(address));
|
||||
|
||||
BOOST_CHECK_THROW(addmultisig(createArgs(0), false), runtime_error);
|
||||
BOOST_CHECK_THROW(addmultisig(createArgs(1), false), runtime_error);
|
||||
|
|
Loading…
Reference in New Issue