spesmilo / electrumx

Alternative implementation of spesmilo/electrum-server
MIT License
441 stars 353 forks source link

blockchain.transaction.get not returning tx.vin[].txid #191

Closed educob closed 2 years ago

educob commented 2 years ago

Hi.

I am running the electrumX against a regtest bitcoind. When getting a tx I am not getting information about the vin.txid so I can't know where the utxos or the spent transaction outputs are.

How can I get this information?

Thanks.

soichisumi commented 2 years ago

blockchain.scripthash.listunspent returns utxos of scriptHash.

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

Due to the mechanics of the blockchain, it is not possible to know UTXO unless you use this convenience method, aggregate all transactions for all previous blocks, or use a third party API.

Can this help you?

educob commented 2 years ago

Thanks for answering. I am not sure i understand your answer.

I have seen that some free testnet electrumX servers returns enough tx information to construct the history of a bitocin address (they return tx.vin[].txid. So there is no need to call blockchain.scripthash.listunspent method. But others don't return the vin[].txid. And then even calling blockchain.scripthash.listunspent only serves to know which tx outputs haven't been spent but not in which tx the rest have been spent.

My electrumX connected to regtest doesn't return tx.vin[].txid. Is it a matter of electrumX version?

The method I use to compose and address history is from blueWallet: https://github.com/BlueWallet/BlueWallet/blob/master/blue_modules/BlueElectrum.js Method: getTransactionsFullByAddress in line 381. It expects tx to return vin[].txid.

Thanks again.

On Wed, Sep 21, 2022 at 10:11 PM Soichi Sumi @.***> wrote:

blockchain.scripthash.listunspent returns utxos of scriptHash.

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

Due to the way the blockchain works, if you don't use this convenience method, you will not be able to know the utxo unless you aggregate all transactions of all previous blocks or use a third-party API.

Can this help you?

— Reply to this email directly, view it on GitHub https://github.com/spesmilo/electrumx/issues/191#issuecomment-1254232308, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADA4E457WUPYOMIHD7UU73TV7N2YHANCNFSM6AAAAAAQSFVEZU . You are receiving this because you authored the thread.Message ID: @.***>

soichisumi commented 2 years ago

I have seen that some free testnet electrumX servers returns enough tx information to construct the history of a bitocin address (they return tx.vin[].txid).

How did you confirm this?

The get_history api used by https://github.com/BlueWallet/BlueWallet returns tx_hash and height, so not returning vin.txid is documented behavior. https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html#blockchain-scripthash-get-history

educob commented 2 years ago

Hi again.

Thakns for answering.

I first call blockchain.address.get_history to get tx_hash & height. Then for each transaction I call blockchain.transaction.get

When I call it in testnet electrumX server 'electrum1.cipig.net', 10068, ' tcp' requesting a tx I get:

{ txid: 'f606110c1b6d6b0b0f84349a62796ddc0046ca2081ed57bf58983fbb40b98974', hash: 'e9f0d6dcb6512ae69d4eaafd5dd5383a1a6080d223cffe6e29c0ba19bd1b7b94', version: 2, size: 223, vsize: 141, weight: 562, locktime: 0, vin: [ { txid: 'b2b932cb07265881d89c4c8bf9636a0e385b8e1fbe81a2072cdf63085c168ef3', vout: 0, scriptSig: [Object], txinwitness: [Array], sequence: 4294967295 } ], vout: [ { value: 0.00005, n: 0, scriptPubKey: [Object] }, { value: 0.00004859, n: 1, scriptPubKey: [Object] } ], hex: '0200...bab400000000', blockhash: '00000000000005f1d41300af0aa20e05ae22713c6fe5d4a66017df69f1573761', confirmations: 986, time: 1663155042, blocktime: 1663155042 }

As you can see vin.has txid so I can know (with some work) with utxos have been spent.

But when I call my regtest electrumX I get:

{ txid: 'b47dcd97abae8ede3c04f890fcb3eec4c93e14ee92f799daa9a2ca40c8fa5b39', hash: 'b831e60c86f459c3e58b47b48c2815a4f2bf77dfd8c929b74e65be7d05362b23', version: 2, size: 170, vsize: 143, weight: 572, locktime: 0, vin: [ { coinbase: '02dd000101', txinwitness: [Array], sequence: 4294967295 } ], vout: [ { value: 25, n: 0, scriptPubKey: [Object] }, { value: 0, n: 1, scriptPubKey: [Object] } ], hex: '02000000000101000...000', blockhash: '61b5a4c0451c629c1dacea4433a9005ee54f14502868dc4dde68febee46cc193', confirmations: 1912, time: 1663768590, blocktime: 1663768590 }

As you can see, from regtest there is no txid in vin[] so I have no way to know anything about spent utxos.

Thanks.

On Wed, Sep 21, 2022 at 11:35 PM Soichi Sumi @.***> wrote:

I have seen that some free testnet electrumX servers returns enough tx information to construct the history of a bitocin address (they return tx.vin[].txid).

How did you confirm this?

The get_history api used by https://github.com/BlueWallet/BlueWallet returns tx_hash and height, so not returning vin.txid is documented behavior.

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

— Reply to this email directly, view it on GitHub https://github.com/spesmilo/electrumx/issues/191#issuecomment-1254302662, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADA4E426JO4PA3IRQHVKUL3V7OERLANCNFSM6AAAAAAQSFVEZU . You are receiving this because you authored the thread.Message ID: @.***>

soichisumi commented 2 years ago

Hi. The transaction appears to be a coinbase transaction, and since a coinbase transaction has no parent vin, it is correct that there is no txid in the vin.

Due to the way bitcoin-based blockchains work, if you get a coinbase transaction, the response will look like this.

Please try to transfer the money yourself in regtest and do transaction.get for that transaction. You should get the desired result.

educob commented 2 years ago

Hi.

Thanks for you time.

Regards.

On Fri, Sep 23, 2022 at 3:05 AM Soichi Sumi @.***> wrote:

Hi. The transaction appears to be a coinbase transaction, and since a coinbase transaction has no parent vin, it is correct that there is no txid in the vin.

Due to the way bitcoin-based blockchains work, if you get a coinbase transaction, the response will look like this.

— Reply to this email directly, view it on GitHub https://github.com/spesmilo/electrumx/issues/191#issuecomment-1255727252, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADA4E467XANDH45EX62FIT3V7UF7BANCNFSM6AAAAAAQSFVEZU . You are receiving this because you authored the thread.Message ID: @.***>

educob commented 1 year ago

HI again.

I think the issue is that in regtest it was a coinbase tx. Silly me.

thanks for your time.

On Thu, Sep 22, 2022 at 11:05 AM Eduardo Cobian @.***> wrote:

Hi again.

Thakns for answering.

I first call blockchain.address.get_history to get tx_hash & height. Then for each transaction I call blockchain.transaction.get

When I call it in testnet electrumX server 'electrum1.cipig.net', 10068, ' tcp' requesting a tx I get:

{ txid: 'f606110c1b6d6b0b0f84349a62796ddc0046ca2081ed57bf58983fbb40b98974', hash: 'e9f0d6dcb6512ae69d4eaafd5dd5383a1a6080d223cffe6e29c0ba19bd1b7b94', version: 2, size: 223, vsize: 141, weight: 562, locktime: 0, vin: [ { txid: 'b2b932cb07265881d89c4c8bf9636a0e385b8e1fbe81a2072cdf63085c168ef3', vout: 0, scriptSig: [Object], txinwitness: [Array], sequence: 4294967295 } ], vout: [ { value: 0.00005, n: 0, scriptPubKey: [Object] }, { value: 0.00004859, n: 1, scriptPubKey: [Object] } ], hex: '0200...bab400000000', blockhash: '00000000000005f1d41300af0aa20e05ae22713c6fe5d4a66017df69f1573761', confirmations: 986, time: 1663155042, blocktime: 1663155042 }

As you can see vin.has txid so I can know (with some work) with utxos have been spent.

But when I call my regtest electrumX I get:

{ txid: 'b47dcd97abae8ede3c04f890fcb3eec4c93e14ee92f799daa9a2ca40c8fa5b39', hash: 'b831e60c86f459c3e58b47b48c2815a4f2bf77dfd8c929b74e65be7d05362b23', version: 2, size: 170, vsize: 143, weight: 572, locktime: 0, vin: [ { coinbase: '02dd000101', txinwitness: [Array], sequence: 4294967295 } ], vout: [ { value: 25, n: 0, scriptPubKey: [Object] }, { value: 0, n: 1, scriptPubKey: [Object] } ], hex: '02000000000101000...000', blockhash: '61b5a4c0451c629c1dacea4433a9005ee54f14502868dc4dde68febee46cc193', confirmations: 1912, time: 1663768590, blocktime: 1663768590 }

As you can see, from regtest there is no txid in vin[] so I have no way to know anything about spent utxos.

Thanks.

On Wed, Sep 21, 2022 at 11:35 PM Soichi Sumi @.***> wrote:

I have seen that some free testnet electrumX servers returns enough tx information to construct the history of a bitocin address (they return tx.vin[].txid).

How did you confirm this?

The get_history api used by https://github.com/BlueWallet/BlueWallet returns tx_hash and height, so not returning vin.txid is documented behavior.

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

— Reply to this email directly, view it on GitHub https://github.com/spesmilo/electrumx/issues/191#issuecomment-1254302662, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADA4E426JO4PA3IRQHVKUL3V7OERLANCNFSM6AAAAAAQSFVEZU . You are receiving this because you authored the thread.Message ID: @.***>