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

3
src/core_io.h

@ -11,13 +11,14 @@ @@ -11,13 +11,14 @@
class CBlock;
class CScript;
class CTransaction;
class CMutableTransaction;
class uint256;
class UniValue;
// core_read.cpp
CScript ParseScript(const std::string& s);
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);
uint256 ParseHashUV(const UniValue& v, 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) @@ -90,7 +90,7 @@ CScript ParseScript(const std::string& s)
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))
return false;

11
src/rpc/rawtransaction.cpp

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

4
src/wallet/rpcdump.cpp

@ -267,7 +267,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request) @@ -267,7 +267,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
"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()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
uint256 hashTx = tx.GetHash();
@ -304,7 +304,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request) @@ -304,7 +304,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
LOCK2(cs_main, pwalletMain->cs_wallet);
if (pwalletMain->IsMine(tx)) {
if (pwalletMain->IsMine(wtx)) {
pwalletMain->AddToWallet(wtx, false);
return NullUniValue;
}

9
src/wallet/rpcwallet.cpp

@ -2557,17 +2557,16 @@ UniValue fundrawtransaction(const JSONRPCRequest& request) @@ -2557,17 +2557,16 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
}
// parse hex string from parameter
CTransaction origTx;
if (!DecodeHexTx(origTx, request.params[0].get_str(), true))
CMutableTransaction tx;
if (!DecodeHexTx(tx, request.params[0].get_str(), true))
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");
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");
CMutableTransaction tx(origTx);
CAmount nFeeOut;
string strFailReason;

Loading…
Cancel
Save