From e84b180ad5e74a49e079b3ba09ada53ac2750080 Mon Sep 17 00:00:00 2001 From: hackrush Date: Mon, 20 May 2019 01:51:54 +0530 Subject: [PATCH] Update tests and code --- lbrynet/extras/daemon/Daemon.py | 4 ++-- lbrynet/wallet/account.py | 10 ++++++---- tests/integration/test_claim_commands.py | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index 1e74ae74b1..215e8e8734 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -1872,7 +1872,7 @@ async def jsonrpc_channel_create( channel_pubkey_hash = account.ledger.public_key_to_address( txo.claim.channel.public_key_bytes ) - account.add_channel_private_key(channel_pubkey_hash, txo.ref.id, txo.private_key) + account.add_channel_private_key(txo.claim_name, channel_pubkey_hash, txo.id, 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) @@ -2013,7 +2013,7 @@ async def jsonrpc_channel_update( channel_pubkey_hash = account.ledger.public_key_to_address( new_txo.claim.channel.public_key_bytes ) - account.add_channel_private_key(channel_pubkey_hash, new_txo.ref.id, new_txo.private_key) + account.add_channel_private_key(new_txo.claim_name, channel_pubkey_hash, new_txo.id, 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) diff --git a/lbrynet/wallet/account.py b/lbrynet/wallet/account.py index 1293b5de30..886de453b2 100644 --- a/lbrynet/wallet/account.py +++ b/lbrynet/wallet/account.py @@ -38,11 +38,13 @@ def apply(self, d: dict): super().apply(d) self.channel_keys.update(d.get('certificates', {})) - def add_channel_private_key(self, channel_pubkey_hash, ref_id, private_key): - assert channel_pubkey_hash not in self.channel_keys, 'Trying to add a duplicate channel private key.' + 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 - self.channel_keys[channel_pubkey_hash] = private_key + if channel_pubkey_hash not in self.channel_keys: + self.channel_keys[channel_pubkey_hash] = private_key + else: + log.info("Public-Private key mapping for the channel %s already exists. Skipping...", channel_name) def get_channel_private_key(self, channel_pubkey_hash): return self.channel_keys.get(channel_pubkey_hash) @@ -180,4 +182,4 @@ def _get_pubkey_address_from_private_key_pem(self, private_key_pem): private_key = ecdsa.SigningKey.from_pem(private_key_pem, hashfunc=hashlib.sha256) public_key_der = private_key.get_verifying_key().to_der() - return self.ledger.public_key_to_address(public_key_der) \ No newline at end of file + return self.ledger.public_key_to_address(public_key_der) diff --git a/tests/integration/test_claim_commands.py b/tests/integration/test_claim_commands.py index 2f74024d00..2bbd43c8fe 100644 --- a/tests/integration/test_claim_commands.py +++ b/tests/integration/test_claim_commands.py @@ -255,7 +255,7 @@ async def test_setting_channel_fields(self): fixed_values['public_key'] = channel['public_key'] self.assertEqual(channel, {'public_key': fixed_values['public_key'], 'featured': ['beef']}) - # update channel setting all fields + # update channel "@featurechannel" setting all fields tx = await self.out(self.channel_update(claim_id, **values)) channel = tx['outputs'][0]['value'] fixed_values['featured'].insert(0, 'beef') # existing featured claim @@ -301,6 +301,8 @@ async def test_setting_channel_fields(self): # 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] # now should have private key txo = (await account2.get_channels())[0]