Skip to content

Commit

Permalink
fundrawtransaction: add explicit rpc flag to treat as extended tx.
Browse files Browse the repository at this point in the history
fundtransaction is often (usually?) handed 0-input txs; these are misparsed
as extended transactions, and parsing fails.  We need an explicit flag
to have backwards compatibility for this case.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Apr 6, 2016
1 parent 2735b87 commit fa68b4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UniValue;
// core_read.cpp
extern CScript ParseScript(const std::string& s);
extern std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode = false);
extern bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx);
extern bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx, bool witnessFormatOK = true);
extern bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
extern uint256 ParseHashUV(const UniValue& v, const std::string& strName);
extern uint256 ParseHashStr(const std::string&, const std::string& strName);
Expand Down
4 changes: 2 additions & 2 deletions src/core_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ CScript ParseScript(const std::string& s)
return result;
}

bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx)
bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx, bool witnessFormatOK)
{
if (!IsHex(strHexTx))
return false;

vector<unsigned char> txData(ParseHex(strHexTx));
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS);
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | (witnessFormatOK ? SERIALIZE_TRANSACTION_WITNESS : 0));
try {
ssData >> tx;
}
Expand Down
9 changes: 7 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2508,7 +2508,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)

if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"fundrawtransaction \"hexstring\" includeWatching\n"
"fundrawtransaction \"hexstring\" includeWatching extendedFormat\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"
Expand All @@ -2520,6 +2520,7 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)
"\nArguments:\n"
"1. \"hexstring\" (string, required) The hex string of the raw transaction\n"
"2. includeWatching (boolean, optional, default false) Also select inputs which are watch only\n"
"3. extendedFormat (boolean, optional, default false) Transaction is in extended BIP144 form\n"
"\nResult:\n"
"{\n"
" \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n"
Expand All @@ -2540,9 +2541,13 @@ UniValue fundrawtransaction(const UniValue& params, bool fHelp)

RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL));

bool extendedFormat = false;
if (params.size() > 2)
extendedFormat = params[2].get_bool();

// parse hex string from parameter
CTransaction origTx;
if (!DecodeHexTx(origTx, params[0].get_str()))
if (!DecodeHexTx(origTx, params[0].get_str(), extendedFormat))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");

if (origTx.vout.size() == 0)
Expand Down

0 comments on commit fa68b4a

Please sign in to comment.