mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
RPC: If a scriptPubKey is a pegout, show pegout info too
This commit is contained in:
parent
8cea3b4d45
commit
190339bcda
3 changed files with 87 additions and 11 deletions
|
|
@ -63,28 +63,46 @@ public:
|
||||||
};
|
};
|
||||||
static RPCRawTransaction_ECC_Init ecc_init_on_load;
|
static RPCRawTransaction_ECC_Init ecc_init_on_load;
|
||||||
|
|
||||||
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
|
static void SidehainScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool is_parent_chain)
|
||||||
{
|
{
|
||||||
|
const std::string prefix = is_parent_chain ? "pegout_" : "";
|
||||||
txnouttype type;
|
txnouttype type;
|
||||||
vector<CTxDestination> addresses;
|
vector<CTxDestination> addresses;
|
||||||
int nRequired;
|
int nRequired;
|
||||||
|
|
||||||
out.push_back(Pair("asm", ScriptToAsmStr(scriptPubKey)));
|
out.push_back(Pair(prefix + "asm", ScriptToAsmStr(scriptPubKey)));
|
||||||
if (fIncludeHex)
|
if (fIncludeHex)
|
||||||
out.push_back(Pair("hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
|
out.push_back(Pair(prefix + "hex", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
|
||||||
|
|
||||||
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
|
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired)) {
|
||||||
out.push_back(Pair("type", GetTxnOutputType(type)));
|
out.push_back(Pair(prefix + "type", GetTxnOutputType(type)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.push_back(Pair("reqSigs", nRequired));
|
out.push_back(Pair(prefix + "reqSigs", nRequired));
|
||||||
out.push_back(Pair("type", GetTxnOutputType(type)));
|
out.push_back(Pair(prefix + "type", GetTxnOutputType(type)));
|
||||||
|
|
||||||
UniValue a(UniValue::VARR);
|
UniValue a(UniValue::VARR);
|
||||||
BOOST_FOREACH(const CTxDestination& addr, addresses)
|
if (is_parent_chain) {
|
||||||
a.push_back(CBitcoinAddress(addr).ToString());
|
BOOST_FOREACH(const CTxDestination& addr, addresses)
|
||||||
out.push_back(Pair("addresses", a));
|
a.push_back(CParentBitcoinAddress(addr).ToString());
|
||||||
|
} else {
|
||||||
|
BOOST_FOREACH(const CTxDestination& addr, addresses)
|
||||||
|
a.push_back(CBitcoinAddress(addr).ToString());
|
||||||
|
}
|
||||||
|
out.push_back(Pair(prefix + "addresses", a));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
|
||||||
|
{
|
||||||
|
SidehainScriptPubKeyToJSON(scriptPubKey, out, fIncludeHex, false);
|
||||||
|
|
||||||
|
uint256 pegout_chain;
|
||||||
|
CScript pegout_scriptpubkey;
|
||||||
|
if (scriptPubKey.IsPegoutScript(pegout_chain, pegout_scriptpubkey)) {
|
||||||
|
out.push_back(Pair("pegout_chain", pegout_chain.GetHex()));
|
||||||
|
SidehainScriptPubKeyToJSON(pegout_scriptpubkey, out, fIncludeHex, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
|
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
|
||||||
|
|
@ -279,6 +297,15 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
|
||||||
" \"reqSigs\" : n, (numeric) The required sigs\n"
|
" \"reqSigs\" : n, (numeric) The required sigs\n"
|
||||||
" \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
|
" \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n"
|
||||||
" \"addresses\" : [ (json array of string)\n"
|
" \"addresses\" : [ (json array of string)\n"
|
||||||
|
" \"address\" (string) elements address\n"
|
||||||
|
" ,...\n"
|
||||||
|
" ]\n"
|
||||||
|
" \"pegout_chain\" : \"hex\", (string) (only pegout) Hash of genesis block of parent chain'\n"
|
||||||
|
" \"pegout_asm\":\"asm\", (string) (only pegout) pegout scriptpubkey (asm)'\n"
|
||||||
|
" \"pegout_hex\":\"hex\", (string) (only pegout) pegout scriptpubkey (hex)'\n"
|
||||||
|
" \"pegout_reqSigs\" : n, (numeric) (only pegout) pegout required sigs\n"
|
||||||
|
" \"pegout_type\" : \"pubkeyhash\", (string) (only pegout) The pegout type, eg 'pubkeyhash'\n"
|
||||||
|
" \"pegout_addresses\" : [ (json array of string) (only pegout)\n"
|
||||||
" \"address\" (string) bitcoin address\n"
|
" \"address\" (string) bitcoin address\n"
|
||||||
" ,...\n"
|
" ,...\n"
|
||||||
" ]\n"
|
" ]\n"
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,43 @@ unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
|
||||||
return subscript.GetSigOpCount(true);
|
return subscript.GetSigOpCount(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CScript::IsPegoutScript(uint256& genesis_hash, CScript& pegout_scriptpubkey) const
|
||||||
|
{
|
||||||
|
const_iterator pc = begin();
|
||||||
|
std::vector<unsigned char> data;
|
||||||
|
opcodetype opcode;
|
||||||
|
|
||||||
|
// OP_RETURN
|
||||||
|
if (!GetOp(pc, opcode, data) || opcode != OP_RETURN) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GetOp(pc, opcode, data) || data.size() != 32 ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
genesis_hash = uint256(data);
|
||||||
|
|
||||||
|
// Read in parent chain destination scriptpubkey
|
||||||
|
if (!GetOp(pc, opcode, data) || data.size() == 0 ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pegout_scriptpubkey = CScript(data.begin(), data.end());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CScript::IsPegoutScript(const uint256& genesis_hash_check) const
|
||||||
|
{
|
||||||
|
uint256 genesis_hash;
|
||||||
|
CScript pegout_scriptpubkey;
|
||||||
|
// Ensure hash matches parent chain genesis block
|
||||||
|
if (this->IsPegoutScript(genesis_hash, pegout_scriptpubkey) &&
|
||||||
|
genesis_hash_check == genesis_hash) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CScript::IsPayToScriptHash() const
|
bool CScript::IsPayToScriptHash() const
|
||||||
{
|
{
|
||||||
// Extra-fast test for pay-to-script-hash CScripts:
|
// Extra-fast test for pay-to-script-hash CScripts:
|
||||||
|
|
|
||||||
|
|
@ -637,6 +637,18 @@ public:
|
||||||
bool IsPayToWitnessScriptHash() const;
|
bool IsPayToWitnessScriptHash() const;
|
||||||
bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const;
|
bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if script follows OP_RETURN <genesis_block_hash> <pegout_scriptpubkey>
|
||||||
|
* and if correct it returns both things in the output parameters.
|
||||||
|
*/
|
||||||
|
bool IsPegoutScript(uint256& genesis_hash, CScript& pegout_scriptpubkey) const;
|
||||||
|
/**
|
||||||
|
* Returns true if script follows OP_RETURN <genesis_block_hash> <destination_scriptpubkey>
|
||||||
|
* it may also have additional pushes at the end. It checks
|
||||||
|
* the genesis hash matches the specified one.
|
||||||
|
*/
|
||||||
|
bool IsPegoutScript(const uint256& genesis_hash) const;
|
||||||
|
|
||||||
/** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */
|
/** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */
|
||||||
bool IsPushOnly(const_iterator pc) const;
|
bool IsPushOnly(const_iterator pc) const;
|
||||||
bool IsPushOnly() const;
|
bool IsPushOnly() const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue