Skip to content

Commit

Permalink
Add support for NullData addresses (OP_RETURN)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Jan 2, 2019
1 parent 18ee341 commit ac1eadd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/rpc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
obj.pushKV("witness_program", HexStr(id.program, id.program + id.length));
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)
Expand Down
15 changes: 15 additions & 0 deletions src/script/standard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
if (!Solver(scriptPubKey, whichType, vSolutions))
return false;

if (whichType == TX_NULL_DATA) {
// This is data, not addresses
return false;
}

if (whichType == TX_PUBKEY)
{
CPubKey pubKey(vSolutions[0]);
Expand Down Expand Up @@ -303,6 +308,16 @@ class CScriptVisitor : public boost::static_visitor<bool>
*script << CScript::EncodeOP_N(id.version) << std::vector<unsigned char>(id.program, id.program + id.length);
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

Expand Down
18 changes: 17 additions & 1 deletion src/script/standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
* * CNoDestination: no destination set
Expand All @@ -119,9 +134,10 @@ struct WitnessUnknown
* * WitnessV0ScriptHash: TX_WITNESS_V0_SCRIPTHASH destination (P2WSH)
* * WitnessV0KeyHash: TX_WITNESS_V0_KEYHASH destination (P2WPKH)
* * 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
*/
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. */
bool IsValidDestination(const CTxDestination& dest);
Expand Down
1 change: 1 addition & 0 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4185,6 +4185,7 @@ class DescribeWalletAddressVisitor : public boost::static_visitor<UniValue>
}

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)
Expand Down

0 comments on commit ac1eadd

Please sign in to comment.