Add tx-comment to instant block generation
This commit is contained in:
parent
a2597a4325
commit
6ad8d1c82c
@ -127,7 +127,7 @@ void BlockAssembler::resetBlock()
|
|||||||
nFees = 0;
|
nFees = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx)
|
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx, std::string coinbaseTxComment)
|
||||||
{
|
{
|
||||||
int64_t nTimeStart = GetTimeMicros();
|
int64_t nTimeStart = GetTimeMicros();
|
||||||
|
|
||||||
@ -187,6 +187,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
|||||||
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
|
coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn;
|
||||||
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
|
coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus());
|
||||||
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||||
|
coinbaseTx.strTxComment = coinbaseTxComment;
|
||||||
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
|
pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx));
|
||||||
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
|
pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, chainparams.GetConsensus());
|
||||||
pblocktemplate->vTxFees[0] = -nFees;
|
pblocktemplate->vTxFees[0] = -nFees;
|
||||||
|
|||||||
@ -168,7 +168,7 @@ public:
|
|||||||
BlockAssembler(const CChainParams& params, const Options& options);
|
BlockAssembler(const CChainParams& params, const Options& options);
|
||||||
|
|
||||||
/** Construct a new block template with coinbase to scriptPubKeyIn */
|
/** Construct a new block template with coinbase to scriptPubKeyIn */
|
||||||
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx=true);
|
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx=true, std::string coinbaseTxComment="");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// utility functions
|
// utility functions
|
||||||
|
|||||||
@ -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);
|
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<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
|
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript, std::string strTxComment)
|
||||||
{
|
{
|
||||||
static const int nInnerLoopCount = 0x10000;
|
static const int nInnerLoopCount = 0x10000;
|
||||||
int nHeightEnd = 0;
|
int nHeightEnd = 0;
|
||||||
@ -120,7 +120,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
|
|||||||
UniValue blockHashes(UniValue::VARR);
|
UniValue blockHashes(UniValue::VARR);
|
||||||
while (nHeight < nHeightEnd)
|
while (nHeight < nHeightEnd)
|
||||||
{
|
{
|
||||||
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(Params()).CreateNewBlock(coinbaseScript->reserveScript));
|
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(Params()).CreateNewBlock(coinbaseScript->reserveScript, true, strTxComment));
|
||||||
if (!pblocktemplate.get())
|
if (!pblocktemplate.get())
|
||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
|
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
|
||||||
CBlock *pblock = &pblocktemplate->block;
|
CBlock *pblock = &pblocktemplate->block;
|
||||||
@ -155,7 +155,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
|
|||||||
|
|
||||||
UniValue generatetoaddress(const JSONRPCRequest& request)
|
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(
|
throw std::runtime_error(
|
||||||
"generatetoaddress nblocks address (maxtries)\n"
|
"generatetoaddress nblocks address (maxtries)\n"
|
||||||
"\nMine blocks immediately to a specified address (before the RPC call returns)\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"
|
"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"
|
"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"
|
"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"
|
"\nResult:\n"
|
||||||
"[ blockhashes ] (array) hashes of blocks generated\n"
|
"[ blockhashes ] (array) hashes of blocks generated\n"
|
||||||
"\nExamples:\n"
|
"\nExamples:\n"
|
||||||
@ -176,6 +177,11 @@ UniValue generatetoaddress(const JSONRPCRequest& request)
|
|||||||
nMaxTries = request.params[2].get_int();
|
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());
|
CBitcoinAddress address(request.params[1].get_str());
|
||||||
if (!address.IsValid())
|
if (!address.IsValid())
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address");
|
||||||
@ -183,7 +189,9 @@ UniValue generatetoaddress(const JSONRPCRequest& request)
|
|||||||
std::shared_ptr<CReserveScript> coinbaseScript = std::make_shared<CReserveScript>();
|
std::shared_ptr<CReserveScript> coinbaseScript = std::make_shared<CReserveScript>();
|
||||||
coinbaseScript->reserveScript = GetScriptForDestination(address.Get());
|
coinbaseScript->reserveScript = GetScriptForDestination(address.Get());
|
||||||
|
|
||||||
return generateBlocks(coinbaseScript, nGenerate, nMaxTries, false);
|
|
||||||
|
|
||||||
|
return generateBlocks(coinbaseScript, nGenerate, nMaxTries, false, coinbaseTxComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue getmininginfo(const JSONRPCRequest& request)
|
UniValue getmininginfo(const JSONRPCRequest& request)
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
|
||||||
/** Generate blocks (mine) */
|
/** Generate blocks (mine) */
|
||||||
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript);
|
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript, std::string strTxComment);
|
||||||
|
|
||||||
/** Check bounds on a command line confirm target */
|
/** Check bounds on a command line confirm target */
|
||||||
unsigned int ParseConfirmTarget(const UniValue& value);
|
unsigned int ParseConfirmTarget(const UniValue& value);
|
||||||
|
|||||||
@ -287,6 +287,7 @@ UniValue verifytxoutproof(const JSONRPCRequest& request)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToDo: FLO 0.15
|
||||||
UniValue createrawtransaction(const JSONRPCRequest& request)
|
UniValue createrawtransaction(const JSONRPCRequest& request)
|
||||||
{
|
{
|
||||||
if (request.fHelp || request.params.size() < 2 || request.params.size() > 4)
|
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);
|
vErrorsRet.push_back(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToDo: FLO 0.15
|
||||||
UniValue combinerawtransaction(const JSONRPCRequest& request)
|
UniValue combinerawtransaction(const JSONRPCRequest& request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -3095,13 +3095,14 @@ UniValue generate(const JSONRPCRequest& request)
|
|||||||
return NullUniValue;
|
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(
|
throw std::runtime_error(
|
||||||
"generate nblocks ( maxtries )\n"
|
"generate nblocks ( maxtries )\n"
|
||||||
"\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n"
|
"\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n"
|
||||||
"\nArguments:\n"
|
"\nArguments:\n"
|
||||||
"1. nblocks (numeric, required) How many blocks are generated immediately.\n"
|
"1. nblocks (numeric, required) How many blocks are generated immediately.\n"
|
||||||
"2. maxtries (numeric, optional) How many iterations to try (default = 1000000).\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"
|
"\nResult:\n"
|
||||||
"[ blockhashes ] (array) hashes of blocks generated\n"
|
"[ blockhashes ] (array) hashes of blocks generated\n"
|
||||||
"\nExamples:\n"
|
"\nExamples:\n"
|
||||||
@ -3116,6 +3117,11 @@ UniValue generate(const JSONRPCRequest& request)
|
|||||||
max_tries = request.params[1].get_int();
|
max_tries = request.params[1].get_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string coinbaseTxComment = "";
|
||||||
|
if (!request.params[2].isNull()) {
|
||||||
|
coinbaseTxComment = request.params[2].get_str();
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<CReserveScript> coinbase_script;
|
std::shared_ptr<CReserveScript> coinbase_script;
|
||||||
pwallet->GetScriptForMining(coinbase_script);
|
pwallet->GetScriptForMining(coinbase_script);
|
||||||
|
|
||||||
@ -3129,7 +3135,7 @@ UniValue generate(const JSONRPCRequest& request)
|
|||||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available");
|
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
|
extern UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user