Skip to content

Commit

Permalink
Removed redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
surangap committed Apr 27, 2021
1 parent 77e8b5f commit 8a04601
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 51 deletions.
6 changes: 2 additions & 4 deletions src/masternodes/rpc_tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,10 @@ UniValue decodecustomtx(const JSONRPCRequest& request)

RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL});

CMutableTransaction mtx;

bool try_witness = request.params[1].isNull() ? true : request.params[1].get_bool();
bool try_no_witness = request.params[1].isNull() ? true : !request.params[1].get_bool();

CMutableTransaction mtx;
if (!DecodeHexTx(mtx, request.params[0].get_str(), try_no_witness, try_witness)) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
}
Expand Down Expand Up @@ -802,13 +801,12 @@ UniValue decodecustomtx(const JSONRPCRequest& request)
result.pushKV("txid", tx->GetHash().GetHex());
result.pushKV("type", ToString(guess));
result.pushKV("valid", res.ok ? true : false); // no actual block height

if (!res.ok) {
result.pushKV("error", res.msg);
} else {
result.pushKV("results", txResults);
}

return result;
} else {
// Should not get here without prior failure.
Expand Down
45 changes: 0 additions & 45 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,51 +1009,6 @@ bool GetTransaction(const uint256& hash, CTransactionRef& txOut, const Consensus
return false;
}

/**
* If the transaction hash is found inside a block, the block hash is placed in hashBlock.
* If blockIndex is provided, the transaction is fetched from the corresponding block and its hash is placed in hashBlock.
*/
bool GetBlockHash(const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock, const CBlockIndex* const blockIndex)
{
CTransactionRef txOut;
//try the genesis block
for (auto && genesisTx : Params().GenesisBlock().vtx) {
if (genesisTx->GetHash() == hash) {
// Return genesis tx
hashBlock = consensusParams.hashGenesisBlock;
txOut = genesisTx;
return true;
}
}

LOCK(cs_main);
if (!blockIndex) {
//try mempool and txindex
CTransactionRef ptx = mempool.get(hash);
if (ptx) {
txOut = ptx;
}

if (g_txindex) {
return g_txindex->FindTx(hash, hashBlock, txOut);
}
} else {
//Load from disk
CBlock block;
if (ReadBlockFromDisk(block, blockIndex, consensusParams)) {
for (const auto& tx : block.vtx) {
if (tx->GetHash() == hash) {
txOut = tx;
hashBlock = blockIndex->GetBlockHash();
return true;
}
}
}
}

return false;
}

//////////////////////////////////////////////////////////////////////////////
//
// CBlock and CBlockIndex
Expand Down
2 changes: 0 additions & 2 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ void UnloadBlockIndex();
void ThreadScriptCheck(int worker_num);
/** Retrieve a transaction (from memory pool, or from disk, if possible) */
bool GetTransaction(const uint256& hash, CTransactionRef& tx, const Consensus::Params& params, uint256& hashBlock, const CBlockIndex* const blockIndex = nullptr);
/** Retrieve a block hash which includes the transaction hash (from memory pool, or from disk, if possible)*/
bool GetBlockHash(const uint256& hash, const Consensus::Params& params, uint256& hashBlock, const CBlockIndex* const blockIndex = nullptr);
/**
* Find the best known block, and make it the tip of the block chain
*
Expand Down

0 comments on commit 8a04601

Please sign in to comment.