Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction time #29

Closed
Marto32 opened this issue Feb 24, 2018 · 4 comments
Closed

Transaction time #29

Marto32 opened this issue Feb 24, 2018 · 4 comments

Comments

@Marto32
Copy link

Marto32 commented Feb 24, 2018

Is there a way to access transaction time? I only see the following methods on transaction:

['__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_hash',
 '_locktime',
 '_txid',
 '_version',
 'from_hex',
 'hash',
 'hex',
 'inputs',
 'is_coinbase',
 'is_segwit',
 'locktime',
 'n_inputs',
 'n_outputs',
 'outputs',
 'size',
 'txid',
 'uses_bip69',
 'uses_replace_by_fee',
 'version']

And the following on block:

['__class__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__',
 '_hash',
 '_header',
 '_n_transactions',
 '_transactions',
 'from_hex',
 'hash',
 'header',
 'height',
 'hex',
 'n_transactions',
 'size',
 'transactions']

locktime on transaction appears to be 0 in the first few I've tried to access.

@alecalve
Copy link
Owner

Transactions don't have a time attached to them, only blocks do.

For transactions, block explorers usually display either the time of the block the transaction was confirmed in, or the time they first saw the transaction in the mempool.

@Marto32
Copy link
Author

Marto32 commented Feb 24, 2018

@alecalve right but I posted the block methods in my comment as well. Which one of those allows us to obtain the block time?

@alecalve
Copy link
Owner

It's in the header, it should be block.header.timestamp

@levushakov
Copy link
Contributor

Is it possible to get the confirmed block number of a transaction? For example if I use

import os
from blockchain_parser.blockchain import Blockchain
import plyvel

blockchain_path = "~/.bitcoin"  # Update this path to your local Bitcoin blockchain data directory
blockchain = Blockchain(os.path.expanduser(blockchain_path + "/blocks"))

txid = "dfcec48bb8491856c353306ab5febeb7e99e4d783eedf3de98f3ee0812b92bad"

plyvel_db = plyvel.DB(
    os.path.expanduser(blockchain_path + "/indexes/txindex"),
    compression=None,
)

result = blockchain.get_transaction(
    txid, plyvel_db
)

I get a transaction object Transaction(48a387570eeffb07e8e84642efe36bc4088285fc04db91743a9850bfd1611af2). I would like to know the block that it was confirmed at.

levushakov added a commit to levushakov/python-bitcoin-blockchain-parser that referenced this issue Mar 5, 2024
alecalve added a commit that referenced this issue Mar 23, 2024
Issue #29 & #105 solved: get_transaction() returns block header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants