def address_for_pay_to_script_wit(script, netcode=None): if netcode is None: netcode = get_current_netcode() bech32_hrp = bech32_hrp_for_netcode(netcode) address = segwit_addr.encode(bech32_hrp, 0, iterbytes(hashlib.sha256(script).digest())) return address
def from_bytes(bytes, byteorder="big", signed=False): if byteorder != "big": bytes = reversed(bytes) v = 0 for c in iterbytes(bytes): v <<= 8 v += c if signed and byte2int(bytes) & 0x80: v = v - (1 << (8 * len(bytes))) return v
def address_f(netcode=netcode): from pycoin.networks import bech32_hrp_for_netcode from pycoin.networks.default import get_current_netcode if netcode is None: netcode = get_current_netcode() bech32_hrp = bech32_hrp_for_netcode(netcode) if bech32_hrp: return segwit_addr.encode(bech32_hrp, self.version, iterbytes(self.hash160)) return None
def from_bytes(bytes, byteorder="big", signed=False): "See int.from_bytes in python 3" if byteorder != "big": bytes = reversed(bytes) v = 0 for c in iterbytes(bytes): v <<= 8 v += c if signed and byte2int(bytes) & 0x80: v = v - (1 << (8*len(bytes))) return v
def from_bytes(bytes, byteorder="big", signed=False): """This is the same functionality as ``int.from_bytes`` in python 3""" if byteorder != "big": bytes = reversed(bytes) v = 0 for c in iterbytes(bytes): v <<= 8 v += c if signed and byte2int(bytes) & 0x80: v = v - (1 << (8*len(bytes))) return v
def ip_bin_to_ip4_addr(ip_bin): return "%d.%d.%d.%d" % tuple(iterbytes(ip_bin[-4:]))
def do_test(as_int, prefix, as_rep, base): self.assertEqual((as_int, prefix), to_long(base, lambda v: v, iterbytes(as_rep))) self.assertEqual(as_rep, from_long(as_int, prefix, base, lambda v: v))
def ip_bin_to_ip4_addr(ip_bin): return "%d.%d.%d.%d" % tuple(iterbytes(ip_bin[-4:]))
def for_p2sh_wit(self, hash256): assert len(hash256) == 32 return segwit_addr.encode(bech32_hrp, 0, iterbytes(hash256))
def do_test(as_int, prefix, as_rep, base): self.assertEqual((as_int, prefix), to_long(base, lambda v: v, iterbytes(as_rep))) self.assertEqual(as_rep, from_long(as_int, prefix, base, lambda v: v))
def address_for_p2sh_wit(self, hash256): if self._bech32_hrp and len(hash256) == 32: return segwit_addr.encode(self._bech32_hrp, 0, iterbytes(hash256)) return "???"
def address_for_p2pkh_wit(self, h160): if self._bech32_hrp and len(h160) == 20: return segwit_addr.encode(self._bech32_hrp, 0, iterbytes(h160)) return "???"
def address_for_p2sh_wit(self, hash256): if self._bech32_hrp and len(hash256) == 32: return segwit_addr.encode(self._bech32_hrp, 0, iterbytes(hash256)) return "???"
def address_for_p2pkh_wit(self, h160): if self._bech32_hrp and len(h160) == 20: return segwit_addr.encode(self._bech32_hrp, 0, iterbytes(h160)) return "???"
def adaptor(nonce32_p, msg32_p, key32_p, algo16_p, data, attempt): nonce32_p.contents[:] = list(iterbytes(k_as_bytes)) return 1
def b2a_base58(s): """Convert binary to base58 using BASE58_ALPHABET. Like Bitcoin addresses.""" v, prefix = to_long(256, lambda x: x, iterbytes(s)) s = from_long(v, prefix, BASE58_BASE, lambda v: BASE58_ALPHABET[v]) return s.decode("utf8")
def adaptor(nonce32_p, msg32_p, key32_p, algo16_p, data, attempt): nonce32_p.contents[:] = list(iterbytes(k_as_bytes)) return 1
def for_p2pkh_wit(self, h160): assert len(h160) == 20 return segwit_addr.encode(bech32_hrp, 0, iterbytes(h160))
def for_p2sh_wit(self, hash256): assert len(hash256) == 32 return segwit_addr.encode(bech32_hrp, 0, iterbytes(hash256))
def for_p2pkh_wit(self, h160): assert len(h160) == 20 return segwit_addr.encode(bech32_hrp, 0, iterbytes(h160))