def op_push(i): if i < 0x4c: return int_to_hex(i) elif i < 0xff: return '4c' + int_to_hex(i) elif i < 0xffff: return '4d' + int_to_hex(i, 2) else: return '4e' + int_to_hex(i, 4)
def serialize_header(self, res): s = int_to_hex(res.get('version'), 4) \ + rev_hex(self.get_block_hash(res)) \ + rev_hex(res.get('merkle_root')) \ + rev_hex(res.get('claim_trie_root')) \ + int_to_hex(int(res.get('timestamp')), 4) \ + int_to_hex(int(res.get('bits')), 4) \ + int_to_hex(int(res.get('nonce')), 4) return s
def get_xpubkeys(self, for_change, n): # unsorted s = ''.join(map(lambda x: int_to_hex(x, 2), (for_change, n))) xpubs = self.get_master_pubkeys() return map( lambda xpub: 'ff' + b58decode_strip_checksum(xpub).encode('hex') + s, xpubs)
def serialize(self, for_sig=None): inputs = self.inputs() outputs = self.outputs() s = int_to_hex(1, 4) # version s += var_int(len(inputs)) # number of inputs for i, txin in enumerate(inputs): s += self.serialize_input(txin, i, for_sig) s += var_int(len(outputs)) # number of outputs for output in outputs: output_type, addr, amount = output s += int_to_hex(amount, 8) # amount script = self.pay_script(output_type, addr) s += var_int(len(script) / 2) # script length s += script # script s += int_to_hex(0, 4) # lock time if for_sig is not None and for_sig != -1: s += int_to_hex(1, 4) # hash type return s
def serialize_input(cls, txin, i, for_sig): # Prev hash and index s = txin['prevout_hash'].decode('hex')[::-1].encode('hex') s += int_to_hex(txin['prevout_n'], 4) # Script length, script, sequence script = cls.input_script(txin, i, for_sig) s += var_int(len(script) / 2) s += script s += "ffffffff" return s
def CKD_pub(cK, c, n): if n & BIP32_PRIME: raise Exception("CKD pub error") return _CKD_pub(cK, c, rev_hex(int_to_hex(n, 4)).decode('hex'))
def CKD_priv(k, c, n): is_prime = n & BIP32_PRIME return _CKD_priv(k, c, rev_hex(int_to_hex(n, 4)).decode('hex'), is_prime)
def get_xpubkeys(self, for_change, n): # unsorted s = ''.join(map(lambda x: int_to_hex(x, 2), (for_change, n))) xpubs = self.get_master_pubkeys() return map(lambda xpub: 'ff' + b58decode_strip_checksum(xpub).encode('hex') + s, xpubs)