Closed developer-betandeal closed 11 months ago
More interesting code:
>>>from bitcoinlib.services.services import Service
>>>s = Service ('testnet',strict=False)
>>>block = s.getblock(2541949)
>>> len(block.transactions)
25
>>> block
<Block(00000000000000129c29a48c1c2606cb09ad90ce26865a30f0e118c184cc50fc, 2541949, transactions: 120)>
As you can see block.transactions has only 25 elements BUT the block object says that have 120 transactions
I found the problem...
From documentation:
limit (int) – Maximum number of transactions to parse. Default is 0: parse all transactions. Only used if parse_transaction is set to True
But this is not true, the default seems to be 25. The code works correctly if you add limit=1000 in the getblock function.
If you searching for a specific transaction hash inside a block you do not have to parse transactions. Otherwise you generate a lot of extra requests to service providers.
from bitcoinlib.services.services import Service
s = Service ('testnet',strict=False)
block = s.getblock(2541949, parse_transactions=False)
This will return the block with all transaction id's.
Thank you,
But I'm searching for outputs to one known hash. I suppose this cannot be searched if you do not parse the transactions. Right?
No then you need to parse transactions. Best to use your own bitcoin or bcoin node, or get an API key somewhere because this will generate a lot of requests.
No then you need to parse transactions. Best to use your own bitcoin or bcoin node, or get an API key somewhere because this will generate a lot of requests.
Yes, I have my own node. I have configured in the providers.json and I see calls, but not all. There are some priority value to maximize the calls to our own node?
Yes you set the priority a bit higher then other providers. Then it first tries you own node, if it fails it switches to a provider with a lower priority.
I have code that load the blocks searching for transactions with some hash, I use the service.getblock(number-of-block) to retrieve the block transactions.
The log says this:
Total: 25 transactions
BUT if you search this block (testnet) https://live.blockcypher.com/btc-testnet/block/00000000000000129c29a48c1c2606cb09ad90ce26865a30f0e118c184cc50fc/
You can see that there are 120 transactions in the block... How can it be? What I'm doing wrong?