Skip to content

Commit a188353

Browse files
committed
Switch GetTransaction to returning a CTransactionRef
1 parent 2efcfa5 commit a188353

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/rest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
363363
if (!ParseHashStr(hashStr, hash))
364364
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
365365

366-
CTransaction tx;
366+
CTransactionRef tx;
367367
uint256 hashBlock = uint256();
368368
if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true))
369369
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
@@ -388,7 +388,7 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
388388

389389
case RF_JSON: {
390390
UniValue objTx(UniValue::VOBJ);
391-
TxToJSON(tx, hashBlock, objTx);
391+
TxToJSON(*tx, hashBlock, objTx);
392392
string strJSON = objTx.write() + "\n";
393393
req->WriteHeader("Content-Type", "application/json");
394394
req->WriteReply(HTTP_OK, strJSON);

src/rpc/rawtransaction.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,19 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
218218
}
219219
}
220220

221-
CTransaction tx;
221+
CTransactionRef tx;
222222
uint256 hashBlock;
223223
if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true))
224224
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
225225

226-
string strHex = EncodeHexTx(tx);
226+
string strHex = EncodeHexTx(*tx);
227227

228228
if (!fVerbose)
229229
return strHex;
230230

231231
UniValue result(UniValue::VOBJ);
232232
result.push_back(Pair("hex", strHex));
233-
TxToJSON(tx, hashBlock, result);
233+
TxToJSON(*tx, hashBlock, result);
234234
return result;
235235
}
236236

@@ -289,7 +289,7 @@ UniValue gettxoutproof(const JSONRPCRequest& request)
289289

290290
if (pblockindex == NULL)
291291
{
292-
CTransaction tx;
292+
CTransactionRef tx;
293293
if (!GetTransaction(oneTxid, tx, Params().GetConsensus(), hashBlock, false) || hashBlock.IsNull())
294294
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block");
295295
if (!mapBlockIndex.count(hashBlock))

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
984984
}
985985

986986
/** Return transaction in txOut, and if it was found inside a block, its hash is placed in hashBlock */
987-
bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::Params& consensusParams, uint256 &hashBlock, bool fAllowSlow)
987+
bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, const Consensus::Params& consensusParams, uint256 &hashBlock, bool fAllowSlow)
988988
{
989989
CBlockIndex *pindexSlow = NULL;
990990

@@ -993,7 +993,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::P
993993
CTransactionRef ptx = mempool.get(hash);
994994
if (ptx)
995995
{
996-
txOut = *ptx;
996+
txOut = ptx;
997997
return true;
998998
}
999999

@@ -1012,7 +1012,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::P
10121012
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
10131013
}
10141014
hashBlock = header.GetHash();
1015-
if (txOut.GetHash() != hash)
1015+
if (txOut->GetHash() != hash)
10161016
return error("%s: txid mismatch", __func__);
10171017
return true;
10181018
}
@@ -1035,7 +1035,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::P
10351035
if (ReadBlockFromDisk(block, pindexSlow, consensusParams)) {
10361036
for (const auto& tx : block.vtx) {
10371037
if (tx->GetHash() == hash) {
1038-
txOut = *tx;
1038+
txOut = tx;
10391039
hashBlock = pindexSlow->GetBlockHash();
10401040
return true;
10411041
}

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ bool IsInitialBlockDownload();
276276
*/
277277
std::string GetWarnings(const std::string& strFor);
278278
/** Retrieve a transaction (from memory pool, or from disk, if possible) */
279-
bool GetTransaction(const uint256 &hash, CTransaction &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
279+
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
280280
/** Find the best known block, and make it the tip of the block chain */
281281
bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, const CBlock* pblock = NULL);
282282
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);

0 commit comments

Comments
 (0)