Add support for NullData addresses (OP_RETURN)

This commit is contained in:
Steven Roose 2018-12-11 13:24:44 +01:00
parent 18ee3417d8
commit ac1eadd0de
4 changed files with 41 additions and 1 deletions

View file

@ -120,6 +120,14 @@ public:
obj.pushKV("witness_program", HexStr(id.program, id.program + id.length)); obj.pushKV("witness_program", HexStr(id.program, id.program + id.length));
return obj; return obj;
} }
UniValue operator()(const NullData& id) const
{
UniValue obj(UniValue::VOBJ);
obj.pushKV("isscript", false);
obj.pushKV("iswitness", false);
return obj;
}
}; };
UniValue DescribeAddress(const CTxDestination& dest) UniValue DescribeAddress(const CTxDestination& dest)

View file

@ -177,6 +177,11 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
if (!Solver(scriptPubKey, whichType, vSolutions)) if (!Solver(scriptPubKey, whichType, vSolutions))
return false; return false;
if (whichType == TX_NULL_DATA) {
// This is data, not addresses
return false;
}
if (whichType == TX_PUBKEY) if (whichType == TX_PUBKEY)
{ {
CPubKey pubKey(vSolutions[0]); CPubKey pubKey(vSolutions[0]);
@ -303,6 +308,16 @@ public:
*script << CScript::EncodeOP_N(id.version) << std::vector<unsigned char>(id.program, id.program + id.length); *script << CScript::EncodeOP_N(id.version) << std::vector<unsigned char>(id.program, id.program + id.length);
return true; return true;
} }
bool operator()(const NullData& id) const
{
script->clear();
*script << OP_RETURN;
for (const auto& push : id.null_data) {
*script << push;
}
return true;
}
}; };
} // namespace } // namespace

View file

@ -111,6 +111,21 @@ struct WitnessUnknown
} }
}; };
// ELEMENTS:
class NullData
{
public:
std::vector<std::vector<unsigned char>> null_data;
friend bool operator==(const NullData &a, const NullData &b) { return true; }
friend bool operator<(const NullData &a, const NullData &b) { return true; }
NullData& operator<<(std::vector<unsigned char> b)
{
null_data.push_back(b);
return *this;
}
};
/** /**
* A txout script template with a specific destination. It is either: * A txout script template with a specific destination. It is either:
* * CNoDestination: no destination set * * CNoDestination: no destination set
@ -119,9 +134,10 @@ struct WitnessUnknown
* * WitnessV0ScriptHash: TX_WITNESS_V0_SCRIPTHASH destination (P2WSH) * * WitnessV0ScriptHash: TX_WITNESS_V0_SCRIPTHASH destination (P2WSH)
* * WitnessV0KeyHash: TX_WITNESS_V0_KEYHASH destination (P2WPKH) * * WitnessV0KeyHash: TX_WITNESS_V0_KEYHASH destination (P2WPKH)
* * WitnessUnknown: TX_WITNESS_UNKNOWN destination (P2W???) * * WitnessUnknown: TX_WITNESS_UNKNOWN destination (P2W???)
* * NullData: TX_NULL_DATA destination (OP_RETURN)
* A CTxDestination is the internal data type encoded in a bitcoin address * A CTxDestination is the internal data type encoded in a bitcoin address
*/ */
typedef boost::variant<CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown> CTxDestination; typedef boost::variant<CNoDestination, CKeyID, CScriptID, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown, NullData> CTxDestination;
/** Check whether a CTxDestination is a CNoDestination. */ /** Check whether a CTxDestination is a CNoDestination. */
bool IsValidDestination(const CTxDestination& dest); bool IsValidDestination(const CTxDestination& dest);

View file

@ -4185,6 +4185,7 @@ public:
} }
UniValue operator()(const WitnessUnknown& id) const { return UniValue(UniValue::VOBJ); } UniValue operator()(const WitnessUnknown& id) const { return UniValue(UniValue::VOBJ); }
UniValue operator()(const NullData& id) const { return NullUniValue; }
}; };
static UniValue DescribeWalletAddress(CWallet* pwallet, const CTxDestination& dest) static UniValue DescribeWalletAddress(CWallet* pwallet, const CTxDestination& dest)