diff --git a/lbry/schema/result.py b/lbry/schema/result.py index 73ab1ea6b..80a9181ac 100644 --- a/lbry/schema/result.py +++ b/lbry/schema/result.py @@ -150,6 +150,20 @@ class Outputs: outputs.blocked, outputs.blocked_total ) + @classmethod + def from_grpc(cls, outputs: OutputsMessage) -> 'Outputs': + print(outputs) + txs = set() + for txo_message in chain(outputs.txos, outputs.extra_txos): + if txo_message.WhichOneof('meta') == 'error': + continue + txs.add((hexlify(txo_message.tx_hash[::-1]).decode(), txo_message.height)) + return cls( + outputs.txos, outputs.extra_txos, txs, + outputs.offset, outputs.total, + outputs.blocked, outputs.blocked_total + ) + @classmethod def to_base64(cls, txo_rows, extra_txo_rows, offset=0, total=None, blocked=None) -> str: return base64.b64encode(cls.to_bytes(txo_rows, extra_txo_rows, offset, total, blocked)).decode() diff --git a/lbry/schema/types/v2/hub_pb2.py b/lbry/schema/types/v2/hub_pb2.py new file mode 100644 index 000000000..4068cb79f --- /dev/null +++ b/lbry/schema/types/v2/hub_pb2.py @@ -0,0 +1,696 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: hub.proto +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.protobuf import wrappers_pb2 as google_dot_protobuf_dot_wrappers__pb2 +import lbry.schema.types.v2.result_pb2 as result__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='hub.proto', + package='pb', + syntax='proto3', + serialized_options=b'Z$github.com/lbryio/hub/protobuf/go/pb', + create_key=_descriptor._internal_create_key, + serialized_pb=b'\n\thub.proto\x12\x02pb\x1a\x1egoogle/protobuf/wrappers.proto\x1a\x0cresult.proto\"0\n\x0fInvertibleField\x12\x0e\n\x06invert\x18\x01 \x01(\x08\x12\r\n\x05value\x18\x02 \x03(\t\"j\n\nRangeField\x12\x1d\n\x02op\x18\x01 \x01(\x0e\x32\x11.pb.RangeField.Op\x12\r\n\x05value\x18\x02 \x03(\t\".\n\x02Op\x12\x06\n\x02\x45Q\x10\x00\x12\x07\n\x03LTE\x10\x01\x12\x07\n\x03GTE\x10\x02\x12\x06\n\x02LT\x10\x03\x12\x06\n\x02GT\x10\x04\"\xc5\x0f\n\rSearchRequest\x12\x0c\n\x04text\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x03(\t\x12\x31\n\x0c\x61mount_order\x18\x03 \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x12*\n\x05limit\x18\x04 \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x12\x10\n\x08order_by\x18\x05 \x03(\t\x12+\n\x06offset\x18\x06 \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x12\x32\n\x0eis_controlling\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12\x1d\n\x15last_take_over_height\x18\x13 \x01(\t\x12%\n\x08\x63laim_id\x18\x14 \x01(\x0b\x32\x13.pb.InvertibleField\x12\x12\n\nclaim_name\x18\x16 \x03(\t\x12\x12\n\nnormalized\x18\x17 \x03(\t\x12#\n\x0btx_position\x18\x18 \x01(\x0b\x32\x0e.pb.RangeField\x12\x1e\n\x06\x61mount\x18\x19 \x01(\x0b\x32\x0e.pb.RangeField\x12!\n\ttimestamp\x18\x1a \x01(\x0b\x32\x0e.pb.RangeField\x12*\n\x12\x63reation_timestamp\x18\x1b \x01(\x0b\x32\x0e.pb.RangeField\x12\x1e\n\x06height\x18\x1c \x01(\x0b\x32\x0e.pb.RangeField\x12\'\n\x0f\x63reation_height\x18\x1d \x01(\x0b\x32\x0e.pb.RangeField\x12)\n\x11\x61\x63tivation_height\x18\x1e \x01(\x0b\x32\x0e.pb.RangeField\x12)\n\x11\x65xpiration_height\x18\x1f \x01(\x0b\x32\x0e.pb.RangeField\x12$\n\x0crelease_time\x18 \x01(\x0b\x32\x0e.pb.RangeField\x12\x11\n\tshort_url\x18! \x03(\t\x12\x15\n\rcanonical_url\x18\" \x03(\t\x12\r\n\x05title\x18# \x03(\t\x12\x0e\n\x06\x61uthor\x18$ \x03(\t\x12\x13\n\x0b\x64\x65scription\x18% \x03(\t\x12\x12\n\nclaim_type\x18& \x03(\t\x12 \n\x08reposted\x18\' \x01(\x0b\x32\x0e.pb.RangeField\x12\x13\n\x0bstream_type\x18( \x03(\t\x12\x12\n\nmedia_type\x18) \x03(\t\x12\"\n\nfee_amount\x18* \x01(\x0b\x32\x0e.pb.RangeField\x12\x14\n\x0c\x66\x65\x65_currency\x18+ \x03(\t\x12 \n\x08\x64uration\x18, \x01(\x0b\x32\x0e.pb.RangeField\x12\x1b\n\x13reposted_claim_hash\x18- \x01(\t\x12#\n\x0b\x63\x65nsor_type\x18. \x01(\x0b\x32\x0e.pb.RangeField\x12\x19\n\x11\x63laims_in_channel\x18/ \x01(\t\x12$\n\x0c\x63hannel_join\x18\x30 \x01(\x0b\x32\x0e.pb.RangeField\x12\x33\n\x0fsignature_valid\x18\x31 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12(\n\x10\x65\x66\x66\x65\x63tive_amount\x18\x33 \x01(\x0b\x32\x0e.pb.RangeField\x12&\n\x0esupport_amount\x18\x34 \x01(\x0b\x32\x0e.pb.RangeField\x12&\n\x0etrending_group\x18\x35 \x01(\x0b\x32\x0e.pb.RangeField\x12&\n\x0etrending_mixed\x18\x36 \x01(\x0b\x32\x0e.pb.RangeField\x12&\n\x0etrending_local\x18\x37 \x01(\x0b\x32\x0e.pb.RangeField\x12\'\n\x0ftrending_global\x18\x38 \x01(\x0b\x32\x0e.pb.RangeField\x12\'\n\nchannel_id\x18\x39 \x01(\x0b\x32\x13.pb.InvertibleField\x12(\n\x0b\x63hannel_ids\x18: \x01(\x0b\x32\x13.pb.InvertibleField\x12\r\n\x05tx_id\x18; \x03(\t\x12,\n\x07tx_nout\x18< \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x12\x11\n\tsignature\x18= \x03(\t\x12\x18\n\x10signature_digest\x18> \x03(\t\x12\x18\n\x10public_key_bytes\x18? \x03(\t\x12\x17\n\x0fpublic_key_hash\x18@ \x03(\t\x12\x15\n\rpublic_key_id\x18\x41 \x01(\t\x12\x0b\n\x03_id\x18\x42 \x03(\x0c\x12\x10\n\x08\x61ny_tags\x18\x43 \x03(\t\x12\x10\n\x08\x61ll_tags\x18\x44 \x03(\t\x12\x10\n\x08not_tags\x18\x45 \x03(\t\x12\x19\n\x11reposted_claim_id\x18\x46 \x03(\t\x12\x39\n\x15has_channel_signature\x18G \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12.\n\nhas_source\x18H \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12=\n\x18limit_claims_per_channel\x18I \x01(\x0b\x32\x1b.google.protobuf.Int32Value\x12\x15\n\rany_languages\x18J \x03(\t\x12\x15\n\rall_languages\x18K \x03(\t21\n\x03Hub\x12*\n\x06Search\x12\x11.pb.SearchRequest\x1a\x0b.pb.Outputs\"\x00\x42&Z$github.com/lbryio/hub/protobuf/go/pbb\x06proto3' + , + dependencies=[google_dot_protobuf_dot_wrappers__pb2.DESCRIPTOR,result__pb2.DESCRIPTOR,]) + + + +_RANGEFIELD_OP = _descriptor.EnumDescriptor( + name='Op', + full_name='pb.RangeField.Op', + filename=None, + file=DESCRIPTOR, + create_key=_descriptor._internal_create_key, + values=[ + _descriptor.EnumValueDescriptor( + name='EQ', index=0, number=0, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='LTE', index=1, number=1, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='GTE', index=2, number=2, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='LT', index=3, number=3, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='GT', index=4, number=4, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), + ], + containing_type=None, + serialized_options=None, + serialized_start=173, + serialized_end=219, +) +_sym_db.RegisterEnumDescriptor(_RANGEFIELD_OP) + + +_INVERTIBLEFIELD = _descriptor.Descriptor( + name='InvertibleField', + full_name='pb.InvertibleField', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='invert', full_name='pb.InvertibleField.invert', index=0, + number=1, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='value', full_name='pb.InvertibleField.value', index=1, + number=2, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=63, + serialized_end=111, +) + + +_RANGEFIELD = _descriptor.Descriptor( + name='RangeField', + full_name='pb.RangeField', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='op', full_name='pb.RangeField.op', index=0, + number=1, type=14, cpp_type=8, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='value', full_name='pb.RangeField.value', index=1, + number=2, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + _RANGEFIELD_OP, + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=113, + serialized_end=219, +) + + +_SEARCHREQUEST = _descriptor.Descriptor( + name='SearchRequest', + full_name='pb.SearchRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + create_key=_descriptor._internal_create_key, + fields=[ + _descriptor.FieldDescriptor( + name='text', full_name='pb.SearchRequest.text', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='name', full_name='pb.SearchRequest.name', index=1, + number=2, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='amount_order', full_name='pb.SearchRequest.amount_order', index=2, + number=3, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='limit', full_name='pb.SearchRequest.limit', index=3, + number=4, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='order_by', full_name='pb.SearchRequest.order_by', index=4, + number=5, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='offset', full_name='pb.SearchRequest.offset', index=5, + number=6, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='is_controlling', full_name='pb.SearchRequest.is_controlling', index=6, + number=7, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='last_take_over_height', full_name='pb.SearchRequest.last_take_over_height', index=7, + number=19, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='claim_id', full_name='pb.SearchRequest.claim_id', index=8, + number=20, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='claim_name', full_name='pb.SearchRequest.claim_name', index=9, + number=22, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='normalized', full_name='pb.SearchRequest.normalized', index=10, + number=23, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='tx_position', full_name='pb.SearchRequest.tx_position', index=11, + number=24, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='amount', full_name='pb.SearchRequest.amount', index=12, + number=25, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='timestamp', full_name='pb.SearchRequest.timestamp', index=13, + number=26, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='creation_timestamp', full_name='pb.SearchRequest.creation_timestamp', index=14, + number=27, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='height', full_name='pb.SearchRequest.height', index=15, + number=28, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='creation_height', full_name='pb.SearchRequest.creation_height', index=16, + number=29, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='activation_height', full_name='pb.SearchRequest.activation_height', index=17, + number=30, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='expiration_height', full_name='pb.SearchRequest.expiration_height', index=18, + number=31, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='release_time', full_name='pb.SearchRequest.release_time', index=19, + number=32, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='short_url', full_name='pb.SearchRequest.short_url', index=20, + number=33, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='canonical_url', full_name='pb.SearchRequest.canonical_url', index=21, + number=34, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='title', full_name='pb.SearchRequest.title', index=22, + number=35, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='author', full_name='pb.SearchRequest.author', index=23, + number=36, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='description', full_name='pb.SearchRequest.description', index=24, + number=37, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='claim_type', full_name='pb.SearchRequest.claim_type', index=25, + number=38, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='reposted', full_name='pb.SearchRequest.reposted', index=26, + number=39, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='stream_type', full_name='pb.SearchRequest.stream_type', index=27, + number=40, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='media_type', full_name='pb.SearchRequest.media_type', index=28, + number=41, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='fee_amount', full_name='pb.SearchRequest.fee_amount', index=29, + number=42, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='fee_currency', full_name='pb.SearchRequest.fee_currency', index=30, + number=43, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='duration', full_name='pb.SearchRequest.duration', index=31, + number=44, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='reposted_claim_hash', full_name='pb.SearchRequest.reposted_claim_hash', index=32, + number=45, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='censor_type', full_name='pb.SearchRequest.censor_type', index=33, + number=46, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='claims_in_channel', full_name='pb.SearchRequest.claims_in_channel', index=34, + number=47, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='channel_join', full_name='pb.SearchRequest.channel_join', index=35, + number=48, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='signature_valid', full_name='pb.SearchRequest.signature_valid', index=36, + number=49, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='effective_amount', full_name='pb.SearchRequest.effective_amount', index=37, + number=51, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='support_amount', full_name='pb.SearchRequest.support_amount', index=38, + number=52, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='trending_group', full_name='pb.SearchRequest.trending_group', index=39, + number=53, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='trending_mixed', full_name='pb.SearchRequest.trending_mixed', index=40, + number=54, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='trending_local', full_name='pb.SearchRequest.trending_local', index=41, + number=55, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='trending_global', full_name='pb.SearchRequest.trending_global', index=42, + number=56, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='channel_id', full_name='pb.SearchRequest.channel_id', index=43, + number=57, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='channel_ids', full_name='pb.SearchRequest.channel_ids', index=44, + number=58, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='tx_id', full_name='pb.SearchRequest.tx_id', index=45, + number=59, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='tx_nout', full_name='pb.SearchRequest.tx_nout', index=46, + number=60, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='signature', full_name='pb.SearchRequest.signature', index=47, + number=61, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='signature_digest', full_name='pb.SearchRequest.signature_digest', index=48, + number=62, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='public_key_bytes', full_name='pb.SearchRequest.public_key_bytes', index=49, + number=63, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='public_key_hash', full_name='pb.SearchRequest.public_key_hash', index=50, + number=64, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='public_key_id', full_name='pb.SearchRequest.public_key_id', index=51, + number=65, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='_id', full_name='pb.SearchRequest._id', index=52, + number=66, type=12, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='any_tags', full_name='pb.SearchRequest.any_tags', index=53, + number=67, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='all_tags', full_name='pb.SearchRequest.all_tags', index=54, + number=68, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='not_tags', full_name='pb.SearchRequest.not_tags', index=55, + number=69, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='reposted_claim_id', full_name='pb.SearchRequest.reposted_claim_id', index=56, + number=70, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='has_channel_signature', full_name='pb.SearchRequest.has_channel_signature', index=57, + number=71, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='has_source', full_name='pb.SearchRequest.has_source', index=58, + number=72, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='limit_claims_per_channel', full_name='pb.SearchRequest.limit_claims_per_channel', index=59, + number=73, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='any_languages', full_name='pb.SearchRequest.any_languages', index=60, + number=74, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + _descriptor.FieldDescriptor( + name='all_languages', full_name='pb.SearchRequest.all_languages', index=61, + number=75, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=222, + serialized_end=2211, +) + +_RANGEFIELD.fields_by_name['op'].enum_type = _RANGEFIELD_OP +_RANGEFIELD_OP.containing_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['amount_order'].message_type = google_dot_protobuf_dot_wrappers__pb2._INT32VALUE +_SEARCHREQUEST.fields_by_name['limit'].message_type = google_dot_protobuf_dot_wrappers__pb2._INT32VALUE +_SEARCHREQUEST.fields_by_name['offset'].message_type = google_dot_protobuf_dot_wrappers__pb2._INT32VALUE +_SEARCHREQUEST.fields_by_name['is_controlling'].message_type = google_dot_protobuf_dot_wrappers__pb2._BOOLVALUE +_SEARCHREQUEST.fields_by_name['claim_id'].message_type = _INVERTIBLEFIELD +_SEARCHREQUEST.fields_by_name['tx_position'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['amount'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['timestamp'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['creation_timestamp'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['height'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['creation_height'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['activation_height'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['expiration_height'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['release_time'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['reposted'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['fee_amount'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['duration'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['censor_type'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['channel_join'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['signature_valid'].message_type = google_dot_protobuf_dot_wrappers__pb2._BOOLVALUE +_SEARCHREQUEST.fields_by_name['effective_amount'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['support_amount'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['trending_group'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['trending_mixed'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['trending_local'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['trending_global'].message_type = _RANGEFIELD +_SEARCHREQUEST.fields_by_name['channel_id'].message_type = _INVERTIBLEFIELD +_SEARCHREQUEST.fields_by_name['channel_ids'].message_type = _INVERTIBLEFIELD +_SEARCHREQUEST.fields_by_name['tx_nout'].message_type = google_dot_protobuf_dot_wrappers__pb2._INT32VALUE +_SEARCHREQUEST.fields_by_name['has_channel_signature'].message_type = google_dot_protobuf_dot_wrappers__pb2._BOOLVALUE +_SEARCHREQUEST.fields_by_name['has_source'].message_type = google_dot_protobuf_dot_wrappers__pb2._BOOLVALUE +_SEARCHREQUEST.fields_by_name['limit_claims_per_channel'].message_type = google_dot_protobuf_dot_wrappers__pb2._INT32VALUE +DESCRIPTOR.message_types_by_name['InvertibleField'] = _INVERTIBLEFIELD +DESCRIPTOR.message_types_by_name['RangeField'] = _RANGEFIELD +DESCRIPTOR.message_types_by_name['SearchRequest'] = _SEARCHREQUEST +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +InvertibleField = _reflection.GeneratedProtocolMessageType('InvertibleField', (_message.Message,), { + 'DESCRIPTOR' : _INVERTIBLEFIELD, + '__module__' : 'hub_pb2' + # @@protoc_insertion_point(class_scope:pb.InvertibleField) + }) +_sym_db.RegisterMessage(InvertibleField) + +RangeField = _reflection.GeneratedProtocolMessageType('RangeField', (_message.Message,), { + 'DESCRIPTOR' : _RANGEFIELD, + '__module__' : 'hub_pb2' + # @@protoc_insertion_point(class_scope:pb.RangeField) + }) +_sym_db.RegisterMessage(RangeField) + +SearchRequest = _reflection.GeneratedProtocolMessageType('SearchRequest', (_message.Message,), { + 'DESCRIPTOR' : _SEARCHREQUEST, + '__module__' : 'hub_pb2' + # @@protoc_insertion_point(class_scope:pb.SearchRequest) + }) +_sym_db.RegisterMessage(SearchRequest) + + +DESCRIPTOR._options = None + +_HUB = _descriptor.ServiceDescriptor( + name='Hub', + full_name='pb.Hub', + file=DESCRIPTOR, + index=0, + serialized_options=None, + create_key=_descriptor._internal_create_key, + serialized_start=2213, + serialized_end=2262, + methods=[ + _descriptor.MethodDescriptor( + name='Search', + full_name='pb.Hub.Search', + index=0, + containing_service=None, + input_type=_SEARCHREQUEST, + output_type=result__pb2._OUTPUTS, + serialized_options=None, + create_key=_descriptor._internal_create_key, + ), +]) +_sym_db.RegisterServiceDescriptor(_HUB) + +DESCRIPTOR.services_by_name['Hub'] = _HUB + +# @@protoc_insertion_point(module_scope) diff --git a/lbry/schema/types/v2/hub_pb2_grpc.py b/lbry/schema/types/v2/hub_pb2_grpc.py new file mode 100644 index 000000000..501c003ec --- /dev/null +++ b/lbry/schema/types/v2/hub_pb2_grpc.py @@ -0,0 +1,67 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +import lbry.schema.types.v2.hub_pb2 as hub__pb2 +import lbry.schema.types.v2.result_pb2 as result__pb2 + + +class HubStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.Search = channel.unary_unary( + '/pb.Hub/Search', + request_serializer=hub__pb2.SearchRequest.SerializeToString, + response_deserializer=result__pb2.Outputs.FromString, + ) + + +class HubServicer(object): + """Missing associated documentation comment in .proto file.""" + + def Search(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_HubServicer_to_server(servicer, server): + rpc_method_handlers = { + 'Search': grpc.unary_unary_rpc_method_handler( + servicer.Search, + request_deserializer=hub__pb2.SearchRequest.FromString, + response_serializer=result__pb2.Outputs.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'pb.Hub', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class Hub(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def Search(request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None): + return grpc.experimental.unary_unary(request, target, '/pb.Hub/Search', + hub__pb2.SearchRequest.SerializeToString, + result__pb2.Outputs.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/lbry/testcase.py b/lbry/testcase.py index 75a79fd6e..f041492d4 100644 --- a/lbry/testcase.py +++ b/lbry/testcase.py @@ -624,13 +624,9 @@ class CommandTestCase(IntegrationTestCase): async def claim_search(self, **kwargs): if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true": - res = await self.out(self.hub.claim_search(**kwargs)) - if 'txos' in res: - return res['txos'] - else: - return [] - else: - return (await self.out(self.daemon.jsonrpc_claim_search(**kwargs)))['items'] + kwargs['new_sdk_server'] = "localhost:50051" + kwargs = self.hub.fix_kwargs(**kwargs) + return (await self.out(self.daemon.jsonrpc_claim_search(**kwargs)))['items'] async def file_list(self, *args, **kwargs): return (await self.out(self.daemon.jsonrpc_file_list(*args, **kwargs)))['items'] @@ -646,11 +642,10 @@ class CommandTestCase(IntegrationTestCase): async def claim_list(self, *args, **kwargs): if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true": + kwargs['new_sdk_server'] = "localhost:50051" + kwargs = self.hub.fix_kwargs(**kwargs) res = await self.out(self.hub.claim_search(**kwargs)) - if 'txos' in res: - return res['txos'] - else: - return [] + return res return (await self.out(self.daemon.jsonrpc_claim_list(*args, **kwargs)))['items'] async def stream_list(self, *args, **kwargs): diff --git a/lbry/wallet/ledger.py b/lbry/wallet/ledger.py index 3b9974ca4..8dca15fbe 100644 --- a/lbry/wallet/ledger.py +++ b/lbry/wallet/ledger.py @@ -772,7 +772,10 @@ class Ledger(metaclass=LedgerRegistry): include_received_tips=False) -> Tuple[List[Output], dict, int, int]: encoded_outputs = await query # log.warning(base64.b64decode(encoded_outputs)) - outputs = Outputs.from_base64(encoded_outputs or b'') # TODO: why is the server returning None? + if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true": + outputs = Outputs.from_grpc(encoded_outputs) + else: + outputs = Outputs.from_base64(encoded_outputs or b'') # TODO: why is the server returning None? txs: List[Transaction] = [] log.warning(outputs) log.warning(outputs.txs) diff --git a/lbry/wallet/network.py b/lbry/wallet/network.py index 7b8b6d3e8..cc5fec874 100644 --- a/lbry/wallet/network.py +++ b/lbry/wallet/network.py @@ -3,11 +3,13 @@ import asyncio import json import socket import random -import os from time import perf_counter from collections import defaultdict from typing import Dict, Optional, Tuple import aiohttp +import grpc +from lbry.schema.types.v2 import hub_pb2_grpc +from lbry.schema.types.v2.hub_pb2 import SearchRequest from lbry import __version__ from lbry.utils import resolve_host @@ -469,12 +471,12 @@ class Network: def claim_search(self, session_override=None, **kwargs): # FIXME: How do i get a session to connect to my go rpc server?!? # if os.environ.get("GO_HUB") and os.environ.get("GO_HUB") == "true": - # session_override = ClientSession( - # network=self, server=("localhost", 50051) - # ) - # return self.rpc('pb.Hub.Search', kwargs, False, session_override) + # session_override = ClientSession( + # network=self, server=("localhost", 50051) + # ) + # return self.rpc('pb.Hub.Search', kwargs, False, session_override) # else: - return self.rpc('blockchain.claimtrie.search', kwargs, False, session_override) + return self.rpc('blockchain.claimtrie.search', kwargs, False, session_override) async def new_resolve(self, server, urls): message = {"method": "resolve", "params": {"urls": urls, "protobuf": True}} @@ -483,11 +485,22 @@ class Network: return result['result'] async def new_claim_search(self, server, **kwargs): - kwargs['protobuf'] = True - message = {"method": "claim_search", "params": kwargs} - async with self.aiohttp_session.post(server, json=message) as r: - result = await r.json() - return result['result'] + if "offset" in kwargs and type(kwargs["offset"]) == int: + kwargs["offset"] = {"value": kwargs["offset"]} + if "limit" in kwargs and type(kwargs["limit"]) == int: + kwargs["limit"] = {"value": kwargs["limit"]} + async with grpc.aio.insecure_channel(server) as channel: + stub = hub_pb2_grpc.HubStub(channel) + log.warning(kwargs) + response = await stub.Search(SearchRequest(**kwargs)) + return response + # kwargs['protobuf'] = True + # # TODO: grpc python client here + # + # message = {"method": "claim_search", "params": kwargs} + # async with self.aiohttp_session.post(server, json=message) as r: + # result = await r.json() + # return result['result'] async def sum_supports(self, server, **kwargs): message = {"method": "support_sum", "params": kwargs} diff --git a/lbry/wallet/orchstr8/node.py b/lbry/wallet/orchstr8/node.py index e1d573ee7..21ea0a78f 100644 --- a/lbry/wallet/orchstr8/node.py +++ b/lbry/wallet/orchstr8/node.py @@ -615,76 +615,95 @@ class HubNode: DEFAULT_PAGE_SIZE = 20 page_num, page_size = abs(kwargs.pop('page', 1)), min(abs(kwargs.pop('page_size', DEFAULT_PAGE_SIZE)), 50) kwargs.update({'offset': page_size * (page_num - 1), 'limit': page_size}) - if "has_no_source" in kwargs: - kwargs["has_source"] = not kwargs["has_no_source"] - del kwargs["has_no_source"] - if "claim_id" in kwargs: - kwargs["claim_id"] = { - "invert": False, - "value": kwargs["claim_id"] - } - if "not_claim_id" in kwargs: - kwargs["claim_id"] = { - "invert": True, - "value": kwargs["not_claim_id"] - } - del kwargs["not_claim_id"] - if "claim_ids" in kwargs: - kwargs["claim_id"] = { - "invert": False, - "value": kwargs["claim_ids"] - } - del kwargs["claim_ids"] - if "not_claim_ids" in kwargs: - kwargs["claim_id"] = { - "invert": True, - "value": kwargs["not_claim_ids"] - } - del kwargs["not_claim_ids"] - if "channel_id" in kwargs: - kwargs["channel_id"] = { - "invert": False, - "value": kwargs["channel_id"] - } - if "channel" in kwargs: - kwargs["channel_id"] = { - "invert": False, - "value": kwargs["channel"] - } - del kwargs["channel"] - if "not_channel_id" in kwargs: - kwargs["channel_id"] = { - "invert": True, - "value": kwargs["not_channel_id"] - } - del kwargs["not_channel_id"] - if "channel_ids" in kwargs: - kwargs["channel_ids"] = { - "invert": False, - "value": kwargs["channel_ids"] - } - if "not_channel_ids" in kwargs: - kwargs["channel_ids"] = { - "invert": True, - "value": kwargs["not_channel_ids"] - } - del kwargs["not_channel_ids"] - if "txid" in kwargs: - kwargs["tx_id"] = kwargs["txid"] - del kwargs["txid"] - if "nout" in kwargs: - kwargs["tx_nout"] = kwargs["nout"] - del kwargs["nout"] - if "valid_channel_signature" in kwargs: - kwargs["signature_valid"] = kwargs["valid_channel_signature"] - del kwargs["valid_channel_signature"] - if "invalid_channel_signature" in kwargs: - kwargs["signature_valid"] = not kwargs["invalid_channel_signature"] - del kwargs["invalid_channel_signature"] - + repeated_fields = {"name", "claim_name", "normalized", "reposted_claim_id", "_id", "public_key_hash", + "public_key_bytes", "signature_digest", "signature", "tx_id", "channel_id", + "fee_currency", "media_type", "stream_type", "claim_type", "description", "author", "title", + "canonical_url", "short_url", "claim_id"} + value_fields = {"offset", "limit", "has_channel_signature", "has_source", "has_no_source", + "limit_claims_per_channel", "tx_nout", + "signature_valid", "is_controlling", "amount_order"} ops = {'<=': 'lte', '>=': 'gte', '<': 'lt', '>': 'gt'} - for key in kwargs.keys(): + for key in list(kwargs.keys()): value = kwargs[key] + + if "txid" == key: + kwargs["tx_id"] = kwargs.pop("txid") + key = "tx_id" + if "nout" == key: + kwargs["tx_nout"] = kwargs.pop("nout") + key = "tx_nout" + if "valid_channel_signature" == key: + kwargs["signature_valid"] = kwargs.pop("valid_channel_signature") + if "invalid_channel_signature" == key: + kwargs["signature_valid"] = not kwargs.pop("invalid_channel_signature") + if key in {"valid_channel_signature", "invalid_channel_signature"}: + key = "signature_valid" + value = kwargs[key] + if "has_no_source" == key: + kwargs["has_source"] = not kwargs.pop("has_no_source") + key = "has_source" + value = kwargs[key] + + if key in value_fields: + kwargs[key] = {"value": value} if type(value) != dict else value + + if key in repeated_fields: + kwargs[key] = [value] + + + if "claim_id" == key: + kwargs["claim_id"] = { + "invert": False, + "value": kwargs["claim_id"] + } + if "not_claim_id" == key: + kwargs["claim_id"] = { + "invert": True, + "value": kwargs["not_claim_id"] + } + del kwargs["not_claim_id"] + if "claim_ids" == key: + kwargs["claim_id"] = { + "invert": False, + "value": kwargs["claim_ids"] + } + del kwargs["claim_ids"] + if "not_claim_ids" == key: + kwargs["claim_id"] = { + "invert": True, + "value": kwargs["not_claim_ids"] + } + del kwargs["not_claim_ids"] + if "channel_id" == key: + kwargs["channel_id"] = { + "invert": False, + "value": kwargs["channel_id"] + } + if "channel" == key: + kwargs["channel_id"] = { + "invert": False, + "value": kwargs["channel"] + } + del kwargs["channel"] + if "not_channel_id" == key: + kwargs["channel_id"] = { + "invert": True, + "value": kwargs["not_channel_id"] + } + del kwargs["not_channel_id"] + if "channel_ids" == key: + kwargs["channel_ids"] = { + "invert": False, + "value": kwargs["channel_ids"] + } + if "not_channel_ids" == key: + kwargs["channel_ids"] = { + "invert": True, + "value": kwargs["not_channel_ids"] + } + del kwargs["not_channel_ids"] + + if key in MY_RANGE_FIELDS and isinstance(value, str) and value[0] in ops: operator_length = 2 if value[:2] in ops else 1 operator, value = value[:operator_length], value[operator_length:] @@ -700,18 +719,18 @@ class HubNode: op = 3 if operator == '>' or operator == 'gt': op = 4 - kwargs[key] = {"op": op, "value": str(value)} + kwargs[key] = {"op": op, "value": [str(value)]} elif key in MY_RANGE_FIELDS: - kwargs[key] = {"op": 0, "value": str(value)} + kwargs[key] = {"op": 0, "value": [str(value)]} - if 'fee_amount' in kwargs: - value = kwargs['fee_amount'] - value.update({"value": str(Decimal(value['value']) * 1000)}) - kwargs['fee_amount'] = value - if 'stream_types' in kwargs: - kwargs['stream_type'] = kwargs.pop('stream_types') - if 'media_types' in kwargs: - kwargs['media_type'] = kwargs.pop('media_types') + if 'fee_amount' == key: + value = kwargs['fee_amount'] + value.update({"value": [str(Decimal(value['value'][0]) * 1000)]}) + kwargs['fee_amount'] = value + if 'stream_types' == key: + kwargs['stream_type'] = kwargs.pop('stream_types') + if 'media_types' == key: + kwargs['media_type'] = kwargs.pop('media_types') return kwargs async def _cli_cmnd2(self, *args): diff --git a/setup.py b/setup.py index 08ca4b9d5..2838b1f7f 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ setup( 'base58==1.0.0', 'cffi==1.13.2', 'cryptography==2.5', - 'protobuf==3.6.1', + 'protobuf==3.17.2', 'msgpack==0.6.1', 'prometheus_client==0.7.1', 'ecdsa==0.13.3', @@ -56,6 +56,7 @@ setup( 'attrs==18.2.0', 'pylru==1.1.0', 'elasticsearch==7.10.1', + 'grpcio==1.38.0' ] + PLYVEL, extras_require={ 'torrent': ['lbry-libtorrent'], diff --git a/tests/integration/hub/test_hub_commands.py b/tests/integration/hub/test_hub_commands.py index 263b4e8fe..53fcb7f40 100644 --- a/tests/integration/hub/test_hub_commands.py +++ b/tests/integration/hub/test_hub_commands.py @@ -69,14 +69,15 @@ class ClaimSearchCommand(ClaimTestCase): async def assertFindsClaims(self, claims, **kwargs): kwargs.setdefault('order_by', ['height', '^name']) + results = await self.claim_search(**kwargs) self.assertEqual(len(claims), len(results)) - # for claim, result in zip(claims, results): - # self.assertEqual( - # (claim['txid'], self.get_claim_id(claim)), - # (result['txid'], result['claim_id']), - # f"(expected {claim['outputs'][0]['name']}) != (got {result['name']})" - # ) + for claim, result in zip(claims, results): + self.assertEqual( + (claim['txid'], self.get_claim_id(claim)), + (result['txid'], result['claim_id']), + f"(expected {claim['outputs'][0]['name']}) != (got {result['name']})" + ) async def assertListsClaims(self, claims, **kwargs): kwargs.setdefault('order_by', 'height') @@ -129,6 +130,7 @@ class ClaimSearchCommand(ClaimTestCase): # three streams in channel, zero streams in abandoned channel claims = [three, two, signed] await self.assertFindsClaims(claims, channel_ids=[self.channel_id]) + # FIXME # channel param doesn't work yet because we need to implement resolve url from search first # await self.assertFindsClaims(claims, channel=f"@abc#{self.channel_id}") # await self.assertFindsClaims([], channel=f"@inexistent") @@ -144,14 +146,16 @@ class ClaimSearchCommand(ClaimTestCase): self.ledger._tx_cache.clear() invalid_claims = await self.claim_search(invalid_channel_signature=True, has_channel_signature=True) self.assertEqual(3, len(invalid_claims)) - # Doesn't work yet because we haven't implemented inflate query yet - # self.assertTrue(all([not c['is_channel_signature_valid'] for c in invalid_claims])) - # self.assertEqual({'channel_id': self.channel_id}, invalid_claims[0]['signing_channel']) + self.assertTrue(all([not c['is_channel_signature_valid'] for c in invalid_claims])) + self.assertEqual({'channel_id': self.channel_id}, invalid_claims[0]['signing_channel']) valid_claims = await self.claim_search(valid_channel_signature=True, has_channel_signature=True) self.assertEqual(1, len(valid_claims)) + # FIXME + # print(valid_claims) + # Something happens in inflation I think and this gets switch from valid to not # self.assertTrue(all([c['is_channel_signature_valid'] for c in valid_claims])) - # This doesn't work yet + # And signing channel only has id? 'signing_channel': {'channel_id': '6f4513e9bbd63d7b7f13dbf4fd2ef28c560ac89b'} # self.assertEqual('@abc', valid_claims[0]['signing_channel']['name']) # abandoned stream won't show up for streams in channel search @@ -177,21 +181,23 @@ class ClaimSearchCommand(ClaimTestCase): await self.assertFindsClaims([channel_repost, no_source_repost, normal_repost, normal, no_source, channel]) # await self.assertListsClaims([channel_repost, no_source_repost, normal_repost, normal, no_source, channel]) - @skip("Won't work until we can inflate hub replies") + @skip("Won't work until we can resolve the channel id") async def test_pagination(self): await self.create_channel() await self.create_lots_of_streams() - # with and without totals - results = await self.daemon.jsonrpc_claim_search() - self.assertEqual(results['total_pages'], 2) - self.assertEqual(results['total_items'], 25) - results = await self.daemon.jsonrpc_claim_search(no_totals=True) - self.assertNotIn('total_pages', results) - self.assertNotIn('total_items', results) + # FIXME: this doesn't work when jsonrpc_claim_search is called directly + # # with and without totals + # results = await self.daemon.jsonrpc_claim_search() + # self.assertEqual(results['total_pages'], 2) + # self.assertEqual(results['total_items'], 25) + # results = await self.daemon.jsonrpc_claim_search(no_totals=True) + # self.assertNotIn('total_pages', results) + # self.assertNotIn('total_items', results) # defaults page = await self.claim_search(channel='@abc', order_by=['height', '^name']) + print(page) page_claim_ids = [item['name'] for item in page] self.assertEqual(page_claim_ids, self.streams[:DEFAULT_PAGE_SIZE])