mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
Add calcfastmerkleroot RPC and test-framework support
This commit is contained in:
parent
3f902b0569
commit
01b03a9206
4 changed files with 51 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <chain.h>
|
#include <chain.h>
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
|
#include <consensus/merkle.h>
|
||||||
#include <core_io.h>
|
#include <core_io.h>
|
||||||
#include <crypto/ripemd160.h>
|
#include <crypto/ripemd160.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
|
|
@ -525,6 +526,22 @@ UniValue getpakinfo(const JSONRPCRequest& request)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniValue calcfastmerkleroot(const JSONRPCRequest& request)
|
||||||
|
{
|
||||||
|
std::vector<uint256> leaves;
|
||||||
|
for (const UniValue& leaf : request.params[0].get_array().getValues()) {
|
||||||
|
uint256 l;
|
||||||
|
l.SetHex(leaf.get_str());
|
||||||
|
leaves.push_back(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint256 root = ComputeFastMerkleRoot(leaves);
|
||||||
|
|
||||||
|
UniValue ret(UniValue::VOBJ);
|
||||||
|
ret.setStr(root.GetHex());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// END ELEMENTS CALLS
|
// END ELEMENTS CALLS
|
||||||
//
|
//
|
||||||
|
|
@ -543,6 +560,7 @@ static const CRPCCommand commands[] =
|
||||||
// ELEMENTS:
|
// ELEMENTS:
|
||||||
{ "util", "getpakinfo", &getpakinfo, {}},
|
{ "util", "getpakinfo", &getpakinfo, {}},
|
||||||
{ "util", "tweakfedpegscript", &tweakfedpegscript, {"claim_script"} },
|
{ "util", "tweakfedpegscript", &tweakfedpegscript, {"claim_script"} },
|
||||||
|
{ "hidden", "calcfastmerkleroot", &calcfastmerkleroot, {"leaves"} },
|
||||||
|
|
||||||
/* Not shown in help */
|
/* Not shown in help */
|
||||||
{ "hidden", "setmocktime", &setmocktime, {"timestamp"}},
|
{ "hidden", "setmocktime", &setmocktime, {"timestamp"}},
|
||||||
|
|
|
||||||
25
test/functional/rpc_calcfastmerkleroot.py
Executable file
25
test/functional/rpc_calcfastmerkleroot.py
Executable file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
from test_framework.util import assert_equal, calcfastmerkleroot
|
||||||
|
from test_framework import util
|
||||||
|
|
||||||
|
class CalcFastMerkleRoot(BitcoinTestFramework):
|
||||||
|
def set_test_params(self):
|
||||||
|
self.setup_clean_chain = True
|
||||||
|
self.num_nodes = 1
|
||||||
|
|
||||||
|
def run_test(self):
|
||||||
|
util.node_fastmerkle = self.nodes[0]
|
||||||
|
|
||||||
|
test_leaves = ["b66b041650db0f297b53f8d93c0e8706925bf3323f8c59c14a6fac37bfdcd06f", "99cb2fa68b2294ae133550a9f765fc755d71baa7b24389fed67d1ef3e5cb0255", "257e1b2fa49dd15724c67bac4df7911d44f6689860aa9f65a881ae0a2f40a303", "b67b0b9f093fa83d5e44b707ab962502b7ac58630e556951136196e65483bb80"]
|
||||||
|
test_roots = ["0000000000000000000000000000000000000000000000000000000000000000", "b66b041650db0f297b53f8d93c0e8706925bf3323f8c59c14a6fac37bfdcd06f", "f752938da0cb71c051aabdd5a86658e8d0b7ac00e1c2074202d8d2a79d8a6cf6", "245d364a28e9ad20d522c4a25ffc6a7369ab182f884e1c7dcd01aa3d32896bd3", "317d6498574b6ca75ee0368ec3faec75e096e245bdd5f36e8726fa693f775dfc"]
|
||||||
|
|
||||||
|
leaves = []
|
||||||
|
for i in range(4):
|
||||||
|
root = calcfastmerkleroot(leaves)
|
||||||
|
assert_equal(root, test_roots[i])
|
||||||
|
leaves.append(test_leaves[i])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
CalcFastMerkleRoot().main()
|
||||||
|
|
@ -22,6 +22,13 @@ from .authproxy import AuthServiceProxy, JSONRPCException
|
||||||
|
|
||||||
logger = logging.getLogger("TestFramework.utils")
|
logger = logging.getLogger("TestFramework.utils")
|
||||||
|
|
||||||
|
# This variable should be set to the node being used for CalcFastMerkleRoot calls
|
||||||
|
node_fastmerkle = None
|
||||||
|
|
||||||
|
def calcfastmerkleroot(leaves):
|
||||||
|
global node_fastmerkle
|
||||||
|
return node_fastmerkle.calcfastmerkleroot(leaves)
|
||||||
|
|
||||||
# Assert functions
|
# Assert functions
|
||||||
##################
|
##################
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ BASE_SCRIPTS = [
|
||||||
'feature_block_v4.py',
|
'feature_block_v4.py',
|
||||||
'feature_pak.py',
|
'feature_pak.py',
|
||||||
'feature_blocksign.py',
|
'feature_blocksign.py',
|
||||||
|
'rpc_calcfastmerkleroot.py',
|
||||||
# Longest test should go first, to favor running tests in parallel
|
# Longest test should go first, to favor running tests in parallel
|
||||||
'feature_fee_estimation.py',
|
'feature_fee_estimation.py',
|
||||||
'wallet_hd.py',
|
'wallet_hd.py',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue