Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// NOTE: Unlike wallet RPC (which use BCC values), mining RPCs follow GBT (BIP | // NOTE: Unlike wallet RPC (which use BCC values), mining RPCs follow GBT (BIP | ||||
// 22) in using satoshi amounts | // 22) in using satoshi amounts | ||||
static UniValue prioritisetransaction(const Config &config, | static UniValue prioritisetransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 3) { | if (request.fHelp || request.params.size() != 3) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"prioritisetransaction <txid> <priority delta> <fee delta>\n" | "prioritisetransaction <txhash> <priority delta> <fee delta>\n" | ||||
"Accepts the transaction into mined blocks at a higher (or lower) " | "Accepts the transaction into mined blocks at a higher (or lower) " | ||||
"priority\n" | "priority\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction id.\n" | "1. \"txhash\" (string, required) The transaction hash.\n" | ||||
"2. priority_delta (numeric, required) The priority to add or " | "2. priority_delta (numeric, required) The priority to add or " | ||||
"subtract.\n" | "subtract.\n" | ||||
" The transaction selection algorithm considers " | " The transaction selection algorithm considers " | ||||
"the tx as it would have a higher priority.\n" | "the tx as it would have a higher priority.\n" | ||||
" (priority of a transaction is calculated: " | " (priority of a transaction is calculated: " | ||||
"coinage * value_in_satoshis / txsize) \n" | "coinage * value_in_satoshis / txsize) \n" | ||||
"3. fee_delta (numeric, required) The fee value (in satoshis) " | "3. fee_delta (numeric, required) The fee value (in satoshis) " | ||||
"to add (or subtract, if negative).\n" | "to add (or subtract, if negative).\n" | ||||
" The fee is not actually paid, only the " | " The fee is not actually paid, only the " | ||||
"algorithm for selecting transactions into a block\n" | "algorithm for selecting transactions into a block\n" | ||||
" considers the transaction as it would have paid " | " considers the transaction as it would have paid " | ||||
"a higher (or lower) fee.\n" | "a higher (or lower) fee.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"true (boolean) Returns true\n" | "true (boolean) Returns true\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000") + | HelpExampleCli("prioritisetransaction", "\"txhash\" 0.0 10000") + | ||||
HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")); | HelpExampleRpc("prioritisetransaction", "\"txhash\", 0.0, 10000")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
uint256 hash = ParseHashStr(request.params[0].get_str(), "txid"); | txhash_t txhash(ParseHashStr(request.params[0].get_str(), "txhash")); | ||||
CAmount nAmount = request.params[2].get_int64(); | CAmount nAmount = request.params[2].get_int64(); | ||||
mempool.PrioritiseTransaction(hash, request.params[0].get_str(), | mempool.PrioritiseTransaction(txhash, request.params[0].get_str(), | ||||
request.params[1].get_real(), nAmount); | request.params[1].get_real(), nAmount); | ||||
return true; | return true; | ||||
} | } | ||||
// NOTE: Assumes a conclusive result; if result is inconclusive, it must be | // NOTE: Assumes a conclusive result; if result is inconclusive, it must be | ||||
// handled by caller | // handled by caller | ||||
static UniValue BIP22ValidationResult(const Config &config, | static UniValue BIP22ValidationResult(const Config &config, | ||||
const CValidationState &state) { | const CValidationState &state) { | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() > 1) { | ||||
" \"previousblockhash\" : \"xxxx\", (string) The hash of " | " \"previousblockhash\" : \"xxxx\", (string) The hash of " | ||||
"current highest block\n" | "current highest block\n" | ||||
" \"transactions\" : [ (array) contents of " | " \"transactions\" : [ (array) contents of " | ||||
"non-coinbase transactions that should be included in the next " | "non-coinbase transactions that should be included in the next " | ||||
"block\n" | "block\n" | ||||
" {\n" | " {\n" | ||||
" \"data\" : \"xxxx\", (string) transaction " | " \"data\" : \"xxxx\", (string) transaction " | ||||
"data encoded in hexadecimal (byte-for-byte)\n" | "data encoded in hexadecimal (byte-for-byte)\n" | ||||
" \"txid\" : \"xxxx\", (string) transaction id " | " \"unspentid\" : \"xxxx\", (string) " | ||||
"transaction id " | |||||
"encoded in little-endian hexadecimal\n" | "encoded in little-endian hexadecimal\n" | ||||
" \"hash\" : \"xxxx\", (string) hash encoded " | " \"hash\" : \"xxxx\", (string) hash encoded " | ||||
"in little-endian hexadecimal (including witness data)\n" | "in little-endian hexadecimal (including witness data)\n" | ||||
" \"depends\" : [ (array) array of numbers " | " \"depends\" : [ (array) array of numbers " | ||||
"\n" | "\n" | ||||
" n (numeric) transactions " | " n (numeric) transactions " | ||||
"before this one (by 1-based index in 'transactions' list) that " | "before this one (by 1-based index in 'transactions' list) that " | ||||
"must be present in the final block if this one is\n" | "must be present in the final block if this one is\n" | ||||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | static UniValue getblocktemplate(const Config &config, | ||||
// Update nTime | // Update nTime | ||||
UpdateTime(pblock, consensusParams, pindexPrev); | UpdateTime(pblock, consensusParams, pindexPrev); | ||||
pblock->nNonce = 0; | pblock->nNonce = 0; | ||||
UniValue aCaps(UniValue::VARR); | UniValue aCaps(UniValue::VARR); | ||||
aCaps.push_back("proposal"); | aCaps.push_back("proposal"); | ||||
UniValue transactions(UniValue::VARR); | UniValue transactions(UniValue::VARR); | ||||
std::map<uint256, int64_t> setTxIndex; | std::map<unspentid_t, int64_t> setTxIndex; | ||||
int i = 0; | int i = 0; | ||||
for (const auto &it : pblock->vtx) { | for (const auto &it : pblock->vtx) { | ||||
const CTransaction &tx = *it; | const CTransaction &tx = *it; | ||||
uint256 txId = tx.GetId(); | unspentid_t unspentid = tx.Getunspentid(); | ||||
setTxIndex[txId] = i++; | setTxIndex[unspentid] = i++; | ||||
if (tx.IsCoinBase()) { | if (tx.IsCoinBase()) { | ||||
continue; | continue; | ||||
} | } | ||||
UniValue entry(UniValue::VOBJ); | UniValue entry(UniValue::VOBJ); | ||||
entry.push_back(Pair("data", EncodeHexTx(tx))); | entry.push_back(Pair("data", EncodeHexTx(tx))); | ||||
entry.push_back(Pair("txid", txId.GetHex())); | entry.push_back(Pair("unspentid", unspentid.GetHex())); | ||||
entry.push_back(Pair("hash", tx.GetHash().GetHex())); | entry.push_back(Pair("hash", tx.GetHash().GetHex())); | ||||
UniValue deps(UniValue::VARR); | UniValue deps(UniValue::VARR); | ||||
for (const CTxIn &in : tx.vin) { | for (const CTxIn &in : tx.vin) { | ||||
if (setTxIndex.count(in.prevout.hash)) | if (setTxIndex.count(in.prevout.unspentid)) | ||||
deps.push_back(setTxIndex[in.prevout.hash]); | deps.push_back(setTxIndex[in.prevout.unspentid]); | ||||
} | } | ||||
entry.push_back(Pair("depends", deps)); | entry.push_back(Pair("depends", deps)); | ||||
int index_in_template = i - 1; | int index_in_template = i - 1; | ||||
entry.push_back(Pair( | entry.push_back(Pair( | ||||
"fee", pblocktemplate->vTxFees[index_in_template].GetSatoshis())); | "fee", pblocktemplate->vTxFees[index_in_template].GetSatoshis())); | ||||
int64_t nTxSigOps = pblocktemplate->vTxSigOpsCount[index_in_template]; | int64_t nTxSigOps = pblocktemplate->vTxSigOpsCount[index_in_template]; | ||||
entry.push_back(Pair("sigops", nTxSigOps)); | entry.push_back(Pair("sigops", nTxSigOps)); | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand commands[] = { | ||||
// category name actor (function) okSafeMode | // category name actor (function) okSafeMode | ||||
// ---------- ------------------------ ---------------------- ---------- | // ---------- ------------------------ ---------------------- ---------- | ||||
{"mining", "getnetworkhashps", getnetworkhashps, true, {"nblocks", "height"}}, | {"mining", "getnetworkhashps", getnetworkhashps, true, {"nblocks", "height"}}, | ||||
{"mining", "getmininginfo", getmininginfo, true, {}}, | {"mining", "getmininginfo", getmininginfo, true, {}}, | ||||
{"mining", "prioritisetransaction", prioritisetransaction, true, {"txid", "priority_delta", "fee_delta"}}, | {"mining", "prioritisetransaction", prioritisetransaction, true, {"txhash", "priority_delta", "fee_delta"}}, | ||||
{"mining", "getblocktemplate", getblocktemplate, true, {"template_request"}}, | {"mining", "getblocktemplate", getblocktemplate, true, {"template_request"}}, | ||||
{"mining", "submitblock", submitblock, true, {"hexdata", "parameters"}}, | {"mining", "submitblock", submitblock, true, {"hexdata", "parameters"}}, | ||||
{"generating", "generate", generate, true, {"nblocks", "maxtries"}}, | {"generating", "generate", generate, true, {"nblocks", "maxtries"}}, | ||||
{"generating", "generatetoaddress", generatetoaddress, true, {"nblocks", "address", "maxtries"}}, | {"generating", "generatetoaddress", generatetoaddress, true, {"nblocks", "address", "maxtries"}}, | ||||
{"util", "estimatefee", estimatefee, true, {"nblocks"}}, | {"util", "estimatefee", estimatefee, true, {"nblocks"}}, | ||||
{"util", "estimatepriority", estimatepriority, true, {"nblocks"}}, | {"util", "estimatepriority", estimatepriority, true, {"nblocks"}}, | ||||
Show All 9 Lines |