support coinbasetxn capability in getblocktemplate
This commit is contained in:
parent
36ccf3e903
commit
24269e177f
1 changed files with 40 additions and 6 deletions
|
@ -25,6 +25,11 @@
|
||||||
#include <utilstrencodings.h>
|
#include <utilstrencodings.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
#include <warnings.h>
|
#include <warnings.h>
|
||||||
|
#ifdef ENABLE_WALLET
|
||||||
|
#include <wallet/rpcwallet.h>
|
||||||
|
#include <wallet/wallet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -372,6 +377,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||||
UniValue lpval = NullUniValue;
|
UniValue lpval = NullUniValue;
|
||||||
std::set<std::string> setClientRules;
|
std::set<std::string> setClientRules;
|
||||||
int64_t nMaxVersionPreVB = -1;
|
int64_t nMaxVersionPreVB = -1;
|
||||||
|
UniValue aMutable(UniValue::VARR);
|
||||||
|
bool wantsCoinbaseTxn = false;
|
||||||
if (!request.params[0].isNull())
|
if (!request.params[0].isNull())
|
||||||
{
|
{
|
||||||
const UniValue& oparam = request.params[0].get_obj();
|
const UniValue& oparam = request.params[0].get_obj();
|
||||||
|
@ -386,6 +393,17 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
|
||||||
lpval = find_value(oparam, "longpollid");
|
lpval = find_value(oparam, "longpollid");
|
||||||
|
|
||||||
|
const UniValue& capval = find_value(oparam, "capabilities");
|
||||||
|
if (capval.isArray()) {
|
||||||
|
for (std::size_t i = 0; i < capval.size(); ++i)
|
||||||
|
if (capval[i].get_str() == "coinbase/append") // should be coinbase/* ? we dont' care what they do to the coinbase
|
||||||
|
aMutable.push_back(capval[i]);
|
||||||
|
#ifdef ENABLE_WALLET
|
||||||
|
else if (capval[i].get_str() == "coinbasetxn")
|
||||||
|
wantsCoinbaseTxn = true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (strMode == "proposal")
|
if (strMode == "proposal")
|
||||||
{
|
{
|
||||||
const UniValue& dataval = find_value(oparam, "data");
|
const UniValue& dataval = find_value(oparam, "data");
|
||||||
|
@ -519,8 +537,20 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||||
fLastTemplateSupportsSegwit = fSupportsSegwit;
|
fLastTemplateSupportsSegwit = fSupportsSegwit;
|
||||||
|
|
||||||
// Create new block
|
// Create new block
|
||||||
CScript scriptDummy = CScript() << OP_TRUE;
|
CScript newBlockScript = CScript() << OP_TRUE;
|
||||||
pblocktemplate = BlockAssembler(Params()).CreateNewBlock(scriptDummy, fSupportsSegwit);
|
#ifdef ENABLE_WALLET
|
||||||
|
if (wantsCoinbaseTxn) {
|
||||||
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
|
if (!wallet)
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMS, "No wallet to comply with coinbasetxn request.");
|
||||||
|
std::shared_ptr<CReserveScript> coinbase_script;
|
||||||
|
wallet->GetScriptForMining(coinbase_script); // tops up and locks inside
|
||||||
|
if (!coinbase_script)
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMS, "Unable to acquire address for coinbasetxn request.");
|
||||||
|
newBlockScript = coinbase_script->reserveScript;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
pblocktemplate = BlockAssembler(Params()).CreateNewBlock(newBlockScript, fSupportsSegwit);
|
||||||
if (!pblocktemplate)
|
if (!pblocktemplate)
|
||||||
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
|
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
|
||||||
|
|
||||||
|
@ -539,6 +569,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||||
const bool fPreSegWit = (ThresholdState::ACTIVE != VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache));
|
const bool fPreSegWit = (ThresholdState::ACTIVE != VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache));
|
||||||
|
|
||||||
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
|
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
|
||||||
|
UniValue result(UniValue::VOBJ);
|
||||||
|
|
||||||
UniValue transactions(UniValue::VARR);
|
UniValue transactions(UniValue::VARR);
|
||||||
std::map<uint256, int64_t> setTxIndex;
|
std::map<uint256, int64_t> setTxIndex;
|
||||||
|
@ -548,7 +579,8 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||||
uint256 txHash = tx.GetHash();
|
uint256 txHash = tx.GetHash();
|
||||||
setTxIndex[txHash] = i++;
|
setTxIndex[txHash] = i++;
|
||||||
|
|
||||||
if (tx.IsCoinBase())
|
auto isCoinbase = tx.IsCoinBase();
|
||||||
|
if (isCoinbase && !wantsCoinbaseTxn)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
UniValue entry(UniValue::VOBJ);
|
UniValue entry(UniValue::VOBJ);
|
||||||
|
@ -575,6 +607,9 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||||
entry.pushKV("sigops", nTxSigOps);
|
entry.pushKV("sigops", nTxSigOps);
|
||||||
entry.pushKV("weight", GetTransactionWeight(tx));
|
entry.pushKV("weight", GetTransactionWeight(tx));
|
||||||
|
|
||||||
|
if (isCoinbase)
|
||||||
|
result.pushKV("coinbasetxn", entry);
|
||||||
|
else
|
||||||
transactions.push_back(entry);
|
transactions.push_back(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,12 +618,11 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||||
|
|
||||||
arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
|
arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
|
||||||
|
|
||||||
UniValue aMutable(UniValue::VARR);
|
|
||||||
aMutable.push_back("time");
|
aMutable.push_back("time");
|
||||||
aMutable.push_back("transactions");
|
aMutable.push_back("transactions");
|
||||||
aMutable.push_back("prevblock");
|
aMutable.push_back("prevblock");
|
||||||
|
aMutable.push_back("submit/coinbase");
|
||||||
|
|
||||||
UniValue result(UniValue::VOBJ);
|
|
||||||
result.pushKV("capabilities", aCaps);
|
result.pushKV("capabilities", aCaps);
|
||||||
|
|
||||||
UniValue aRules(UniValue::VARR);
|
UniValue aRules(UniValue::VARR);
|
||||||
|
|
Loading…
Reference in a new issue