Only store pubkey-private key pairs

This commit is contained in:
hackrush 2019-05-20 12:59:48 +05:30 committed by Lex Berezhny
parent 56edf62cb9
commit e45c6fe42c
3 changed files with 4 additions and 16 deletions

View file

@ -1903,7 +1903,7 @@ class Daemon(metaclass=JSONRPCServerType):
channel_pubkey_hash = account.ledger.public_key_to_address(
txo.claim.channel.public_key_bytes
)
account.add_channel_private_key(txo.claim_name, channel_pubkey_hash, txo.id, txo.private_key)
account.add_channel_private_key(txo.claim_name, channel_pubkey_hash, txo.private_key)
self.default_wallet.save()
await self.storage.save_claims([self._old_get_temp_claim_info(
tx, txo, claim_address, claim, name, dewies_to_lbc(amount)
@ -2044,7 +2044,7 @@ class Daemon(metaclass=JSONRPCServerType):
channel_pubkey_hash = account.ledger.public_key_to_address(
new_txo.claim.channel.public_key_bytes
)
account.add_channel_private_key(new_txo.claim_name, channel_pubkey_hash, new_txo.id, new_txo.private_key)
account.add_channel_private_key(new_txo.claim_name, channel_pubkey_hash, new_txo.private_key)
self.default_wallet.save()
await self.storage.save_claims([self._old_get_temp_claim_info(
tx, new_txo, claim_address, new_txo.claim, new_txo.claim_name, dewies_to_lbc(amount)

View file

@ -38,9 +38,7 @@ class Account(BaseAccount):
super().apply(d)
self.channel_keys.update(d.get('certificates', {}))
def add_channel_private_key(self, channel_name, channel_pubkey_hash, ref_id, private_key):
assert ref_id not in self.channel_keys, 'Trying to add a duplicate channel private key.'
self.channel_keys[ref_id] = private_key
def add_channel_private_key(self, channel_name, channel_pubkey_hash, private_key):
if channel_pubkey_hash not in self.channel_keys:
self.channel_keys[channel_pubkey_hash] = private_key
else:
@ -53,10 +51,8 @@ class Account(BaseAccount):
if not self.channel_keys:
return
addresses = {}
results = {
'total': 0,
'old-tx-pri-key-map': 0,
'migrate-success': 0,
'migrate-failed': 0,
'previous-success': 0,
@ -68,7 +64,6 @@ class Account(BaseAccount):
for maybe_outpoint in self.channel_keys:
results['total'] += 1
if ':' in maybe_outpoint:
results['old-tx-pri-key-map'] += 1
try:
private_key_pem = self.channel_keys[maybe_outpoint]
pubkey_hash = self._get_pubkey_address_from_private_key_pem(private_key_pem)
@ -91,18 +86,13 @@ class Account(BaseAccount):
log.warning("Corrupt public:private key-pair: %s", str(e))
results['previous-corrupted'] += 1
self.channel_keys.clear()
for key in new_channel_keys:
self.channel_keys[key] = new_channel_keys[key]
self.wallet.save()
log.info('verifying and possibly migrating certificates:')
log.info(json.dumps(results, indent=2))
if addresses:
log.warning('failed for addresses:')
log.warning(json.dumps(
[{'address': a, 'number of certificates': c} for a, c in addresses.items()],
indent=2
))
async def save_max_gap(self):
if issubclass(self.address_generator, HierarchicalDeterministic):

View file

@ -299,8 +299,6 @@ class ChannelCommands(CommandTestCase):
self.assertIsNone(txo.private_key)
# send the private key too
txoid = f"{tx['outputs'][0]['txid']}:{tx['outputs'][0]['nout']}"
account2.channel_keys[txoid] = self.account.channel_keys[txoid]
channel_pubkey_address_hash = self.account.ledger.public_key_to_address(unhexlify(channel['public_key']))
account2.channel_keys[channel_pubkey_address_hash] = self.account.channel_keys[channel_pubkey_address_hash]