@@ -2359,3 +2359,57 @@ UniValue listunspent(const UniValue& params, bool fHelp)
23592359
23602360 return results;
23612361}
2362+
2363+ UniValue fundrawtransaction (const UniValue& params, bool fHelp )
2364+ {
2365+ if (!EnsureWalletIsAvailable (fHelp ))
2366+ return NullUniValue;
2367+
2368+ if (fHelp || params.size () != 1 )
2369+ throw runtime_error (
2370+ " fundrawtransaction \" hexstring\"\n "
2371+ " \n Add inputs to a transaction until it has enough in value to meet its out value.\n "
2372+ " This will not modify existing inputs, and will add one change output to the outputs.\n "
2373+ " Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.\n "
2374+ " The inputs added will not be signed, use signrawtransaction for that.\n "
2375+ " \n Arguments:\n "
2376+ " 1. \" hexstring\" (string, required) The hex string of the raw transaction\n "
2377+ " \n Result:\n "
2378+ " {\n "
2379+ " \" hex\" : \" value\" , (string) The resulting raw transaction (hex-encoded string)\n "
2380+ " \" fee\" : n, (numeric) The fee added to the transaction\n "
2381+ " \" changepos\" : n (numeric) The position of the added change output, or -1\n "
2382+ " }\n "
2383+ " \" hex\" \n "
2384+ " \n Examples:\n "
2385+ " \n Create a transaction with no inputs\n "
2386+ + HelpExampleCli (" createrawtransaction" , " \" []\" \" {\\\" myaddress\\\" :0.01}\" " ) +
2387+ " \n Add sufficient unsigned inputs to meet the output value\n "
2388+ + HelpExampleCli (" fundrawtransaction" , " \" rawtransactionhex\" " ) +
2389+ " \n Sign the transaction\n "
2390+ + HelpExampleCli (" signrawtransaction" , " \" fundedtransactionhex\" " ) +
2391+ " \n Send the transaction\n "
2392+ + HelpExampleCli (" sendrawtransaction" , " \" signedtransactionhex\" " )
2393+ );
2394+
2395+ RPCTypeCheck (params, boost::assign::list_of (UniValue::VSTR));
2396+
2397+ // parse hex string from parameter
2398+ CTransaction origTx;
2399+ if (!DecodeHexTx (origTx, params[0 ].get_str ()))
2400+ throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " TX decode failed" );
2401+
2402+ CMutableTransaction tx (origTx);
2403+ CAmount nFee;
2404+ string strFailReason;
2405+ int nChangePos = -1 ;
2406+ if (!pwalletMain->FundTransaction (tx, nFee, nChangePos, strFailReason))
2407+ throw JSONRPCError (RPC_INTERNAL_ERROR, strFailReason);
2408+
2409+ UniValue result (UniValue::VOBJ);
2410+ result.push_back (Pair (" hex" , EncodeHexTx (tx)));
2411+ result.push_back (Pair (" changepos" , nChangePos));
2412+ result.push_back (Pair (" fee" , ValueFromAmount (nFee)));
2413+
2414+ return result;
2415+ }
0 commit comments