python-bitcoin-blockchain-parser icon indicating copy to clipboard operation
python-bitcoin-blockchain-parser copied to clipboard

db parameter in get_transaction

Open czanoci opened this issue 3 years ago • 2 comments

What should we pass as the database db in get_transaction(txid, db)? Is there any sample code that showcases the use of this function? Thanks!

czanoci avatar Jun 10 '22 16:06 czanoci

Do you resolve this problem?

JavierPorron avatar Aug 29 '22 10:08 JavierPorron

I finally resolve it. Just you have to open the leveldb index tx and pass it as parameter.

db = plyvel.DB(os.path.expanduser('~/.bitcoin/indexes/txindex'), compression=None)

tx = blockchain.get_transaction(txid,index)

db.close()

...

JavierPorron avatar Aug 29 '22 12:08 JavierPorron

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 avatar Mar 02 '24 16:03 levushakov