bitcoinlib icon indicating copy to clipboard operation
bitcoinlib copied to clipboard

Error Importing Transactions: Address not Found

Open rossbates opened this issue 3 years ago • 2 comments

Hello - I'm trying to import btc transactions into a wallet using a connection to my electrumx server.

The relevant code I'm using is straight forward:

w = Wallet(1)
tx = Transaction.parse(rawtx="...")
w.transaction_import(tx)

I'm certain that the wallet is valid and has an address generated that matches an output in the transaction. Reading the documentation what I'm expecting it to do is import the relevant transaction for the matching address and ignore the others

https://bitcoinlib.readthedocs.io/en/latest/source/bitcoinlib.transactions.html?highlight=transaction_import#bitcoinlib.transactions.Transaction.parse

What's happening when I run the import is that the code errors on the UTXO/addresses for other addresses in the transaction not associated to my wallet.

UTXO %s and key with address %s not found in this wallet

Am I approaching this correctly? Thanks!

rossbates avatar Apr 03 '22 12:04 rossbates

The code probably fails because the keys of the inputs are not known in the wallet, only the outputs keys.

I'm not sure what your end-goal is, but why not updating the wallet with w.scan(), to import the latest transactions?

mccwdev avatar Apr 20 '22 07:04 mccwdev

What I'm trying to accomplish is maintaining multiple offline wallets. In this case offline being no 3rd party services using cold storage wallets.

I have a local electrumx server running and I can query it to get transaction history for any given xpub.

https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-scripthash-get-history

From there what I was trying to do is iterate through the list getting the raw transaction values

https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-get

I think I misinterpreted how the transaction importer worked assuming that it only imported data for the associated addresses in the block.

The reason I haven't gone down the path of setting up a service to talk to the bitcoin node directly is because I assumed electrumx was the easier path for indexing multiple xpubs. I don't want to create/store multiple wallets (and private keys) directly on the btc node.

rossbates avatar Apr 20 '22 13:04 rossbates

See https://github.com/1200wd/bitcoinlib/issues/234

mccwdev avatar Jan 15 '24 21:01 mccwdev