mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
Merge pull request #1114 from stevenroose/fix-dynafed-json
Improve the JSON representation of dynafed parameters
This commit is contained in:
commit
b4d4b1a2c1
2 changed files with 46 additions and 12 deletions
|
|
@ -110,14 +110,46 @@ double GetDifficulty(const CBlockIndex* blockindex)
|
|||
UniValue paramEntryToJSON(const DynaFedParamEntry& entry)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
|
||||
// set the type
|
||||
if (entry.m_serialize_type == 0) {
|
||||
result.pushKV("type", "null");
|
||||
} else if (entry.m_serialize_type == 1) {
|
||||
result.pushKV("type", "compact");
|
||||
} else if (entry.m_serialize_type == 2) {
|
||||
result.pushKV("type", "full");
|
||||
}
|
||||
|
||||
// nothing more to do for null
|
||||
if (entry.m_serialize_type == 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// fields all params have
|
||||
result.pushKV("root", HexStr(entry.CalculateRoot()));
|
||||
result.pushKV("signblockscript", HexStr(entry.m_signblockscript));
|
||||
result.pushKV("max_block_witness", (uint64_t)entry.m_signblock_witness_limit);
|
||||
result.pushKV("fedpegscript", HexStr(entry.m_fedpegscript));
|
||||
UniValue result_extension(UniValue::VARR);
|
||||
for (auto& item : entry.m_extension_space) {
|
||||
result_extension.push_back(HexStr(item));
|
||||
|
||||
// add the extra root which is stored for compact and calculated for full
|
||||
if (entry.m_serialize_type == 1) {
|
||||
// compact
|
||||
result.pushKV("extra_root", HexStr(entry.m_elided_root));
|
||||
} else if (entry.m_serialize_type == 2) {
|
||||
// full
|
||||
result.pushKV("extra_root", HexStr(entry.CalculateExtraRoot()));
|
||||
}
|
||||
result.pushKV("extension_space", result_extension);
|
||||
|
||||
// some extra fields only present on full params
|
||||
if (entry.m_serialize_type == 2) {
|
||||
result.pushKV("fedpeg_program", HexStr(entry.m_fedpeg_program));
|
||||
result.pushKV("fedpegscript", HexStr(entry.m_fedpegscript));
|
||||
UniValue result_extension(UniValue::VARR);
|
||||
for (auto& item : entry.m_extension_space) {
|
||||
result_extension.push_back(HexStr(item));
|
||||
}
|
||||
result.pushKV("extension_space", result_extension);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ def go_to_epoch_end(node):
|
|||
node.generatetoaddress(blocks_to_mine, node.getnewaddress())
|
||||
|
||||
def validate_no_vote_op_true(node, block, first_dynafed_active_block):
|
||||
|
||||
block_info = node.getblock(block)
|
||||
dynamic_parameters = block_info["dynamic_parameters"]
|
||||
block_height = block_info["height"]
|
||||
|
|
@ -48,18 +47,21 @@ def validate_no_vote_op_true(node, block, first_dynafed_active_block):
|
|||
WSH_OP_TRUE = node.decodescript("51")["segwit"]["hex"]
|
||||
assert_equal(dynamic_parameters["current"]["signblockscript"], WSH_OP_TRUE)
|
||||
if block_height % 10 == 0 or first_dynafed_active_block:
|
||||
assert_equal(dynamic_parameters["current"]["type"], "full")
|
||||
assert_equal(dynamic_parameters["current"]["fedpegscript"], "51")
|
||||
assert_equal(dynamic_parameters["current"]["extension_space"], initial_extension)
|
||||
else:
|
||||
assert_equal(dynamic_parameters["current"]["fedpegscript"], "")
|
||||
assert_equal(dynamic_parameters["current"]["extension_space"], [])
|
||||
assert_equal(dynamic_parameters["current"]["type"], "compact")
|
||||
assert not "fedpegscript" in dynamic_parameters["proposed"]
|
||||
assert not "extension_space" in dynamic_parameters["proposed"]
|
||||
assert_equal(dynamic_parameters["current"]["max_block_witness"], 74)
|
||||
# nothing was proposed, null fields make impossible to be valid blockheader
|
||||
# due to script rules requiring bool true on stack
|
||||
assert_equal(dynamic_parameters["proposed"]["signblockscript"], "")
|
||||
assert_equal(dynamic_parameters["proposed"]["fedpegscript"], "")
|
||||
assert_equal(dynamic_parameters["proposed"]["max_block_witness"], 0)
|
||||
assert_equal(dynamic_parameters["proposed"]["extension_space"], [])
|
||||
assert_equal(dynamic_parameters["proposed"]["type"], "null")
|
||||
assert not "signblockscript" in dynamic_parameters["proposed"]
|
||||
assert not "max_block_witness" in dynamic_parameters["proposed"]
|
||||
assert not "fedpegscript" in dynamic_parameters["proposed"]
|
||||
assert not "extension_space" in dynamic_parameters["proposed"]
|
||||
|
||||
class DynaFedTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue