Browse Source

Make DecodeHexTx return a CMutableTransaction

0.14
Pieter Wuille 8 years ago
parent
commit
42fd8dee30
  1. 6
      src/bitcoin-tx.cpp
  2. 3
      src/core_io.h
  3. 2
      src/core_read.cpp
  4. 11
      src/rpc/rawtransaction.cpp
  5. 4
      src/wallet/rpcdump.cpp
  6. 9
      src/wallet/rpcwallet.cpp

6
src/bitcoin-tx.cpp

@ -623,7 +623,7 @@ static int CommandLineRawTx(int argc, char* argv[])
argv++; argv++;
} }
CTransaction txDecodeTmp; CMutableTransaction tx;
int startArg; int startArg;
if (!fCreateBlank) { if (!fCreateBlank) {
@ -636,15 +636,13 @@ static int CommandLineRawTx(int argc, char* argv[])
if (strHexTx == "-") // "-" implies standard input if (strHexTx == "-") // "-" implies standard input
strHexTx = readStdin(); strHexTx = readStdin();
if (!DecodeHexTx(txDecodeTmp, strHexTx, true)) if (!DecodeHexTx(tx, strHexTx, true))
throw std::runtime_error("invalid transaction encoding"); throw std::runtime_error("invalid transaction encoding");
startArg = 2; startArg = 2;
} else } else
startArg = 1; startArg = 1;
CMutableTransaction tx(txDecodeTmp);
for (int i = startArg; i < argc; i++) { for (int i = startArg; i < argc; i++) {
std::string arg = argv[i]; std::string arg = argv[i];
std::string key, value; std::string key, value;

3
src/core_io.h

@ -11,13 +11,14 @@
class CBlock; class CBlock;
class CScript; class CScript;
class CTransaction; class CTransaction;
class CMutableTransaction;
class uint256; class uint256;
class UniValue; class UniValue;
// core_read.cpp // core_read.cpp
CScript ParseScript(const std::string& s); CScript ParseScript(const std::string& s);
std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode = false); std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode = false);
bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx, bool fTryNoWitness = false); bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness = false);
bool DecodeHexBlk(CBlock&, const std::string& strHexBlk); bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
uint256 ParseHashUV(const UniValue& v, const std::string& strName); uint256 ParseHashUV(const UniValue& v, const std::string& strName);
uint256 ParseHashStr(const std::string&, const std::string& strName); uint256 ParseHashStr(const std::string&, const std::string& strName);

2
src/core_read.cpp

@ -90,7 +90,7 @@ CScript ParseScript(const std::string& s)
return result; return result;
} }
bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx, bool fTryNoWitness) bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness)
{ {
if (!IsHex(strHexTx)) if (!IsHex(strHexTx))
return false; return false;

11
src/rpc/rawtransaction.cpp

@ -520,13 +520,13 @@ UniValue decoderawtransaction(const JSONRPCRequest& request)
LOCK(cs_main); LOCK(cs_main);
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)); RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR));
CTransaction tx; CMutableTransaction mtx;
if (!DecodeHexTx(tx, request.params[0].get_str(), true)) if (!DecodeHexTx(mtx, request.params[0].get_str(), true))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
TxToJSON(tx, uint256(), result); TxToJSON(CTransaction(std::move(mtx)), uint256(), result);
return result; return result;
} }
@ -883,9 +883,10 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL)); RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL));
// parse hex string from parameter // parse hex string from parameter
CTransaction tx; CMutableTransaction mtx;
if (!DecodeHexTx(tx, request.params[0].get_str())) if (!DecodeHexTx(mtx, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
CTransaction tx(std::move(mtx));
uint256 hashTx = tx.GetHash(); uint256 hashTx = tx.GetHash();
bool fLimitFree = false; bool fLimitFree = false;

4
src/wallet/rpcdump.cpp

@ -267,7 +267,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
"2. \"txoutproof\" (string, required) The hex output from gettxoutproof that contains the transaction\n" "2. \"txoutproof\" (string, required) The hex output from gettxoutproof that contains the transaction\n"
); );
CTransaction tx; CMutableTransaction tx;
if (!DecodeHexTx(tx, request.params[0].get_str())) if (!DecodeHexTx(tx, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
uint256 hashTx = tx.GetHash(); uint256 hashTx = tx.GetHash();
@ -304,7 +304,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
if (pwalletMain->IsMine(tx)) { if (pwalletMain->IsMine(wtx)) {
pwalletMain->AddToWallet(wtx, false); pwalletMain->AddToWallet(wtx, false);
return NullUniValue; return NullUniValue;
} }

9
src/wallet/rpcwallet.cpp

@ -2557,17 +2557,16 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
} }
// parse hex string from parameter // parse hex string from parameter
CTransaction origTx; CMutableTransaction tx;
if (!DecodeHexTx(origTx, request.params[0].get_str(), true)) if (!DecodeHexTx(tx, request.params[0].get_str(), true))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
if (origTx.vout.size() == 0) if (tx.vout.size() == 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "TX must have at least one output"); throw JSONRPCError(RPC_INVALID_PARAMETER, "TX must have at least one output");
if (changePosition != -1 && (changePosition < 0 || (unsigned int)changePosition > origTx.vout.size())) if (changePosition != -1 && (changePosition < 0 || (unsigned int)changePosition > tx.vout.size()))
throw JSONRPCError(RPC_INVALID_PARAMETER, "changePosition out of bounds"); throw JSONRPCError(RPC_INVALID_PARAMETER, "changePosition out of bounds");
CMutableTransaction tx(origTx);
CAmount nFeeOut; CAmount nFeeOut;
string strFailReason; string strFailReason;

Loading…
Cancel
Save