Bitcoin Forum
May 01, 2024, 04:55:59 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: looking for coinkit or pybitcoin for running on python3  (Read 282 times)
citb0in (OP)
Hero Member
*****
Offline Offline

Activity: 658
Merit: 656


Bitcoin g33k


View Profile
August 29, 2022, 12:33:55 PM
 #21

I'm not sure what the issue with the Python code is right now; I can take another look later.
Simply said: I have a file with valid Bitcoin addresses, each per line. The idea was somehow using function get_balance of pycoin library to query all these adresses contained in the file. I would be glad an it would be enough for the first step to get the result and redirect it to a new file result.txt which I could run several "grep" and "awk" filtering to it. I could then filter eg. to show only those adresses containing a positive balance, or to show those "greater than x.xx BTC" etc. However it would be awesome to have the option to retrieve not only the balance but also the state of transactions. I'd like to know if the adresses with balance > 0 had any historical outputs so I could run a query like "Show me all the addresses that either have a positive balance or had incoming/outgoing transactions  in the past.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
1714539359
Hero Member
*
Offline Offline

Posts: 1714539359

View Profile Personal Message (Offline)

Ignore
1714539359
Reply with quote  #2

1714539359
Report to moderator
There are several different types of Bitcoin clients. The most secure are full nodes like Bitcoin Core, which will follow the rules of the network no matter what miners do. Even if every miner decided to create 1000 bitcoins per block, full nodes would stick to the rules and reject those blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714539359
Hero Member
*
Offline Offline

Posts: 1714539359

View Profile Personal Message (Offline)

Ignore
1714539359
Reply with quote  #2

1714539359
Report to moderator
1714539359
Hero Member
*
Offline Offline

Posts: 1714539359

View Profile Personal Message (Offline)

Ignore
1714539359
Reply with quote  #2

1714539359
Report to moderator
1714539359
Hero Member
*
Offline Offline

Posts: 1714539359

View Profile Personal Message (Offline)

Ignore
1714539359
Reply with quote  #2

1714539359
Report to moderator
ABCbits
Legendary
*
Offline Offline

Activity: 2856
Merit: 7430


Crypto Swap Exchange


View Profile
August 29, 2022, 12:34:29 PM
Merited by seoincorporation (3), citb0in (1)
 #22

Thanks for your thoughts. I intend to set up and run my own full node in the future. I think I'll have an option (3) then, speaking: my Python application would simply do the queries against my own full-node. Advantages: Third parties don't know which addresses are being queried and I'm not restricted or limited in the amount and throughput of queries.

Take note you're limited by your hardware instead.

Am I seeing this correctly or do I have a thinking error? Or is "running an own full-node NOT equal runngin an own blockexplorer" ?

Running full node and block explorer are 2 different thing. Block explorer depends on full node to get all block and transaction. So you'll need to run both full node and block explorer.

However, I'm still facing the problem and question of how to access pycoins' .get_balance function to query one or more addresses online on the blockchain using the URL defined in pycoin. This is my first concernt at the moment, I need to build up the pyton commands. Am very grateful for any hint and suggestion as always.

I have trouble understanding your question, but here's example of working script.

Code:
from pycoin.services.blockcypher import BlockcypherProvider
bp = BlockcypherProvider()
result = bp.get_balance(address="157dPuCytnX1tTDcviaqxxTogRzTJUSbc4")
print(result)

Here's the output.

Quote
{'address': '157dPuCytnX1tTDcviaqxxTogRzTJUSbc4', 'total_received': 15011490, 'total_sentalance': 14518229, 'unconfirmed_balance': 0, 'final_balance': 14518229, 'n_tx': 4, 'uncon 0, 'final_n_tx': 4}

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
citb0in (OP)
Hero Member
*****
Offline Offline

Activity: 658
Merit: 656


Bitcoin g33k


View Profile
August 29, 2022, 01:20:23 PM
Last edit: August 29, 2022, 01:45:26 PM by citb0in
 #23

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
Code:
grep -R -i 'get_balance'
in pycoins' root folder? On my computer I get this result...
Quote
~/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  Roll Eyes

currently my script and the provided address.lst looks like that:
Code:
$ cat address.lst 

157dPuCytnX1tTDcviaqxxTogRzTJUSbc4
3HvgFC6VSeT3DZthW4CH6QK9VYmS2KDwA8
bc1qaqn5ay35jm3whdj2z8y76n9q4d7wlx6vemrp0k
1EhpfhPtnRFUi1B8Z8hSEHrnNv6qDC5abp

Code:
#!/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
Code:
./myscript.py address.lst

but I get the error
Quote
['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.

Code:
#!/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

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
Pages: « 1 [2]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!