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) \ + rev_hex(res.get('nonce')) return s
def parse_xpubkey(cls, pubkey): assert is_extended_pubkey(pubkey) pk = pubkey.decode('hex') pk = pk[1:] xkey = EncodeBase58Check(pk[0:78]) dd = pk[78:] s = [] while dd: n = int(rev_hex(dd[0:2].encode('hex')), 16) dd = dd[2:] s.append(n) assert len(s) == 2 return xkey, s
def get_name_claims(self, domain=None, include_abandoned=True, include_supports=True, exclude_expired=True): claims = [] if domain is None: domain = self.get_addresses() if self.use_change: domain += self.get_addresses(True) for addr in domain: txos, txis = self.get_addr_io(addr) for txo, v in txos.items(): tx_height, value, is_cb = v prevout_hash, prevout_n = txo.split(':') tx = self.tx_transactions.get(prevout_hash) tx.deserialize() txout = tx.outputs()[int(prevout_n)] if not include_abandoned and txo in txis: continue if not include_supports and txout[0] & TYPE_SUPPORT: continue if txout[0] & (TYPE_CLAIM | TYPE_UPDATE | TYPE_SUPPORT): local_height = self.get_local_height() expired = tx_height + EXPIRATION_BLOCKS <= local_height if expired and exclude_expired: continue output = { 'txid': prevout_hash, 'nout': int(prevout_n), 'address': addr, 'amount': Decimal(value), 'height': tx_height, 'expiration_height': tx_height + EXPIRATION_BLOCKS, 'expired': expired, 'confirmations': local_height - tx_height, 'is_spent': txo in txis, } if tx_height: output['height'] = tx_height output[ 'expiration_height'] = tx_height + EXPIRATION_BLOCKS output['expired'] = expired output['confirmations'] = local_height - tx_height output['is_pending'] = False else: output['height'] = None output['expiration_height'] = None output['expired'] = expired output['confirmations'] = None output['is_pending'] = True if txout[0] & TYPE_CLAIM: output['category'] = 'claim' claim_name, claim_value = txout[1][0] output['name'] = claim_name output['value'] = claim_value.encode('hex') claim_id = claim_id_hash( rev_hex(output['txid']).decode('hex'), output['nout']) claim_id = encode_claim_id_hex(claim_id) output['claim_id'] = claim_id elif txout[0] & TYPE_SUPPORT: output['category'] = 'support' claim_name, claim_id = txout[1][0] output['name'] = claim_name output['claim_id'] = encode_claim_id_hex(claim_id) elif txout[0] & TYPE_UPDATE: output['category'] = 'update' claim_name, claim_id, claim_value = txout[1][0] output['name'] = claim_name output['value'] = claim_value.encode('hex') output['claim_id'] = encode_claim_id_hex(claim_id) if not expired: output[ 'blocks_to_expiration'] = tx_height + EXPIRATION_BLOCKS - local_height claims.append(output) return claims
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 encode_claim_id_hex(claim_id): return rev_hex(claim_id.encode('hex'))
def decode_claim_id_hex(claim_id_hex): return rev_hex(claim_id_hex).decode('hex')