From 7e182a1840d765ae28aaab11b6396d12f992eabb Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Fri, 6 Oct 2017 12:53:27 -0400 Subject: [PATCH] add getsidechaininfo RPC call --- qa/rpc-tests/pegging.py | 7 +++++++ src/rpc/blockchain.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/qa/rpc-tests/pegging.py b/qa/rpc-tests/pegging.py index e23bd6986f..e9635212c2 100755 --- a/qa/rpc-tests/pegging.py +++ b/qa/rpc-tests/pegging.py @@ -208,6 +208,13 @@ try: print("Success!") + # Testing sidechain info RPC + sideinfo = sidechain.getsidechaininfo() + assert sideinfo["fedpegscript"] == fedpeg_pubkey + assert sideinfo["pegged_asset"] == sidechain.dumpassetlabels()["bitcoin"] + assert sideinfo["min_peg_diff"] == "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + assert sideinfo["parent_blockhash"] == "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206" + except JSONRPCException as e: print("Pegging testing failed, aborting:") print(e.error) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 7951c058f5..d2efe56e11 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1109,6 +1109,38 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) return obj; } +UniValue getsidechaininfo(const JSONRPCRequest& request) +{ + if (request.fHelp || request.params.size() != 0) + throw runtime_error( + "getsidechaininfo\n" + "Returns an object containing various state info regarding sidechain functionality.\n" + "\nResult:\n" + "{\n" + " \"fedpegscript\": \"xxxx\", (string) The fedpegscript in hex\n" + " \"pegged_asset\" : \"xxxx\", (string) Pegged asset type in hex\n" + " \"min_peg_diff\" : \"xxxx\", (string) The minimum difficulty parent chain header target. Peg-in headers that have less work will be rejected as an anti-Dos measure.\n" + " \"parent_blockhash\" : \"xxxx\", (string) The parent genesis blockhash as source of pegged-in funds.\n" + "}\n" + "\nExamples:\n" + + HelpExampleCli("getsidechaininfo", "") + + HelpExampleRpc("getsidechaininfo", "") + ); + + LOCK(cs_main); + + const Consensus::Params& consensus = Params().GetConsensus(); + const uint256& parent_blockhash = Params().ParentGenesisBlockHash(); + + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("fedpegscript", HexStr(consensus.fedpegScript.begin(), consensus.fedpegScript.end()))); + obj.push_back(Pair("pegged_asset", consensus.pegged_asset.GetHex())); + obj.push_back(Pair("min_peg_diff", consensus.parentChainPowLimit.GetHex())); + obj.push_back(Pair("parent_blockhash", parent_blockhash.GetHex())); + return obj; +} + + /** Comparison function for sorting the getchaintips heads. */ struct CompareBlocksByHeight { @@ -1391,6 +1423,7 @@ static const CRPCCommand commands[] = { "blockchain", "getmempoolentry", &getmempoolentry, true, {"txid"} }, { "blockchain", "getmempoolinfo", &getmempoolinfo, true, {} }, { "blockchain", "getrawmempool", &getrawmempool, true, {"verbose"} }, + { "blockchain", "getsidechaininfo", &getsidechaininfo, true, {} }, { "blockchain", "gettxout", &gettxout, true, {"txid","n","include_mempool"} }, { "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true, {} }, { "blockchain", "pruneblockchain", &pruneblockchain, true, {"height"} },