Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ idea:
cp -r scripts/idea/* .idea

elastic-docker:
docker run -d -v lbryhub:/usr/share/elasticsearch/data -p 9200:9200 -p 9300:9300 -e"ES_JAVA_OPTS=-Xms512m -Xmx512m" -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.12.1
docker run -d --env network.publish_host=127.0.0.1 -v lbryhub:/usr/share/elasticsearch/data -p 9200:9200 -p 9300:9300 -e"ES_JAVA_OPTS=-Xms512m -Xmx512m" -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.12.1
5 changes: 5 additions & 0 deletions lbry/error/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from .base import BaseError, claim_id

class StreamExtensionTypeUnresolved(BaseError):
def __init__(self, url_prefix, name):
self.url_prefix = url_prefix
self.name = name
super().__init__(f"Stream extension type '{url_prefix}/{name}' could not be resolved.")

class UserInputError(BaseError):
"""
Expand Down
52 changes: 49 additions & 3 deletions lbry/extras/daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import base58
from aiohttp import web
from prometheus_client import generate_latest as prom_generate_latest, Gauge, Histogram, Counter
# For pylint issue see: https://github.com/PyCQA/pylint/issues/6281
from google.protobuf.any_pb2 import Any as AnyMessage # pylint: disable=no-name-in-module
from google.protobuf.message import DecodeError

from lbry.wallet import (
Expand All @@ -39,7 +41,7 @@
DownloadSDTimeoutError, ComponentsNotStartedError, ComponentStartConditionNotMetError,
CommandDoesNotExistError, BaseError, WalletNotFoundError, WalletAlreadyLoadedError, WalletAlreadyExistsError,
ConflictingInputValueError, AlreadyPurchasedError, PrivateKeyNotFoundError, InputStringIsBlankError,
InputValueError
InputValueError, StreamExtensionTypeUnresolved
)
from lbry.extras import system_info
from lbry.extras.daemon import analytics
Expand All @@ -53,6 +55,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.attrs import StreamExtension
from lbry.schema.url import URL


Expand Down Expand Up @@ -3352,8 +3355,29 @@ async def jsonrpc_stream_repost(
# TODO: use error from lbry.error
raise Exception('Invalid claim id. It is expected to be a 40 characters long hexadecimal string.')

extensions = kwargs.get('extensions', None)
if extensions:
# Resolve unknown extension types using get_claim_by_claim_id()
for schema, ext in extensions.items():
try:
obj = StreamExtension(None, AnyMessage())
if isinstance(ext, StreamExtension):
obj.from_value(ext)
else:
obj.from_value({schema: ext})
except StreamExtensionTypeUnresolved as e:
descriptor_txo = await self.ledger.get_claim_by_claim_id(e.url_prefix, include_is_my_output=True)
ext = descriptor_txo.claim.stream.extensions['descriptor']
pb_serialized = ext.unpacked['descriptor']
StreamExtension.DESCRIPTOR_POOL.AddSerializedFile(pb_serialized)
Comment thread
moodyjon marked this conversation as resolved.
Outdated

reposted_txo = await self.ledger.get_claim_by_claim_id(claim_id, include_is_my_output=True)
if not isinstance(reposted_txo, Output) or not reposted_txo.is_claim:
raise InputValueError(f"Could not find claim '{claim_id}'.")
if not reposted_txo.can_decode_claim:
raise InputValueError(f"A claim with id '{claim_id}' was found but could not be decoded.")
claim = Claim()
claim.repost.update(**kwargs)
claim.repost.update(claim_type=reposted_txo.claim.claim_type, **kwargs)
claim.repost.reference.claim_id = claim_id
tx = await Transaction.claim_create(
name, claim, amount, claim_address, funding_accounts, funding_accounts[0], channel
Expand Down Expand Up @@ -3506,6 +3530,22 @@ async def jsonrpc_stream_create(
)
kwargs.update(spec)

extensions = kwargs.get('extensions', None)
if extensions:
# Resolve unknown extension types using get_claim_by_claim_id()
for schema, ext in extensions.items():
try:
obj = StreamExtension(None, AnyMessage())
if isinstance(ext, StreamExtension):
obj.from_value(ext)
else:
obj.from_value({schema: ext})
except StreamExtensionTypeUnresolved as e:
descriptor_txo = await self.ledger.get_claim_by_claim_id(e.url_prefix, include_is_my_output=True)
ext = descriptor_txo.claim.stream.extensions['descriptor']
pb_serialized = ext.unpacked['descriptor']
StreamExtension.DESCRIPTOR_POOL.AddSerializedFile(pb_serialized)
Comment thread
moodyjon marked this conversation as resolved.
Outdated

claim = Claim()
if file_path is not None:
claim.stream.update(file_path=file_path, sd_hash='0' * 96, **kwargs)
Expand Down Expand Up @@ -3735,7 +3775,13 @@ async def jsonrpc_stream_update(
if old_txo.claim.is_stream:
claim.stream.update(file_path=file_path, **kwargs)
elif old_txo.claim.is_repost:
claim.repost.update(**kwargs)
reposted_id = old_txo.claim.repost.reference.claim_id
reposted_txo = await self.ledger.get_claim_by_claim_id(reposted_id, include_is_my_output=True)
if not isinstance(reposted_txo, Output) or not reposted_txo.is_claim:
raise InputValueError(f"Could not find reposted claim '{reposted_id}'.")
if not reposted_txo.can_decode_claim:
raise InputValueError(f"A claim with id '{reposted_id}' was found but could not be decoded.")
claim.repost.update(claim_type=reposted_txo.claim.claim_type, **kwargs)

if clear_channel:
claim.clear_signature()
Expand Down
4 changes: 2 additions & 2 deletions lbry/schema/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build:
rm types/v2/* -rf
rm -rf types/v2/*
touch types/v2/__init__.py
cd types/v2/ && protoc --python_out=. -I ../../../../../types/v2/proto/ ../../../../../types/v2/proto/*.proto
cd types/v2/ && cp ../../../../../types/jsonschema/* ./
sed -e 's/^import\ \(.*\)_pb2\ /from . import\ \1_pb2\ /g' -i types/v2/*.py
sed -e 's/^import\ \(.*\)_pb2\ /from . import\ \1_pb2\ /g' -i.bak types/v2/*.py
Loading