From 45799bf330b2df379ab4c076a34cd98b2f791e5e Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Sat, 5 Mar 2022 16:41:46 -0500 Subject: [PATCH] remove imports to lbry.wallet.server --- lbry/extras/daemon/daemon.py | 26 +++++++++++++-- lbry/schema/result.py | 32 ++++++++++++++++--- tests/integration/blockchain/test_network.py | 2 +- .../blockchain/test_wallet_server_sessions.py | 2 +- .../integration/claims/test_claim_commands.py | 11 ++++++- 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index 003ea9cf7..1240eb407 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -53,8 +53,7 @@ from lbry.extras.daemon.security import ensure_request_allowed from lbry.file_analysis import VideoFileAnalyzer from lbry.schema.claim import Claim from lbry.schema.url import URL, normalize_name -from lbry.wallet.server.db.elasticsearch.constants import RANGE_FIELDS, REPLACEMENTS -MY_RANGE_FIELDS = RANGE_FIELDS - {"limit_claims_per_channel"} + if typing.TYPE_CHECKING: from lbry.blob.blob_manager import BlobManager @@ -67,6 +66,29 @@ if typing.TYPE_CHECKING: log = logging.getLogger(__name__) +RANGE_FIELDS = { + 'height', 'creation_height', 'activation_height', 'expiration_height', + 'timestamp', 'creation_timestamp', 'duration', 'release_time', 'fee_amount', + 'tx_position', 'repost_count', 'limit_claims_per_channel', + 'amount', 'effective_amount', 'support_amount', + 'trending_score', 'censor_type', 'tx_num' +} +MY_RANGE_FIELDS = RANGE_FIELDS - {"limit_claims_per_channel"} +REPLACEMENTS = { + 'claim_name': 'normalized_name', + 'name': 'normalized_name', + 'txid': 'tx_id', + 'nout': 'tx_nout', + 'trending_group': 'trending_score', + 'trending_mixed': 'trending_score', + 'trending_global': 'trending_score', + 'trending_local': 'trending_score', + 'reposted': 'repost_count', + 'stream_types': 'stream_type', + 'media_types': 'media_type', + 'valid_channel_signature': 'is_signature_valid' +} + def is_transactional_function(name): for action in ('create', 'update', 'abandon', 'send', 'fund'): diff --git a/lbry/schema/result.py b/lbry/schema/result.py index 991b608a0..399aeabdf 100644 --- a/lbry/schema/result.py +++ b/lbry/schema/result.py @@ -1,13 +1,11 @@ import base64 -from typing import List, TYPE_CHECKING, Union, Optional +from typing import List, Union, Optional, NamedTuple from binascii import hexlify from itertools import chain from lbry.error import ResolveCensoredError from lbry.schema.types.v2.result_pb2 import Outputs as OutputsMessage from lbry.schema.types.v2.result_pb2 import Error as ErrorMessage -if TYPE_CHECKING: - from lbry.wallet.server.db.common import ResolveResult INVALID = ErrorMessage.Code.Name(ErrorMessage.INVALID) NOT_FOUND = ErrorMessage.Code.Name(ErrorMessage.NOT_FOUND) @@ -58,6 +56,32 @@ class Censor: outputs.blocked_total += len(count) +class ResolveResult(NamedTuple): # a named tuple returned by the database containing all the resolve fields + name: str + normalized_name: str + claim_hash: bytes + tx_num: int + position: int + tx_hash: bytes + height: int + amount: int + short_url: str + is_controlling: bool + canonical_url: str + creation_height: int + activation_height: int + expiration_height: int + effective_amount: int + support_amount: int + reposted: int + last_takeover_height: Optional[int] + claims_in_channel: Optional[int] + channel_hash: Optional[bytes] + reposted_claim_hash: Optional[bytes] + signature_valid: Optional[bool] + + + class Outputs: __slots__ = 'txos', 'extra_txos', 'txs', 'offset', 'total', 'blocked', 'blocked_total' @@ -202,7 +226,7 @@ class Outputs: return page.SerializeToString() @classmethod - def encode_txo(cls, txo_message, resolve_result: Union['ResolveResult', Exception]): + def encode_txo(cls, txo_message, resolve_result: Union[ResolveResult, Exception]): if isinstance(resolve_result, Exception): txo_message.error.text = resolve_result.args[0] if isinstance(resolve_result, ValueError): diff --git a/tests/integration/blockchain/test_network.py b/tests/integration/blockchain/test_network.py index 2a88e9dad..26dd4c3dc 100644 --- a/tests/integration/blockchain/test_network.py +++ b/tests/integration/blockchain/test_network.py @@ -50,7 +50,7 @@ class NetworkTests(IntegrationTestCase): self.conductor.spv_node.server.env.description = 'Fastest server in the west.' self.conductor.spv_node.server.env.daily_fee = '42' - from lbry.wallet.server.session import LBRYElectrumX + from scribe.server.session import LBRYElectrumX LBRYElectrumX.set_server_features(self.conductor.spv_node.server.env) # await self.ledger.network.on_connected.first diff --git a/tests/integration/blockchain/test_wallet_server_sessions.py b/tests/integration/blockchain/test_wallet_server_sessions.py index 43ac0326f..ba56dff22 100644 --- a/tests/integration/blockchain/test_wallet_server_sessions.py +++ b/tests/integration/blockchain/test_wallet_server_sessions.py @@ -5,7 +5,7 @@ import lbry.wallet from lbry.error import ServerPaymentFeeAboveMaxAllowedError from lbry.wallet.network import ClientSession from lbry.wallet.rpc import RPCError -from lbry.wallet.server.session import LBRYElectrumX +from scribe.server.session import LBRYElectrumX from lbry.testcase import IntegrationTestCase, CommandTestCase from lbry.wallet.orchstr8.node import SPVNode diff --git a/tests/integration/claims/test_claim_commands.py b/tests/integration/claims/test_claim_commands.py index 38a990bd6..58015d2d7 100644 --- a/tests/integration/claims/test_claim_commands.py +++ b/tests/integration/claims/test_claim_commands.py @@ -12,7 +12,6 @@ from lbry.error import InsufficientFundsError from lbry.extras.daemon.daemon import DEFAULT_PAGE_SIZE from lbry.testcase import CommandTestCase from lbry.wallet.orchstr8.node import SPVNode -from lbry.wallet.server.db.common import STREAM_TYPES from lbry.wallet.transaction import Transaction, Output from lbry.wallet.util import satoshis_to_coins as lbc from lbry.crypto.hash import sha256 @@ -20,6 +19,16 @@ from lbry.crypto.hash import sha256 log = logging.getLogger(__name__) +STREAM_TYPES = { + 'video': 1, + 'audio': 2, + 'image': 3, + 'document': 4, + 'binary': 5, + 'model': 6, +} + + def verify(channel, data, signature, channel_hash=None): pieces = [ signature['signing_ts'].encode(),