def create_push_script(datums): # datums can be ints or strs res = [] for datum in datums: if isinstance(datum, (int, long)): if datum == -1 or 1 <= datum <= 16: res.append(chr(datum + 80)) continue negative = datum < 0 datum = math.natural_to_string(abs(datum)) if datum and ord(datum[0]) & 128: datum = '\x00' + datum if negative: datum = chr(ord(datum[0]) + 128) + datum[1:] datum = datum[::-1] if len(datum) < 76: res.append(chr(len(datum))) elif len(datum) <= 0xff: res.append(76) res.append(chr(len(datum))) elif len(datum) <= 0xffff: res.append(77) res.append(pack.IntType(16).pack(len(datum))) elif len(datum) <= 0xffffffff: res.append(78) res.append(pack.IntType(32).pack(len(datum))) else: raise ValueError('string too long') res.append(datum) return ''.join(res)
def from_target_upper_bound(cls, target): n = math.natural_to_string(target) if n and ord(n[0]) >= 128: n = '\x00' + n bits2 = (chr(len(n)) + (n + 3*chr(0))[:3])[::-1] bits = pack.IntType(32).unpack(bits2) return cls(bits)
def from_target_upper_bound(cls, target): n = math.natural_to_string(target) if n and ord(n[0]) >= 128: n = '\x00' + n bits2 = (chr(len(n)) + (n + 3 * chr(0))[:3])[::-1] bits = pack.IntType(32).unpack(bits2) return cls(bits)
def base58_decode(b58data): b58data2 = b58data.lstrip(base58_alphabet[0]) return chr(0) * (len(b58data) - len(b58data2)) + math.natural_to_string( math.string_to_natural(b58data2, base58_alphabet))
def base58_encode(bindata): bindata2 = bindata.lstrip(chr(0)) return base58_alphabet[0] * ( len(bindata) - len(bindata2)) + math.natural_to_string( math.string_to_natural(bindata2), base58_alphabet)
def base58_decode(b58data): b58data2 = b58data.lstrip(base58_alphabet[0]) return chr(0)*(len(b58data) - len(b58data2)) + math.natural_to_string(math.string_to_natural(b58data2, base58_alphabet))
def base58_encode(bindata): bindata2 = bindata.lstrip(chr(0)) return base58_alphabet[0]*(len(bindata) - len(bindata2)) + math.natural_to_string(math.string_to_natural(bindata2), base58_alphabet)