Conversation
added syntax highlighting to code blocks
backport bitcoins getrawtransaction additional parameter "myblockhash" to query transactions without -txindex
This reverts commit 850eabe.
patricklodder
left a comment
There was a problem hiding this comment.
Concept ACK.
Code review inline, and additionally: please add test cases for the new functionality to qa/rpc-tests/rawtransactions.py
Also needs a rebase to remove 2 stray commits at some point.
|
I did all changes that are clear to me already. What is the best practice - wait until everything is discussed and resolved and push the code again, or is an update from what I have so far also ok? |
This. Just push what commits you have when you think it solves things, even when partially. Fixed comments will be marked outdated and I'll resolve them (and if it's good I don't create a new one). Then can simply do a good old squash at the end to clean up commits mess. |
|
|
|
Much better now! Please don't forget to restore result.pushKV("hex", strHex);between line 269 and 270, I am quite sure that this is what is causing the CI to error out. |
|
f4611c2 contains the test scripts. Sorry for this mess... All test-scripts from 1 - 8 fail as well the step "No such transaction found" in test 11 fails. Maybe some can help me here again (: |
|
Hey there! I think the part when actually retrieving the tx is missing: // validation.cpp
bool GetTransaction(const uint256 &hash, CTransactionRef &txOut, const Consensus::Params& consensusParams, uint256 &hashBlock, bool fAllowSlow, CBlockIndex* blockIndex)
{
CBlockIndex *pindexSlow = blockIndex;
LOCK(cs_main);
if (!blockIndex) {
CTransactionRef ptx = mempool.get(hash);
if (ptx) {
txOut = ptx;
return true;
}
if (fTxIndex) {
CDiskTxPos postx;
if (pblocktree->ReadTxIndex(hash, postx)) {
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
if (file.IsNull())
return error("%s: OpenBlockFile failed", __func__);
CBlockHeader header;
try {
file >> header;
fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
file >> txOut;
} catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}
hashBlock = header.GetHash();
if (txOut->GetHash() != hash)
return error("%s: txid mismatch", __func__);
return true;
}
}
if (fAllowSlow) { // use coin database to locate block that contains transaction, and scan it
int nHeight = -1;
{
const CCoinsViewCache& view = *pcoinsTip;
const CCoins* coins = view.AccessCoins(hash);
if (coins)
nHeight = coins->nHeight;
}
if (nHeight > 0)
pindexSlow = chainActive[nHeight];
}
}
if (pindexSlow) {
CBlock block;
if (ReadBlockFromDisk(block, pindexSlow, consensusParams)) {
for (const auto& tx : block.vtx) {
if (tx->GetHash() == hash) {
txOut = tx;
hashBlock = pindexSlow->GetBlockHash();
return true;
}
}
}
}
return false;
}// validation.h
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false, CBlockIndex* blockIndex = nullptr); |
|
Hey @patricklodder is there any further to do on my side or do I only have to wait for your checks? (: |
| "2. verbose (bool, optional, default=false) If false, return a string, otherwise return a json object\n" | ||
| "3. \"blockhash\" (string, optional) The block in which to look for the transaction\n" |
There was a problem hiding this comment.
Is it worth adding a test or two when verbose is false but blockhash is provided?
| if (hash == Params().GenesisBlock().hashMerkleRoot) { | ||
| // Special exception for the genesis block coinbase transaction | ||
| throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "The genesis block coinbase is not considered an ordinary transaction and cannot be retrieved"); | ||
| } |
There was a problem hiding this comment.
Another case where it might be worth adding a test.
src/rpc/rawtransaction.cpp
Outdated
There was a problem hiding this comment.
Minor formatting nit: I read this wrong the first time. I recommend either indenting the result.pushKv(...) call or adding a blank line between these two lines.
|
Concept ACK from me and all tests pass. |
added myblockhash argument to getrawtransaction (bitcoin backport)