mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Add fundrawtransaction RPC method
This commit is contained in:
@@ -2359,3 +2359,57 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
UniValue fundrawtransaction(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (!EnsureWalletIsAvailable(fHelp))
|
||||
return NullUniValue;
|
||||
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
"fundrawtransaction \"hexstring\"\n"
|
||||
"\nAdd inputs to a transaction until it has enough in value to meet its out value.\n"
|
||||
"This will not modify existing inputs, and will add one change output to the outputs.\n"
|
||||
"Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n"
|
||||
"The inputs added will not be signed, use signrawtransaction for that.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"hexstring\" (string, required) The hex string of the raw transaction\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n"
|
||||
" \"fee\": n, (numeric) The fee added to the transaction\n"
|
||||
" \"changepos\": n (numeric) The position of the added change output, or -1\n"
|
||||
"}\n"
|
||||
"\"hex\" \n"
|
||||
"\nExamples:\n"
|
||||
"\nCreate a transaction with no inputs\n"
|
||||
+ HelpExampleCli("createrawtransaction", "\"[]\" \"{\\\"myaddress\\\":0.01}\"") +
|
||||
"\nAdd sufficient unsigned inputs to meet the output value\n"
|
||||
+ HelpExampleCli("fundrawtransaction", "\"rawtransactionhex\"") +
|
||||
"\nSign the transaction\n"
|
||||
+ HelpExampleCli("signrawtransaction", "\"fundedtransactionhex\"") +
|
||||
"\nSend the transaction\n"
|
||||
+ HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")
|
||||
);
|
||||
|
||||
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR));
|
||||
|
||||
// parse hex string from parameter
|
||||
CTransaction origTx;
|
||||
if (!DecodeHexTx(origTx, params[0].get_str()))
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
|
||||
|
||||
CMutableTransaction tx(origTx);
|
||||
CAmount nFee;
|
||||
string strFailReason;
|
||||
int nChangePos = -1;
|
||||
if(!pwalletMain->FundTransaction(tx, nFee, nChangePos, strFailReason))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, strFailReason);
|
||||
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("hex", EncodeHexTx(tx)));
|
||||
result.push_back(Pair("changepos", nChangePos));
|
||||
result.push_back(Pair("fee", ValueFromAmount(nFee)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user