From 10232790e7891eb34a9542dd49b107ef7db6d581 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 14 Feb 2022 10:18:43 +0000 Subject: [PATCH] proto.btc: pubkey2segwitaddr() -> pubhash2segwitaddr() - also changed: pubkey2redeem_script() -> pubhash2redeem_script() --- mmgen/addrgen.py | 4 ++-- mmgen/proto/bch.py | 4 ++-- mmgen/proto/btc.py | 8 ++++---- mmgen/tool/coin.py | 5 +++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mmgen/addrgen.py b/mmgen/addrgen.py index 675a8cfc..e4a935c3 100755 --- a/mmgen/addrgen.py +++ b/mmgen/addrgen.py @@ -65,10 +65,10 @@ class addr_generator: def to_addr(self,data): return CoinAddr( self.proto, - self.proto.pubkey2segwitaddr(data.pubkey) ) + self.proto.pubhash2segwitaddr( hash160(data.pubkey)) ) def to_segwit_redeem_script(self,data): # NB: returns hex - return self.proto.pubkey2redeem_script(data.pubkey).hex() + return self.proto.pubhash2redeem_script( hash160(data.pubkey) ).hex() class bech32(base): diff --git a/mmgen/proto/bch.py b/mmgen/proto/bch.py index f2509296..abd12641 100755 --- a/mmgen/proto/bch.py +++ b/mmgen/proto/bch.py @@ -26,8 +26,8 @@ class mainnet(mainnet): max_tx_fee = '0.1' ignore_daemon_version = False - def pubkey2redeem_script(self,pubkey): raise NotImplementedError - def pubkey2segwitaddr(self,pubkey): raise NotImplementedError + def pubhash2redeem_script(self,pubkey): raise NotImplementedError + def pubhash2segwitaddr(self,pubkey): raise NotImplementedError class testnet(mainnet): addr_ver_bytes = { '6f': 'p2pkh', 'c4': 'p2sh' } diff --git a/mmgen/proto/btc.py b/mmgen/proto/btc.py index 1f1ff79c..e370a578 100755 --- a/mmgen/proto/btc.py +++ b/mmgen/proto/btc.py @@ -105,15 +105,15 @@ class mainnet(CoinProtocol.Secp256k1): # chainparams.cpp ) # Segwit: - def pubkey2redeem_script(self,pubkey): + def pubhash2redeem_script(self,pubhash): # https://bitcoincore.org/en/segwit_wallet_dev/ # The P2SH redeemScript is always 22 bytes. It starts with a OP_0, followed # by a canonical push of the keyhash (i.e. 0x0014{20-byte keyhash}) - return bytes.fromhex(self.witness_vernum_hex + '14') + hash160(pubkey) + return bytes.fromhex(self.witness_vernum_hex + '14') + pubhash - def pubkey2segwitaddr(self,pubkey): + def pubhash2segwitaddr(self,pubhash): return self.pubhash2addr( - hash160( self.pubkey2redeem_script(pubkey) ), + hash160( self.pubhash2redeem_script(pubhash) ), p2sh = True ) def pubhash2bech32addr(self,pubhash): diff --git a/mmgen/tool/coin.py b/mmgen/tool/coin.py index 6f8c259a..48f3d039 100755 --- a/mmgen/tool/coin.py +++ b/mmgen/tool/coin.py @@ -132,14 +132,15 @@ class tool_cmd(tool_cmd_base): pubkey = bytes.fromhex(pubkeyhex) from ..proto.common import hash160 if self.mmtype.name == 'segwit': - return self.proto.pubkey2segwitaddr( pubkey ) + return self.proto.pubhash2segwitaddr( hash160(pubkey) ) else: return self.pubhash2addr( hash160(pubkey).hex() ) def pubhex2redeem_script(self,pubkeyhex:'sstr'): # new "convert a hex pubkey to a Segwit P2SH-P2WPKH redeem script" assert self.mmtype.name == 'segwit','This command is meaningful only for --type=segwit' - return self.proto.pubkey2redeem_script( bytes.fromhex(pubkeyhex) ).hex() + from ..proto.common import hash160 + return self.proto.pubhash2redeem_script( hash160(bytes.fromhex(pubkeyhex)) ).hex() def redeem_script2addr(self,redeem_scripthex:'sstr'): # new "convert a Segwit P2SH-P2WPKH redeem script to an address"