diff --git a/qa/rpc-tests/createauxblock.py b/qa/rpc-tests/createauxblock.py index 2c82c85ef..d0dbbc1f9 100644 --- a/qa/rpc-tests/createauxblock.py +++ b/qa/rpc-tests/createauxblock.py @@ -23,7 +23,7 @@ class CreateAuxBlockTest(BitcoinTestFramework): def setup_network(self): self.nodes = [] self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-txindex"])) - self.nodes.append(start_node(1, self.options.tmpdir, ["-debug"])) + self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-rpcnamecoinapi"])) connect_nodes_bi(self.nodes, 0, 1) self.sync_all() @@ -170,6 +170,25 @@ class CreateAuxBlockTest(BitcoinTestFramework): except JSONRPCException as exc: assert_equal(exc.error["code"], -8) + self.sync_all() + + # Call createauxblock while using the Namecoin API + nmc_api_auxblock = self.nodes[1].createauxblock(dummy_p2pkh_addr) + + # must not contain a "target" field, but a "_target" field + assert "target" not in nmc_api_auxblock + assert "_target" in nmc_api_auxblock + + reversedTarget = auxpow.reverseHex(nmc_api_auxblock["_target"]) + apow = auxpow.computeAuxpowWithChainId(nmc_api_auxblock["hash"], reversedTarget, "98", True) + res = self.nodes[1].submitauxblock(nmc_api_auxblock["hash"], apow) + assert res + + self.sync_all() + + # check the mined block + self.check_mined_block(nmc_api_auxblock, apow, dummy_p2pkh_addr, Decimal("500000")) + def check_mined_block(self, auxblock, apow, addr, min_value, txid=None): # Call getblock and verify the auxpow field. data = self.nodes[1].getblock(auxblock["hash"]) diff --git a/qa/rpc-tests/getauxblock.py b/qa/rpc-tests/getauxblock.py index cb44383e8..92296602a 100755 --- a/qa/rpc-tests/getauxblock.py +++ b/qa/rpc-tests/getauxblock.py @@ -12,9 +12,22 @@ from test_framework import scrypt_auxpow as auxpow class GetAuxBlockTest (BitcoinTestFramework): + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 2 + self.is_network_split = False + + def setup_network(self): + self.nodes = [] + self.nodes.append(start_node(0, self.options.tmpdir, ["-debug"])) + self.nodes.append(start_node(1, self.options.tmpdir, ["-debug", "-rpcnamecoinapi"])) + connect_nodes_bi(self.nodes, 0, 1) + self.sync_all() + def run_test (self): # Generate a block so that we are not "downloading blocks". - self.nodes[0].generate (1) + self.nodes[0].generate(100) # Compare basic data of getauxblock to getblocktemplate. auxblock = self.nodes[0].getauxblock () @@ -117,5 +130,19 @@ class GetAuxBlockTest (BitcoinTestFramework): coinbase = tx['vin'][0]['coinbase'] assert_equal ("01%02x01" % auxblock['height'], coinbase[0 : 6]) # DOGE: We mine less blocks in these tests + # Call getauxblock while using the Namecoin API + nmc_api_auxblock = self.nodes[1].getauxblock() + + # must not contain a "target" field, but a "_target" field + assert "target" not in nmc_api_auxblock + assert "_target" in nmc_api_auxblock + + reversedTarget = auxpow.reverseHex(nmc_api_auxblock["_target"]) + apow = auxpow.computeAuxpowWithChainId(nmc_api_auxblock["hash"], reversedTarget, "98", True) + res = self.nodes[1].getauxblock(nmc_api_auxblock["hash"], apow) + assert res + + self.sync_all() + if __name__ == '__main__': GetAuxBlockTest ().main () diff --git a/src/init.cpp b/src/init.cpp index ebfe30960..192cc6a2c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -503,6 +503,7 @@ std::string HelpMessage(HelpMessageMode mode) if (showDebug) { strUsage += HelpMessageOpt("-rpcworkqueue=", strprintf("Set the depth of the work queue to service RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE)); strUsage += HelpMessageOpt("-rpcservertimeout=", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_SERVER_TIMEOUT)); + strUsage += HelpMessageOpt("-rpcnamecoinapi", strprintf(_("Use Namecoin-compatible AuxPow API structure, (default: %u)"), DEFAULT_USE_NAMECOIN_API)); } return strUsage; @@ -1062,6 +1063,9 @@ bool AppInitParameterInteraction() return false; #endif + // Configure usage of the namecoin AuxPow API structure + fUseNamecoinApi = GetBoolArg("-rpcnamecoinapi", DEFAULT_USE_NAMECOIN_API); + fIsBareMultisigStd = GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); fAcceptDatacarrier = GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); nMaxDatacarrierBytes = GetArg("-datacarriersize", nMaxDatacarrierBytes); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 084f982d4..c0afea1e6 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -974,6 +974,8 @@ UniValue estimatesmartpriority(const JSONRPCRequest& request) /* ************************************************************************** */ /* Merge mining. */ +bool fUseNamecoinApi; + /** * The variables below are used to keep track of created and not yet * submitted auxpow blocks. Lock them to be sure even for multiple @@ -1090,7 +1092,7 @@ static UniValue AuxMiningCreateBlock(const CScript& scriptPubKey) result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue); result.pushKV("bits", strprintf("%08x", pblock->nBits)); result.pushKV("height", static_cast (pindexPrev->nHeight + 1)); - result.pushKV("target", HexStr(BEGIN(target), END(target))); + result.pushKV(fUseNamecoinApi ? "_target" : "target", HexStr(BEGIN(target), END(target))); return result; } @@ -1147,8 +1149,12 @@ UniValue getauxblockbip22(const JSONRPCRequest& request) " \"coinbasevalue\" (numeric) value of the block's coinbase\n" " \"bits\" (string) compressed target of the block\n" " \"height\" (numeric) height of the block\n" - " \"target\" (string) target in reversed byte order\n" - "}\n" + + (std::string) ( + fUseNamecoinApi + ? " \"_target\" (string) target in reversed byte order\n" + : " \"target\" (string) target in reversed byte order\n" + ) + + "}\n" "\nResult (with arguments):\n" "xxxxx (boolean) whether the submitted block was correct\n" "\nExamples:\n" @@ -1231,7 +1237,7 @@ UniValue getauxblockbip22(const JSONRPCRequest& request) result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue); result.pushKV("bits", strprintf("%08x", pblock->nBits)); result.pushKV("height", static_cast (pindexPrev->nHeight + 1)); - result.pushKV("target", HexStr(BEGIN(target), END(target))); + result.pushKV(fUseNamecoinApi ? "_target" : "target", HexStr(BEGIN(target), END(target))); return result; } @@ -1285,8 +1291,12 @@ UniValue createauxblock(const JSONRPCRequest& request) " \"coinbasevalue\" (numeric) value of the block's coinbase\n" " \"bits\" (string) compressed target of the block\n" " \"height\" (numeric) height of the block\n" - " \"target\" (string) target in reversed byte order\n" - "}\n" + + (std::string) ( + fUseNamecoinApi + ? " \"_target\" (string) target in reversed byte order\n" + : " \"target\" (string) target in reversed byte order\n" + ) + + "}\n" "\nExamples:\n" + HelpExampleCli("createauxblock", "\"address\"") + HelpExampleRpc("createauxblock", "\"address\"") diff --git a/src/rpc/server.h b/src/rpc/server.h index 2ea9326ac..1da1a3e2c 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -21,6 +21,7 @@ #include static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION = 1; +static const bool DEFAULT_USE_NAMECOIN_API = false; class CRPCCommand; @@ -211,4 +212,6 @@ void RPCNotifyBlockChange(bool ibd, const CBlockIndex *); // Retrieves any serialization flags requested in command line argument int RPCSerializationFlags(); +extern bool fUseNamecoinApi; + #endif // BITCOIN_RPCSERVER_H