mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 01:43:29 +01:00
enhance contribs to allow to connect to an external server
This commit is contained in:
parent
b94c98fc31
commit
74f13419a8
1
contrib/.gitignore
vendored
Normal file
1
contrib/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.venv
|
@ -5,10 +5,11 @@ import json
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--host', default='localhost')
|
||||
parser.add_argument("txid")
|
||||
args = parser.parse_args()
|
||||
|
||||
conn = client.Client(("localhost", 50001))
|
||||
conn = client.Client((args.host, 50001))
|
||||
tx, = conn.call([client.request("blockchain.transaction.get", args.txid, True)])
|
||||
print(json.dumps(tx))
|
||||
|
||||
|
@ -5,7 +5,6 @@ import hashlib
|
||||
import io
|
||||
import sys
|
||||
|
||||
import pycoin
|
||||
from logbook import Logger, StreamHandler
|
||||
import prettytable
|
||||
|
||||
@ -30,6 +29,7 @@ def show_rows(rows, field_names):
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--host', default='localhost')
|
||||
parser.add_argument('--network', default='mainnet')
|
||||
parser.add_argument('address', nargs='+')
|
||||
args = parser.parse_args()
|
||||
@ -46,7 +46,7 @@ def main():
|
||||
else:
|
||||
raise ValueError(f"unknown network: {args.network}")
|
||||
|
||||
hostport = ('localhost', port)
|
||||
hostport = (args.host, port)
|
||||
log.info('connecting to {}:{}', *hostport)
|
||||
conn = client.Client(hostport)
|
||||
|
||||
|
@ -1,4 +1,18 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
cd `dirname $0`
|
||||
.env/bin/python history.py $*
|
||||
|
||||
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"
|
||||
|
||||
venv=false
|
||||
if [ "$1" = "--venv" ];
|
||||
then
|
||||
shift
|
||||
venv=true
|
||||
fi
|
||||
|
||||
if [ $venv = true ] && [ ! -d .venv ]; then
|
||||
virtualenv .venv
|
||||
.venv/bin/pip install pycoin logbook prettytable
|
||||
fi
|
||||
|
||||
exec .venv/bin/python history.py "$@"
|
||||
|
@ -4,10 +4,11 @@ import client
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--host', default='localhost')
|
||||
parser.add_argument("txid")
|
||||
args = parser.parse_args()
|
||||
|
||||
conn = client.Client(("localhost", 50001))
|
||||
conn = client.Client((args.host, 50001))
|
||||
tx, = conn.call([client.request("blockchain.transaction.get", args.txid, True)])
|
||||
requests = []
|
||||
for vin in tx["vin"]:
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import hashlib
|
||||
import sys
|
||||
|
||||
@ -10,11 +11,20 @@ import client
|
||||
|
||||
log = Logger("xpub")
|
||||
|
||||
|
||||
def main():
|
||||
conn = client.Client(('localhost', 50001))
|
||||
xpub, = sys.argv[1:]
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--host', default='localhost')
|
||||
parser.add_argument('xpub')
|
||||
args = parser.parse_args()
|
||||
|
||||
conn = client.Client((args.host, 50001))
|
||||
total = 0
|
||||
xpub = network.parse.bip32_pub(xpub)
|
||||
xpub = network.parse.bip32(args.xpub)
|
||||
|
||||
if xpub is None:
|
||||
log.error('Invalid BIP32 pub key %s' % args.xpub)
|
||||
sys.exit(1)
|
||||
|
||||
for change in (0, 1):
|
||||
empty = 0
|
||||
|
@ -476,10 +476,10 @@ $ echo '{"jsonrpc": "2.0", "method": "server.version", "params": ["", "1.4"], "i
|
||||
|
||||
For more complex tasks, you may need to convert addresses to
|
||||
[script hashes](https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-basics.html#script-hashes) - see
|
||||
[contrib/addr.py](https://github.com/romanz/electrs/blob/master/contrib/addr.py) for getting an address balance and history:
|
||||
[contrib/history.py](https://github.com/romanz/electrs/blob/master/contrib/history.py) for getting an address balance and history:
|
||||
|
||||
```
|
||||
$ ./contrib/history.sh 144STc7gcb9XCp6t4hvrcUEKg9KemivsCR
|
||||
$ ./contrib/history.sh --venv 144STc7gcb9XCp6t4hvrcUEKg9KemivsCR
|
||||
[2021-08-18 13:56:40.254317] INFO: electrum: connecting to localhost:50001
|
||||
[2021-08-18 13:56:40.574461] INFO: electrum: subscribed to 1 scripthashes
|
||||
[2021-08-18 13:56:40.645072] DEBUG: electrum: 0.00000 mBTC (total)
|
||||
|
Loading…
Reference in New Issue
Block a user