From 7d521f8fe809006b427f97c1dfec3aafd1fea233 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Tue, 11 Apr 2023 22:22:59 +0300 Subject: [PATCH] Add address->scripthash conversion tool --- contrib/script_hash.py | 31 +++++++++++++++++++++++++++++++ contrib/script_hash.sh | 1 + 2 files changed, 32 insertions(+) create mode 100755 contrib/script_hash.py create mode 120000 contrib/script_hash.sh diff --git a/contrib/script_hash.py b/contrib/script_hash.py new file mode 100755 index 0000000..47a62fe --- /dev/null +++ b/contrib/script_hash.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +import argparse +import datetime +import hashlib +import io +import sys + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--network', default='mainnet') + args = parser.parse_args() + + if args.network == 'regtest': + from pycoin.symbols.xrt import network + elif args.network == 'testnet': + from pycoin.symbols.xtn import network + elif args.network == 'mainnet': + from pycoin.symbols.btc import network + else: + raise ValueError(f"unknown network: {args.network}") + + for line in sys.stdin: + addr = line.strip() + script = network.parse.address(addr).script() + script_hash = hashlib.sha256(script).digest() + print(script_hash[::-1].hex()) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/contrib/script_hash.sh b/contrib/script_hash.sh new file mode 120000 index 0000000..a7906e5 --- /dev/null +++ b/contrib/script_hash.sh @@ -0,0 +1 @@ +venv_wrapper.sh \ No newline at end of file