Of course, I would be limited by the hardware used for running both, the full-node
and the blockexplorer underneath. Thanks for pointing out to take this into consideration.
Also thanks for the snippet you provided. This is a really helpful for me as a beginner. How did you know which module is the correct one for this task? Did you just run something similar like
in pycoins' root folder? On my computer I get this result...
~/pycoin$ grep -R -i 'get_balance'
pycoin/wallet/SQLite3Wallet.py: while confirmations > 0 and self.get_balance(confirmations=confirmations) < amount + estimated_fee:
pycoin/wallet/SQLite3Wallet.py: def get_balance(self, confirmations=1):
pycoin/services/blockcypher.py: def get_balance(self, address):
So you know that the particular file we're looking for is pycoin/services/blockcypher.py and the class is called "BlockcypherProvider" where it is contained. Is that correct? My goal ist to learn, that's why I am asking this stupid questions, I don't want to simply copy&paste&use
currently my script and the provided address.lst looks like that:
$ cat address.lst
157dPuCytnX1tTDcviaqxxTogRzTJUSbc4
3HvgFC6VSeT3DZthW4CH6QK9VYmS2KDwA8
bc1qaqn5ay35jm3whdj2z8y76n9q4d7wlx6vemrp0k
1EhpfhPtnRFUi1B8Z8hSEHrnNv6qDC5abp
#!/usr/bin/python3
import sys
from pycoin.services.blockcypher import BlockcypherProvider
args = sys.argv
filepath = args[1]
bp = BlockcypherProvider()
with open(filepath, 'r') as f:
addresslist = f.readlines()
addresslist = [a.strip('\n') for a in addresslist]
# do something with address list here
print(addresslist)
# retrieve and print balance and tx info of each address listed in provided address.lst
# with a line separator (horizontal line or or a line feed \n or similar)
result = bp.get_balance(addresslist)
print(result)
I execute the script with
./myscript.py address.lst
but I get the error
['157dPuCytnX1tTDcviaqxxTogRzTJUSbc4', '3HvgFC6VSeT3DZthW4CH6QK9VYmS2KDwA8', 'bc1qaqn5ay35jm3whdj2z8y76n9q4d7wlx6vemrp0k', '1EhpfhPtnRFUi1B8Z8hSEHrnNv6qDC5abp']
Traceback (most recent call last):
File "/home/citb0in/myscript.py", line 18, in <module>
result = bp.get_balance(addresslist)
File "/home/citb0in/.local/lib/python3.10/site-packages/pycoin/services/blockcypher.py", line 63, in get_balance
url = self.base_url("addrs/%s" % (address + url_append))
TypeError: can only concatenate list (not "str") to list
I am pretty sure this error occurs due to addresslist containing several addresses. Is the variable "addresses" a string type here in this example or is it an array? What is the best approach to run the get_balance correctly against a bunch of addresses? Thank you so much for your patience and assistance.
EDIT: I think that was the culprit. The variable is kind of an array, at least I am pretty sure it is not a string or a concatenated string but rather a list. I've made some progress and it seems, that it works. Here my actual snippet. Please look over it and tell me where the errors are or how you suggest to optimize for better performance.
#!/usr/bin/python3
import sys
from pycoin.services.blockcypher import BlockcypherProvider
args = sys.argv
filepath = args[1]
bp = BlockcypherProvider()
with open(filepath, 'r') as f:
addresslist = f.readlines()
addresslist = [a.strip('\n') for a in addresslist]
# do something with address list here
print(addresslist)
# retrieve and output balance and tx info of each address listed in provided address.lst
# with a line separator (horizontal line or similar)
#result = bp.get_balance(addresslist)
for details in addresslist:
result = bp.get_balance(details)
print(result)
print('―' * 40) # U+2015, Horizontal Bar, 40 times