比特币 RPC 命令「estimatefee」
$ bitcoin-cli help estimatefee estimatefee nblocks 估算对于在第 nblocks 个区块开始确认的一笔交易的每千字节的大致费用。 参数: 1. nblocks(数字) 结果: n(数字)估算的每千字节的费用 如果没有观察足够的交易和区块来做估算则返回一个负值。 例子: > bitcoin-cli estimatefee 6
源码剖析
estimatefee
对应的函数在文件 rpcserver.h
中被引用。
extern UniValue estimatefee(const UniValue& params, bool fHelp);
实现在文件 rpcmining.cpp
中。
UniValue estimatefee(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"estimatefee nblocks\n"
"\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
"confirmation within nblocks blocks.\n"
"\nArguments:\n"
"1. nblocks (numeric)\n"
"\nResult:\n"
"n (numeric) estimated fee-per-kilobyte\n"
"\n"
"A negative value is returned if not enough transactions and blocks\n"
"have been observed to make an estimate.\n"
"\nExample:\n"
+ HelpExampleCli("estimatefee", "6")
); // 1. 帮助内容
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM)); // 2. RPC 类型检测
int nBlocks = params[0].get_int();
if (nBlocks < 1)
nBlocks = 1;
CFeeRate feeRate = mempool.estimateFee(nBlocks); // 3. 估算指定位置区块的交易费并返回
if (feeRate == CFeeRate(0))
return -1.0;
return ValueFromAmount(feeRate.GetFeePerK());
}
1. 帮助内容
参考比特币 RPC 命令「getbestblockhash」1. 帮助内容。