rename bc_address functions
This commit is contained in:
parent
b9da5afa9d
commit
4d3e079778
|
@ -288,7 +288,7 @@ def hash_160(public_key):
|
|||
return md.digest()
|
||||
|
||||
|
||||
def hash_160_to_bc_address(h160, addrtype, witness_program_version=1):
|
||||
def hash160_to_b58_address(h160, addrtype, witness_program_version=1):
|
||||
s = bytes([addrtype])
|
||||
if addrtype == ADDRTYPE_P2WPKH:
|
||||
s += bytes([witness_program_version]) + b'\x00'
|
||||
|
@ -296,18 +296,18 @@ def hash_160_to_bc_address(h160, addrtype, witness_program_version=1):
|
|||
return base_encode(s+Hash(s)[0:4], base=58)
|
||||
|
||||
|
||||
def bc_address_to_hash_160(addr):
|
||||
def b58_address_to_hash160(addr):
|
||||
addr = to_bytes(addr, 'ascii')
|
||||
_bytes = base_decode(addr, 25, base=58)
|
||||
return _bytes[0], _bytes[1:21]
|
||||
|
||||
|
||||
def hash160_to_p2pkh(h160):
|
||||
return hash_160_to_bc_address(h160, ADDRTYPE_P2PKH)
|
||||
return hash160_to_b58_address(h160, ADDRTYPE_P2PKH)
|
||||
|
||||
|
||||
def hash160_to_p2sh(h160):
|
||||
return hash_160_to_bc_address(h160, ADDRTYPE_P2SH)
|
||||
return hash160_to_b58_address(h160, ADDRTYPE_P2SH)
|
||||
|
||||
|
||||
def public_key_to_p2pkh(public_key):
|
||||
|
@ -315,10 +315,10 @@ def public_key_to_p2pkh(public_key):
|
|||
|
||||
|
||||
def public_key_to_p2wpkh(public_key):
|
||||
return hash_160_to_bc_address(hash_160(public_key), ADDRTYPE_P2WPKH)
|
||||
return hash160_to_b58_address(hash_160(public_key), ADDRTYPE_P2WPKH)
|
||||
|
||||
def address_to_script(addr):
|
||||
addrtype, hash_160 = bc_address_to_hash_160(addr)
|
||||
addrtype, hash_160 = b58_address_to_hash160(addr)
|
||||
if addrtype == ADDRTYPE_P2PKH:
|
||||
script = '76a9' # op_dup, op_hash_160
|
||||
script += push_script(bh2u(hash_160))
|
||||
|
@ -478,21 +478,21 @@ def address_from_private_key(sec):
|
|||
|
||||
def is_address(addr):
|
||||
try:
|
||||
addrtype, h = bc_address_to_hash_160(addr)
|
||||
addrtype, h = b58_address_to_hash160(addr)
|
||||
except Exception as e:
|
||||
return False
|
||||
if addrtype not in [ADDRTYPE_P2PKH, ADDRTYPE_P2SH]:
|
||||
return False
|
||||
return addr == hash_160_to_bc_address(h, addrtype)
|
||||
return addr == hash160_to_b58_address(h, addrtype)
|
||||
|
||||
def is_p2pkh(addr):
|
||||
if is_address(addr):
|
||||
addrtype, h = bc_address_to_hash_160(addr)
|
||||
addrtype, h = b58_address_to_hash160(addr)
|
||||
return addrtype == ADDRTYPE_P2PKH
|
||||
|
||||
def is_p2sh(addr):
|
||||
if is_address(addr):
|
||||
addrtype, h = bc_address_to_hash_160(addr)
|
||||
addrtype, h = b58_address_to_hash160(addr)
|
||||
return addrtype == ADDRTYPE_P2SH
|
||||
|
||||
def is_private_key(key):
|
||||
|
|
|
@ -601,7 +601,7 @@ def xpubkey_to_address(x_pubkey):
|
|||
# TODO: check that ord() is OK here
|
||||
addrtype = ord(bfh(x_pubkey[2:4]))
|
||||
hash160 = bfh(x_pubkey[4:])
|
||||
address = bitcoin.hash_160_to_bc_address(hash160, addrtype)
|
||||
address = bitcoin.hash160_to_b58_address(hash160, addrtype)
|
||||
return x_pubkey, address
|
||||
if x_pubkey[0:2] in ['02', '03', '04']:
|
||||
pubkey = x_pubkey
|
||||
|
|
|
@ -1413,7 +1413,7 @@ class Imported_Wallet(Abstract_Wallet):
|
|||
return []
|
||||
|
||||
def add_input_sig_info(self, txin, address):
|
||||
addrtype, hash160 = bc_address_to_hash_160(address)
|
||||
addrtype, hash160 = b58_address_to_hash160(address)
|
||||
x_pubkey = 'fd' + bh2u(bytes([addrtype]) + hash160)
|
||||
txin['x_pubkeys'] = [x_pubkey]
|
||||
txin['signatures'] = [None]
|
||||
|
|
|
@ -6,7 +6,7 @@ from binascii import hexlify, unhexlify
|
|||
from functools import partial
|
||||
|
||||
from electrum.util import bfh, bh2u
|
||||
from electrum.bitcoin import (bc_address_to_hash_160, xpub_from_pubkey,
|
||||
from electrum.bitcoin import (b58_address_to_hash160, xpub_from_pubkey,
|
||||
public_key_to_p2pkh, EncodeBase58Check,
|
||||
TYPE_ADDRESS, TYPE_SCRIPT,
|
||||
TESTNET, ADDRTYPE_P2PKH, ADDRTYPE_P2SH)
|
||||
|
@ -334,7 +334,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||
info = tx.output_info.get(address)
|
||||
if info is not None and not has_change:
|
||||
has_change = True # no more than one change address
|
||||
addrtype, hash_160 = bc_address_to_hash_160(address)
|
||||
addrtype, hash_160 = b58_address_to_hash160(address)
|
||||
index, xpubs, m = info
|
||||
if len(xpubs) == 1:
|
||||
script_type = self.types.PAYTOP2SHWITNESS if segwit else self.types.PAYTOADDRESS
|
||||
|
@ -365,7 +365,7 @@ class TrezorCompatiblePlugin(HW_PluginBase):
|
|||
txoutputtype.script_type = self.types.PAYTOOPRETURN
|
||||
txoutputtype.op_return_data = address[2:]
|
||||
elif _type == TYPE_ADDRESS:
|
||||
addrtype, hash_160 = bc_address_to_hash_160(address)
|
||||
addrtype, hash_160 = b58_address_to_hash160(address)
|
||||
if addrtype == ADDRTYPE_P2PKH:
|
||||
txoutputtype.script_type = self.types.PAYTOADDRESS
|
||||
elif addrtype == ADDRTYPE_P2SH:
|
||||
|
|
Loading…
Reference in New Issue