Skip to content

Commit 42fd8de

Browse files
committed
Make DecodeHexTx return a CMutableTransaction
1 parent c3f5673 commit 42fd8de

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

src/bitcoin-tx.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ static int CommandLineRawTx(int argc, char* argv[])
623623
argv++;
624624
}
625625

626-
CTransaction txDecodeTmp;
626+
CMutableTransaction tx;
627627
int startArg;
628628

629629
if (!fCreateBlank) {
@@ -636,15 +636,13 @@ static int CommandLineRawTx(int argc, char* argv[])
636636
if (strHexTx == "-") // "-" implies standard input
637637
strHexTx = readStdin();
638638

639-
if (!DecodeHexTx(txDecodeTmp, strHexTx, true))
639+
if (!DecodeHexTx(tx, strHexTx, true))
640640
throw std::runtime_error("invalid transaction encoding");
641641

642642
startArg = 2;
643643
} else
644644
startArg = 1;
645645

646-
CMutableTransaction tx(txDecodeTmp);
647-
648646
for (int i = startArg; i < argc; i++) {
649647
std::string arg = argv[i];
650648
std::string key, value;

src/core_io.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
class CBlock;
1212
class CScript;
1313
class CTransaction;
14+
class CMutableTransaction;
1415
class uint256;
1516
class UniValue;
1617

1718
// core_read.cpp
1819
CScript ParseScript(const std::string& s);
1920
std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode = false);
20-
bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx, bool fTryNoWitness = false);
21+
bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness = false);
2122
bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
2223
uint256 ParseHashUV(const UniValue& v, const std::string& strName);
2324
uint256 ParseHashStr(const std::string&, const std::string& strName);

src/core_read.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ CScript ParseScript(const std::string& s)
9090
return result;
9191
}
9292

93-
bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx, bool fTryNoWitness)
93+
bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness)
9494
{
9595
if (!IsHex(strHexTx))
9696
return false;

src/rpc/rawtransaction.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,13 @@ UniValue decoderawtransaction(const JSONRPCRequest& request)
520520
LOCK(cs_main);
521521
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR));
522522

523-
CTransaction tx;
523+
CMutableTransaction mtx;
524524

525-
if (!DecodeHexTx(tx, request.params[0].get_str(), true))
525+
if (!DecodeHexTx(mtx, request.params[0].get_str(), true))
526526
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
527527

528528
UniValue result(UniValue::VOBJ);
529-
TxToJSON(tx, uint256(), result);
529+
TxToJSON(CTransaction(std::move(mtx)), uint256(), result);
530530

531531
return result;
532532
}
@@ -883,9 +883,10 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
883883
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)(UniValue::VBOOL));
884884

885885
// parse hex string from parameter
886-
CTransaction tx;
887-
if (!DecodeHexTx(tx, request.params[0].get_str()))
886+
CMutableTransaction mtx;
887+
if (!DecodeHexTx(mtx, request.params[0].get_str()))
888888
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
889+
CTransaction tx(std::move(mtx));
889890
uint256 hashTx = tx.GetHash();
890891

891892
bool fLimitFree = false;

src/wallet/rpcdump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
267267
"2. \"txoutproof\" (string, required) The hex output from gettxoutproof that contains the transaction\n"
268268
);
269269

270-
CTransaction tx;
270+
CMutableTransaction tx;
271271
if (!DecodeHexTx(tx, request.params[0].get_str()))
272272
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
273273
uint256 hashTx = tx.GetHash();
@@ -304,7 +304,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
304304

305305
LOCK2(cs_main, pwalletMain->cs_wallet);
306306

307-
if (pwalletMain->IsMine(tx)) {
307+
if (pwalletMain->IsMine(wtx)) {
308308
pwalletMain->AddToWallet(wtx, false);
309309
return NullUniValue;
310310
}

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,17 +2557,16 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
25572557
}
25582558

25592559
// parse hex string from parameter
2560-
CTransaction origTx;
2561-
if (!DecodeHexTx(origTx, request.params[0].get_str(), true))
2560+
CMutableTransaction tx;
2561+
if (!DecodeHexTx(tx, request.params[0].get_str(), true))
25622562
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
25632563

2564-
if (origTx.vout.size() == 0)
2564+
if (tx.vout.size() == 0)
25652565
throw JSONRPCError(RPC_INVALID_PARAMETER, "TX must have at least one output");
25662566

2567-
if (changePosition != -1 && (changePosition < 0 || (unsigned int)changePosition > origTx.vout.size()))
2567+
if (changePosition != -1 && (changePosition < 0 || (unsigned int)changePosition > tx.vout.size()))
25682568
throw JSONRPCError(RPC_INVALID_PARAMETER, "changePosition out of bounds");
25692569

2570-
CMutableTransaction tx(origTx);
25712570
CAmount nFeeOut;
25722571
string strFailReason;
25732572

0 commit comments

Comments
 (0)