transactions – How one can get block peak from CTransactionRef object in Bitcoin C++ code?

on

|

views

and

comments


The block peak for a transaction is also recorded in two other puts: the txindex, or within the pockets. Either one of those have purposes that may take a transaction hash and go back details about the transaction, together with the transaction itself, the block hash it’s showed in, and so forth. Alternatively those don’t seem to be at all times to be had as they’re non-compulsory options, nor are they to be had in all portions of the codebase. It depends upon what you might be if truth be told seeking to do.

With out a txindex or a pockets, it is not imaginable to get the block peak as this information isn’t recorded anyplace, and usually does now not want to be.


If you’re within the pockets, i.e. have a CWallet to be had, then you’ll do one thing like:

// Assuming pockets is a CWallet& that already exists
// Assuming tx is a CTransactionRef that already exists
const CWalletTx* wtx = pockets.GetWalletTx(tx->GetHash());
if (wtx && (auto conf = wtx->state<TxStateConfirmed>())) {
    uint256 block_hash = conf->confirmed_block_hash;
    int block_height;
    chain().findBlock(block_hash, FoundBlock().peak(block_height));
}

The peak will probably be positioned into block_height.


If the txindex is to be had, it’s good to do one thing like:

// Assuming tx is a CTranasctionRef that already exists
// Assuming chainman is a CChainMan that already exists
CTransactionRef dummy;
uint256 block_hash;
g_txindex->FindTx(tx->GetHash(), block_hash, dummy);
int block_height = chainman.m_blockman.LookupBlockIndex(block_hash)->nHeight;

The FindTx serve as will look up the transaction within the txindex given via the hash within the first parameter. The block hash will probably be positioned into the second one parameter, and the transaction that used to be discovered into the 3rd parameter.

Share this
Tags

Must-read

Tesla Govt Says Repair For Vampire Drain In Sentry Mode Coming In Q2: ‘Energy Intake Wishes Development’ – Tesla (NASDAQ:TSLA)

Tesla Inc TSLA govt, Drew Baglino, on Thursday printed that the corporate is operating on liberating a device replace for decreasing energy intake...

Dividend Kings In Focal point: Phone & Information Techniques

Printed on February twenty second, 2024 through Bob Ciura The Dividend Kings consist of businesses that experience raised their dividends for a minimum of...

Tyler Perry Calls On Leisure Trade, Executive To Corral AI Prior to Everybody Is Out Of Trade

Tyler Perry has observed demonstrations of what AI can do. Whilst he's astonished, he’s additionally sounding an alarm. Perry is already balloting together...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here