From 6ad8d1c82c4f4e269c3416600f449db47e17365e Mon Sep 17 00:00:00 2001 From: Jeremiah Buddenhagen Date: Thu, 4 Jan 2018 05:01:07 -0600 Subject: [PATCH] Add tx-comment to instant block generation --- src/miner.cpp | 3 ++- src/miner.h | 2 +- src/rpc/mining.cpp | 16 ++++++++++++---- src/rpc/mining.h | 2 +- src/rpc/rawtransaction.cpp | 2 ++ src/wallet/rpcwallet.cpp | 10 ++++++++-- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 01366fea4..8fc387721 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -127,7 +127,7 @@ void BlockAssembler::resetBlock() nFees = 0; } -std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx) +std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx, std::string coinbaseTxComment) { int64_t nTimeStart = GetTimeMicros(); @@ -187,6 +187,7 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()); coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; + coinbaseTx.strTxComment = coinbaseTxComment; pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx)); pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus()); pblocktemplate->vTxFees[0] = -nFees; diff --git a/src/miner.h b/src/miner.h index 5c9cfd78f..d36e50d7f 100644 --- a/src/miner.h +++ b/src/miner.h @@ -168,7 +168,7 @@ public: BlockAssembler(const CChainParams& params, const Options& options); /** Construct a new block template with coinbase to scriptPubKeyIn */ - std::unique_ptr CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx=true); + std::unique_ptr CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx=true, std::string coinbaseTxComment=""); private: // utility functions diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 55bb7e495..0a648e0c5 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -105,7 +105,7 @@ UniValue getnetworkhashps(const JSONRPCRequest& request) return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1); } -UniValue generateBlocks(std::shared_ptr coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript) +UniValue generateBlocks(std::shared_ptr coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript, std::string strTxComment) { static const int nInnerLoopCount = 0x10000; int nHeightEnd = 0; @@ -120,7 +120,7 @@ UniValue generateBlocks(std::shared_ptr coinbaseScript, int nGen UniValue blockHashes(UniValue::VARR); while (nHeight < nHeightEnd) { - std::unique_ptr pblocktemplate(BlockAssembler(Params()).CreateNewBlock(coinbaseScript->reserveScript)); + std::unique_ptr pblocktemplate(BlockAssembler(Params()).CreateNewBlock(coinbaseScript->reserveScript, true, strTxComment)); if (!pblocktemplate.get()) throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); CBlock *pblock = &pblocktemplate->block; @@ -155,7 +155,7 @@ UniValue generateBlocks(std::shared_ptr coinbaseScript, int nGen UniValue generatetoaddress(const JSONRPCRequest& request) { - if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) + if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) throw std::runtime_error( "generatetoaddress nblocks address (maxtries)\n" "\nMine blocks immediately to a specified address (before the RPC call returns)\n" @@ -163,6 +163,7 @@ UniValue generatetoaddress(const JSONRPCRequest& request) "1. nblocks (numeric, required) How many blocks are generated immediately.\n" "2. address (string, required) The address to send the newly generated litecoin to.\n" "3. maxtries (numeric, optional) How many iterations to try (default = 1000000).\n" + "4. tx-comment (string, optional) Coinbase transaction tx-comment (default = \"\").\n" "\nResult:\n" "[ blockhashes ] (array) hashes of blocks generated\n" "\nExamples:\n" @@ -176,6 +177,11 @@ UniValue generatetoaddress(const JSONRPCRequest& request) nMaxTries = request.params[2].get_int(); } + std::string coinbaseTxComment = ""; + if (!request.params[3].isNull()) { + coinbaseTxComment = request.params[3].get_str(); + } + CBitcoinAddress address(request.params[1].get_str()); if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address"); @@ -183,7 +189,9 @@ UniValue generatetoaddress(const JSONRPCRequest& request) std::shared_ptr coinbaseScript = std::make_shared(); coinbaseScript->reserveScript = GetScriptForDestination(address.Get()); - return generateBlocks(coinbaseScript, nGenerate, nMaxTries, false); + + + return generateBlocks(coinbaseScript, nGenerate, nMaxTries, false, coinbaseTxComment); } UniValue getmininginfo(const JSONRPCRequest& request) diff --git a/src/rpc/mining.h b/src/rpc/mining.h index 868d7002b..a46a43a45 100644 --- a/src/rpc/mining.h +++ b/src/rpc/mining.h @@ -10,7 +10,7 @@ #include /** Generate blocks (mine) */ -UniValue generateBlocks(std::shared_ptr coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript); +UniValue generateBlocks(std::shared_ptr coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript, std::string strTxComment); /** Check bounds on a command line confirm target */ unsigned int ParseConfirmTarget(const UniValue& value); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index ac770cadf..e1ca777c7 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -287,6 +287,7 @@ UniValue verifytxoutproof(const JSONRPCRequest& request) return res; } +// ToDo: FLO 0.15 UniValue createrawtransaction(const JSONRPCRequest& request) { if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) @@ -551,6 +552,7 @@ static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std:: vErrorsRet.push_back(entry); } +// ToDo: FLO 0.15 UniValue combinerawtransaction(const JSONRPCRequest& request) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fe60a3141..5f007c95d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3095,13 +3095,14 @@ UniValue generate(const JSONRPCRequest& request) return NullUniValue; } - if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { + if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) { throw std::runtime_error( "generate nblocks ( maxtries )\n" "\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n" "\nArguments:\n" "1. nblocks (numeric, required) How many blocks are generated immediately.\n" "2. maxtries (numeric, optional) How many iterations to try (default = 1000000).\n" + "3. tx-comment (string, optional) Coinbase transaction tx-comment (default = \"\").\n" "\nResult:\n" "[ blockhashes ] (array) hashes of blocks generated\n" "\nExamples:\n" @@ -3116,6 +3117,11 @@ UniValue generate(const JSONRPCRequest& request) max_tries = request.params[1].get_int(); } + std::string coinbaseTxComment = ""; + if (!request.params[2].isNull()) { + coinbaseTxComment = request.params[2].get_str(); + } + std::shared_ptr coinbase_script; pwallet->GetScriptForMining(coinbase_script); @@ -3129,7 +3135,7 @@ UniValue generate(const JSONRPCRequest& request) throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available"); } - return generateBlocks(coinbase_script, num_generate, max_tries, true); + return generateBlocks(coinbase_script, num_generate, max_tries, true, coinbaseTxComment); } extern UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp