Пример #1
0
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
Пример #2
0
 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
Пример #4
0
 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
Пример #5
0
 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
Пример #6
0
def ip_bin_to_ip4_addr(ip_bin):
    return "%d.%d.%d.%d" % tuple(iterbytes(ip_bin[-4:]))
Пример #7
0
 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))
Пример #8
0
def ip_bin_to_ip4_addr(ip_bin):
    return "%d.%d.%d.%d" % tuple(iterbytes(ip_bin[-4:]))
Пример #9
0
 def for_p2sh_wit(self, hash256):
     assert len(hash256) == 32
     return segwit_addr.encode(bech32_hrp, 0, iterbytes(hash256))
Пример #10
0
 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))
Пример #11
0
 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 "???"
Пример #12
0
 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 "???"
Пример #13
0
 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 "???"
Пример #14
0
 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 "???"
Пример #15
0
 def adaptor(nonce32_p, msg32_p, key32_p, algo16_p, data, attempt):
     nonce32_p.contents[:] = list(iterbytes(k_as_bytes))
     return 1
Пример #16
0
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")
Пример #17
0
 def adaptor(nonce32_p, msg32_p, key32_p, algo16_p, data, attempt):
     nonce32_p.contents[:] = list(iterbytes(k_as_bytes))
     return 1
Пример #18
0
 def for_p2pkh_wit(self, h160):
     assert len(h160) == 20
     return segwit_addr.encode(bech32_hrp, 0, iterbytes(h160))
Пример #19
0
 def for_p2sh_wit(self, hash256):
     assert len(hash256) == 32
     return segwit_addr.encode(bech32_hrp, 0, iterbytes(hash256))
Пример #20
0
 def for_p2pkh_wit(self, h160):
     assert len(h160) == 20
     return segwit_addr.encode(bech32_hrp, 0, iterbytes(h160))