Browse Source
Add testnet support for address-based balance query tool
refactor-mempool
Roman Zeyde
7 years ago
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
1 changed files with
21 additions and
7 deletions
-
tools/addr.py
|
|
@ -1,18 +1,32 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
import hashlib |
|
|
|
import sys |
|
|
|
import argparse |
|
|
|
|
|
|
|
from pycoin.coins.bitcoin.networks import BitcoinMainnet |
|
|
|
from pycoin.coins.bitcoin.networks import BitcoinTestnet, BitcoinMainnet |
|
|
|
|
|
|
|
import client |
|
|
|
|
|
|
|
def main(): |
|
|
|
conn = client.Connection(('localhost', 50001)) |
|
|
|
addr, = sys.argv[1:] |
|
|
|
script = BitcoinMainnet.ui.script_for_address(addr) |
|
|
|
script_hash = hashlib.sha256(script).digest()[::-1].hex() |
|
|
|
res = conn.call('blockchain.scripthash.get_balance', script_hash)['result'] |
|
|
|
print('{} has {} satoshis'.format(addr, res)) |
|
|
|
parser = argparse.ArgumentParser() |
|
|
|
parser.add_argument('--testnet', action='store_true') |
|
|
|
parser.add_argument('address', nargs='+') |
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
if args.testnet: |
|
|
|
Network = BitcoinTestnet |
|
|
|
port = 60001 |
|
|
|
else: |
|
|
|
Network = BitcoinMainnet |
|
|
|
port = 50001 |
|
|
|
|
|
|
|
conn = client.Connection(('localhost', port)) |
|
|
|
for addr in args.address: |
|
|
|
script = Network.ui.script_for_address(addr) |
|
|
|
script_hash = hashlib.sha256(script).digest()[::-1].hex() |
|
|
|
reply = conn.call('blockchain.scripthash.get_balance', script_hash) |
|
|
|
result = reply['result'] |
|
|
|
print('{} has {} satoshis'.format(addr, result)) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|