def test_serialize_privkey(self): for priv_details in self.priv_pub_addr: txin_type, privkey, compressed = deserialize_privkey( priv_details['priv']) priv2 = serialize_privkey(privkey, compressed, txin_type) if not priv_details['minikey']: self.assertEqual(priv_details['priv'], priv2)
def main(**kwargs): input_file = kwargs.pop('input_file') output_file = kwargs.pop('output_file', None) inplace = kwargs.pop('inplace', False) dry_run = kwargs.pop('dry_run', False) if inplace: output_file = input_file olines = [] total_sub = 0 for ln, l in enumerate(open(input_file, 'r').read().splitlines()): pos = 0 ol = '' while pos < len(l): m = ADDR_PATTERN.search(l, pos) if not m: ol += l[pos:] break ol += l[pos:m.start()] val = m.group() try: addrtype, h = b58_address_to_hash160_btc(val) except: h = None if h and addrtype == 0: new_val = hash160_to_b58_address(h, net.ADDRTYPE_P2PKH) total_sub += 1 elif h and addrtype == 5: new_val = hash160_to_b58_address(h, net.ADDRTYPE_P2SH) total_sub += 1 else: new_val = None if not new_val: try: txin_type, privkey, compressed = deserialize_btc_priv(val) except Exception as e: privkey = None if privkey: new_val = serialize_privkey(privkey, compressed, txin_type, internal_use=True) if dry_run and new_val: print('line %s, col %s: %s => %s' % (ln, m.start(), val, new_val)) ol += new_val if new_val else val pos = m.end() olines.append(ol) out = '\n'.join(olines) if not output_file: print(out) elif not dry_run: with open(output_file, 'w') as wfd: wfd.write('%s\n' % out) else: print('Total sub count:', total_sub)
def test_serialize_privkey(self): for priv_details in self.priv_pub_addr: txin_type, privkey, key_type = deserialize_privkey( priv_details['priv']) priv2 = serialize_privkey(privkey, key_type, txin_type) self.assertEqual(priv_details['exported_privkey'], priv2)
def test_serialize_privkey(self): for priv_details in self.priv_pub_addr: txin_type, privkey, compressed = deserialize_privkey(priv_details['priv']) priv2 = serialize_privkey(privkey, compressed, txin_type) self.assertEqual(priv_details['exported_privkey'], priv2)