Skip to content

Commit

Permalink
Update tests and code
Browse files Browse the repository at this point in the history
  • Loading branch information
hackrush committed May 23, 2019
1 parent 5542e97 commit e84b180
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lbrynet/extras/daemon/Daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions lbrynet/wallet/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
return self.ledger.public_key_to_address(public_key_der)
4 changes: 3 additions & 1 deletion tests/integration/test_claim_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit e84b180

Please sign in to comment.