Skip to content

Commit

Permalink
Merge 070e35b into 5a0c225
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba committed Mar 28, 2022
2 parents 5a0c225 + 070e35b commit a537b7c
Show file tree
Hide file tree
Showing 21 changed files with 163 additions and 548 deletions.
22 changes: 11 additions & 11 deletions lbry/extras/daemon/daemon.py
Expand Up @@ -8,6 +8,7 @@
import inspect
import typing
import random
import hashlib
import tracemalloc
from decimal import Decimal
from urllib.parse import urlencode, quote
Expand All @@ -16,6 +17,7 @@
from traceback import format_exc
from functools import wraps, partial

import ecdsa
import base58
from aiohttp import web
from prometheus_client import generate_latest as prom_generate_latest, Gauge, Histogram, Counter
Expand All @@ -27,7 +29,6 @@
)
from lbry.wallet.dewies import dewies_to_lbc, lbc_to_dewies, dict_values_to_lbc
from lbry.wallet.constants import TXO_TYPES, CLAIM_TYPE_NAMES
from lbry.wallet.bip32 import PrivateKey

from lbry import utils
from lbry.conf import Config, Setting, NOT_SET
Expand Down Expand Up @@ -2728,13 +2729,12 @@ async def jsonrpc_channel_create(
name, claim, amount, claim_address, funding_accounts, funding_accounts[0]
)
txo = tx.outputs[0]
txo.set_channel_private_key(
await funding_accounts[0].generate_channel_private_key()
)
await txo.generate_channel_private_key()

await tx.sign(funding_accounts)

