Skip to content

Commit 75ec320

Browse files
committed
Merge #8153: [rpc] fundrawtransaction feeRate: Use BTC/kB
fa7f4f5 [rpc] fundrawtransaction feeRate: Use BTC/kB (MarcoFalke) faf82e8 [rpc] fundrawtransaction: Fix help text and interface (MarcoFalke)
2 parents a7c41f2 + fa7f4f5 commit 75ec320

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

qa/rpc-tests/fundrawtransaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,9 @@ def run_test(self):
681681
inputs = []
682682
outputs = {self.nodes[2].getnewaddress() : 1}
683683
rawtx = self.nodes[3].createrawtransaction(inputs, outputs)
684-
result = self.nodes[3].fundrawtransaction(rawtx, )
685-
result2 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 2000})
686-
result3 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 10000})
684+
result = self.nodes[3].fundrawtransaction(rawtx) # uses min_relay_tx_fee (set by settxfee)
685+
result2 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 2*min_relay_tx_fee})
686+
result3 = self.nodes[3].fundrawtransaction(rawtx, {"feeRate": 10*min_relay_tx_fee})
687687
assert_equal(result['fee']*2, result2['fee'])
688688
assert_equal(result['fee']*10, result3['fee'])
689689

src/rpc/rawtransaction.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,12 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
682682

683683
UniValue prevOut = p.get_obj();
684684

685-
RPCTypeCheckObj(prevOut, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM)("scriptPubKey", UniValue::VSTR));
685+
RPCTypeCheckObj(prevOut,
686+
{
687+
{"txid", UniValueType(UniValue::VSTR)},
688+
{"vout", UniValueType(UniValue::VNUM)},
689+
{"scriptPubKey", UniValueType(UniValue::VSTR)},
690+
});
686691

687692
uint256 txid = ParseHashO(prevOut, "txid");
688693

@@ -710,7 +715,13 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
710715
// if redeemScript given and not using the local wallet (private keys
711716
// given), add redeemScript to the tempKeystore so it can be signed:
712717
if (fGivenKeys && scriptPubKey.IsPayToScriptHash()) {
713-
RPCTypeCheckObj(prevOut, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM)("scriptPubKey", UniValue::VSTR)("redeemScript",UniValue::VSTR));
718+
RPCTypeCheckObj(prevOut,
719+
{
720+
{"txid", UniValueType(UniValue::VSTR)},
721+
{"vout", UniValueType(UniValue::VNUM)},
722+
{"scriptPubKey", UniValueType(UniValue::VSTR)},
723+
{"redeemScript", UniValueType(UniValue::VSTR)},
724+
});
714725
UniValue v = find_value(prevOut, "redeemScript");
715726
if (!v.isNull()) {
716727
vector<unsigned char> rsData(ParseHexV(v, "redeemScript"));

src/rpc/server.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,18 @@ void RPCTypeCheck(const UniValue& params,
8888
}
8989

9090
void RPCTypeCheckObj(const UniValue& o,
91-
const map<string, UniValue::VType>& typesExpected,
92-
bool fAllowNull,
93-
bool fStrict)
91+
const map<string, UniValueType>& typesExpected,
92+
bool fAllowNull,
93+
bool fStrict)
9494
{
95-
BOOST_FOREACH(const PAIRTYPE(string, UniValue::VType)& t, typesExpected)
96-
{
95+
for (const auto& t : typesExpected) {
9796
const UniValue& v = find_value(o, t.first);
9897
if (!fAllowNull && v.isNull())
9998
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first));
10099

101-
if (!((v.type() == t.second) || (fAllowNull && (v.isNull()))))
102-
{
100+
if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull()))) {
103101
string err = strprintf("Expected type %s for %s, got %s",
104-
uvTypeName(t.second), t.first, uvTypeName(v.type()));
102+
uvTypeName(t.second.type), t.first, uvTypeName(v.type()));
105103
throw JSONRPCError(RPC_TYPE_ERROR, err);
106104
}
107105
}

src/rpc/server.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ namespace RPCServer
3232
class CBlockIndex;
3333
class CNetAddr;
3434