if not preview:
account.add_channel_private_key(txo.private_key)
wallet.save()
await self.broadcast_or_release(tx, blocking)
self.component_manager.loop.create_task(self.storage.save_claims([self._old_get_temp_claim_info(
Expand Down Expand Up @@ -2883,9 +2883,7 @@ async def jsonrpc_channel_update(
new_txo = tx.outputs[0]

if new_signing_key:
new_txo.set_channel_private_key(
await funding_accounts[0].generate_channel_private_key()
)
await new_txo.generate_channel_private_key()
else:
new_txo.private_key = old_txo.private_key

Expand All @@ -2894,6 +2892,7 @@ async def jsonrpc_channel_update(
await tx.sign(funding_accounts)

if not preview:
account.add_channel_private_key(new_txo.private_key)
wallet.save()
await self.broadcast_or_release(tx, blocking)
self.component_manager.loop.create_task(self.storage.save_claims([self._old_get_temp_claim_info(
Expand Down Expand Up @@ -3065,7 +3064,7 @@ async def jsonrpc_channel_export(self, channel_id=None, channel_name=None, accou
'channel_id': channel.claim_id,
'holding_address': address,
'holding_public_key': public_key.extended_key_string(),
'signing_private_key': channel.private_key.signing_key.to_pem().decode()
'signing_private_key': channel.private_key.to_pem().decode()
}
return base58.b58encode(json.dumps(export, separators=(',', ':')))

Expand All @@ -3088,14 +3087,15 @@ async def jsonrpc_channel_import(self, channel_data, wallet_id=None):

decoded = base58.b58decode(channel_data)
data = json.loads(decoded)
channel_private_key = PrivateKey.from_pem(
self.ledger, data['signing_private_key']
channel_private_key = ecdsa.SigningKey.from_pem(
data['signing_private_key'], hashfunc=hashlib.sha256
)
public_key_der = channel_private_key.get_verifying_key().to_der()

# check that the holding_address hasn't changed since the export was made
holding_address = data['holding_address']
channels, _, _, _ = await self.ledger.claim_search(
wallet.accounts, public_key_id=channel_private_key.address
wallet.accounts, public_key_id=self.ledger.public_key_to_address(public_key_der)
)
if channels and channels[0].get_address(self.ledger) != holding_address:
holding_address = channels[0].get_address(self.ledger)
Expand Down
4 changes: 2 additions & 2 deletions lbry/extras/daemon/json_response_encoder.py
Expand Up @@ -10,7 +10,7 @@
from lbry.schema.support import Support
from lbry.torrent.torrent_manager import TorrentSource
from lbry.wallet import Wallet, Ledger, Account, Transaction, Output
from lbry.wallet.bip32 import PublicKey
from lbry.wallet.bip32 import PubKey
from lbry.wallet.dewies import dewies_to_lbc
from lbry.stream.managed_stream import ManagedStream

Expand Down Expand Up @@ -138,7 +138,7 @@ def default(self, obj): # pylint: disable=method-hidden,arguments-renamed,too-m
return self.encode_claim(obj)
if isinstance(obj, Support):
return obj.to_dict()
if isinstance(obj, PublicKey):
if isinstance(obj, PubKey):
return obj.extended_key_string()
if isinstance(obj, datetime):
return obj.strftime("%Y%m%dT%H:%M:%S")
Expand Down
11 changes: 2 additions & 9 deletions lbry/schema/claim.py
Expand Up @@ -2,9 +2,6 @@
from typing import List
from binascii import hexlify, unhexlify

from asn1crypto.keys import PublicKeyInfo
from coincurve import PublicKey as cPublicKey

from google.protobuf.json_format import MessageToDict
from google.protobuf.message import DecodeError
from hachoir.core.log import log as hachoir_log
Expand Down Expand Up @@ -349,19 +346,15 @@ def to_dict(self):

@property
def public_key(self) -> str:
return hexlify(self.public_key_bytes).decode()
return hexlify(self.message.public_key).decode()

@public_key.setter
def public_key(self, sd_public_key: str):
self.message.public_key = unhexlify(sd_public_key.encode())

@property
def public_key_bytes(self) -> bytes:
if len(self.message.public_key) == 33:
return self.message.public_key
public_key_info = PublicKeyInfo.load(self.message.public_key)
public_key = cPublicKey(public_key_info.native['public_key'])
return public_key.format(compressed=True)
return self.message.public_key

@public_key_bytes.setter
def public_key_bytes(self, public_key: bytes):
Expand Down
15 changes: 0 additions & 15 deletions lbry/testcase.py
Expand Up @@ -17,10 +17,8 @@
from lbry.wallet import WalletManager, Wallet, Ledger, Account, Transaction
from lbry.conf import Config
from lbry.wallet.util import satoshis_to_coins
from lbry.wallet.dewies import lbc_to_dewies
from lbry.wallet.orchstr8 import Conductor
from lbry.wallet.orchstr8.node import LBCWalletNode, WalletNode, HubNode
from lbry.schema.claim import Claim

from lbry.extras.daemon.daemon import Daemon, jsonrpc_dumps_pretty
from lbry.extras.daemon.components import Component, WalletComponent
Expand Down Expand Up @@ -559,19 +557,6 @@ async def confirm_and_render(self, awaitable, confirm, return_tx=False) -> Trans
return self.sout(tx)
return tx

async def create_nondeterministic_channel(self, name, price, pubkey_bytes, daemon=None, blocking=False):
account = (daemon or self.daemon).wallet_manager.default_account
claim_address = await account.receiving.get_or_create_usable_address()
claim = Claim()
claim.channel.public_key_bytes = pubkey_bytes
tx = await Transaction.claim_create(
name, claim, lbc_to_dewies(price),
claim_address, [self.account], self.account
)
await tx.sign([self.account])
await (daemon or self.daemon).broadcast_or_release(tx, blocking)
return self.sout(tx)

def create_upload_file(self, data, prefix=None, suffix=None):
file_path = tempfile.mktemp(prefix=prefix or "tmp", suffix=suffix or "", dir=self.daemon.conf.upload_dir)
with open(file_path, 'w+b') as file:
Expand Down
3 changes: 1 addition & 2 deletions lbry/wallet/__init__.py
Expand Up @@ -15,8 +15,7 @@
from lbry.wallet.manager import WalletManager
from lbry.wallet.network import Network
from lbry.wallet.ledger import Ledger, RegTestLedger, TestNetLedger, BlockHeightEvent
from lbry.wallet.account import Account, AddressManager, SingleKey, HierarchicalDeterministic, \
DeterministicChannelKeyManager
from lbry.wallet.account import Account, AddressManager, SingleKey, HierarchicalDeterministic
from lbry.wallet.transaction import Transaction, Output, Input
from lbry.wallet.script import OutputScript, InputScript
from lbry.wallet.database import SQLiteMixin, Database
Expand Down

0 comments on commit a537b7c

Please sign in to comment.