35+
/** Wrapper for UniValue::VType, which includes typeAny:
36+
* Used to denote don't care type. Only used by RPCTypeCheckObj */
37+
struct UniValueType {
38+
UniValueType(UniValue::VType _type) : typeAny(false), type(_type) {}
39+
UniValueType() : typeAny(true) {}
40+
bool typeAny;
41+
UniValue::VType type;
42+
};
43+
3544
class JSONRequest
3645
{
3746
public:
@@ -60,17 +69,17 @@ bool RPCIsInWarmup(std::string *statusOut);
6069
/**
6170
* Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
6271
* the right number of arguments are passed, just that any passed are the correct type.
63-
* Use like: RPCTypeCheck(params, boost::assign::list_of(str_type)(int_type)(obj_type));
6472
*/
6573
void RPCTypeCheck(const UniValue& params,
6674
const std::list<UniValue::VType>& typesExpected, bool fAllowNull=false);
6775

6876
/*
6977
Check for expected keys/value types in an Object.
70-
Use like: RPCTypeCheckObj(object, boost::assign::map_list_of("name", str_type)("value", int_type));
7178
*/
7279
void RPCTypeCheckObj(const UniValue& o,
73-
const std::map<std::string, UniValue::VType>& typesExpected, bool fAllowNull=false, bool fStrict=false);
80+
const std::map<std::string, UniValueType>& typesExpected,
81+
bool fAllowNull = false,
82+
bool fStrict = false);
7483

7584
/** Opaque base class for timers returned by NewTimerFunc.
7685
* This provides no methods at the moment, but makes sure that delete

src/wallet/rpcwallet.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,11 @@ UniValue lockunspent(const UniValue& params, bool fHelp)
20692069
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected object");
20702070
const UniValue& o = output.get_obj();
20712071

2072-
RPCTypeCheckObj(o, boost::assign::map_list_of("txid", UniValue::VSTR)("vout", UniValue::VNUM));
2072+
RPCTypeCheckObj(o,
2073+
{
2074+
{"txid", UniValueType(UniValue::VSTR)},
2075+
{"vout", UniValueType(UniValue::VNUM)},
2076+
});
20732077

20742078
string txid = find_value(o, "txid").get_str();
20752079
if (!IsHex(txid))
@@ -2369,13 +2373,13 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
23692373
" \"changePosition\" (numeric, optional, default random) The index of the change output\n"
23702374
" \"includeWatching\" (boolean, optional, default false) Also select inputs which are watch only\n"
23712375
" \"lockUnspents\" (boolean, optional, default false) Lock selected unspent outputs\n"
2372-
" \"feeRate\" (numeric, optional, default 0=estimate) Set a specific feerate (fee per KB)\n"
2376+
" \"feeRate\" (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate (" + CURRENCY_UNIT + " per KB)\n"
23732377
" }\n"
23742378
" for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}\n"
23752379
"\nResult:\n"
23762380
"{\n"
23772381
" \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n"
2378-
" \"fee\": n, (numeric) Fee the resulting transaction pays\n"
2382+
" \"fee\": n, (numeric) Fee in " + CURRENCY_UNIT + " the resulting transaction pays\n"
23792383
" \"changepos\": n (numeric) The position of the added change output, or -1\n"
23802384
"}\n"
23812385
"\"hex\" \n"
@@ -2409,7 +2413,15 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
24092413

24102414
UniValue options = params[1];
24112415

2412-
RPCTypeCheckObj(options, boost::assign::map_list_of("changeAddress", UniValue::VSTR)("changePosition", UniValue::VNUM)("includeWatching", UniValue::VBOOL)("lockUnspents", UniValue::VBOOL)("feeRate", UniValue::VNUM), true, true);
2416+
RPCTypeCheckObj(options,
2417+
{
2418+
{"changeAddress", UniValueType(UniValue::VSTR)},
2419+
{"changePosition", UniValueType(UniValue::VNUM)},
2420+
{"includeWatching", UniValueType(UniValue::VBOOL)},
2421+
{"lockUnspents", UniValueType(UniValue::VBOOL)},
2422+
{"feeRate", UniValueType()}, // will be checked below
2423+
},
2424+
true, true);
24132425

24142426
if (options.exists("changeAddress")) {
24152427
CBitcoinAddress address(options["changeAddress"].get_str());
@@ -2431,7 +2443,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
24312443

24322444
if (options.exists("feeRate"))
24332445
{
2434-
feeRate = CFeeRate(options["feeRate"].get_real());
2446+
feeRate = CFeeRate(AmountFromValue(options["feeRate"]));
24352447
overrideEstimatedFeerate = true;
24362448
}
24372449
}

0 commit comments

Comments
 (0)