Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the wallet server/hub database use only leveldb (drop sqlite) and safely handle reorgs #3205

Merged
merged 206 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
206 commits
Select commit Hold shift + click to select a range
23035b9
Merkle staticmethods
jackrobison Nov 29, 2020
cf5dba9
combine leveldb databases
jackrobison Jan 9, 2021
9f224a9
atomic flush_dbs
jackrobison Jan 11, 2021
62cc6df
consolidate leveldb block advance/reorg
jackrobison Jan 11, 2021
4258cef
remove lbry.wallet.server.history
jackrobison Jan 12, 2021
ccac4ff
consolidate flush_backup
jackrobison Jan 13, 2021
2c8ceb1
named tuples
jackrobison Feb 19, 2021
6988a47
disable sqlite in block processor
jackrobison Feb 19, 2021
28c603a
transaction_num_mapping
jackrobison Feb 19, 2021
588edf9
claims db
jackrobison Feb 19, 2021
923834c
get_claim_by_claim_id
jackrobison Feb 19, 2021
c681041
claim expiration
jackrobison Feb 21, 2021
b7df277
db state struct
jackrobison Feb 24, 2021
04bb7b4
add wrapper for getnamesintrie
jackrobison Feb 24, 2021
bfeeacb
tests
jackrobison Mar 10, 2021
cacbe30
rebase
jackrobison Mar 26, 2021
6d4c1cd
LBRYBlockProcessor -> BlockProcessor
jackrobison May 5, 2021
103bdc1
dead code
jackrobison May 5, 2021
aa3b18f
advance_blocks -> advance_block
jackrobison May 5, 2021
9a11ac0
claim activations and takeovers (WIP)
jackrobison May 5, 2021
4aa4e35
tests
jackrobison May 5, 2021
f290753
move get_expiration_height and claimtrie constants to Coin class
jackrobison May 20, 2021
586b196
claim takeovers
jackrobison May 20, 2021
d27c2cc
remove unused COIN file
jackrobison May 20, 2021
e77f998
DBError
jackrobison May 20, 2021
efb92ea
fix udp ping test
jackrobison May 21, 2021
b69faf6
bid ordered resolve (WIP)
jackrobison May 24, 2021
0a28d21
comments
jackrobison May 24, 2021
410d4ae
fix takeover edge case
jackrobison May 25, 2021
3eb9d23
require previous_winning arg for get_takeover_name_ops
jackrobison May 25, 2021
77cde41
test_early_takeover_abandoned_controlling_support
jackrobison May 25, 2021
62a4f0f
fix early takeovers by not-yet activated claims
jackrobison May 26, 2021
407cd8d
fix duplicate update op for early activating claim
jackrobison May 26, 2021
6f5bca0
bid ordered resolve, feed ES claim data from block processor
jackrobison May 27, 2021
eb1ba14
fix updating the ES search index
jackrobison May 28, 2021
2abc67c
reposts
jackrobison Jun 2, 2021
338488f
tests
jackrobison Jun 4, 2021
e605c14
flush count
jackrobison Jun 4, 2021
f493f13
prints
jackrobison Jun 4, 2021
ffff3bd
debugging
jackrobison Jun 6, 2021
515f270
faster get_future_activated
jackrobison Jun 6, 2021
27be5de
ignore activation for headless supports
jackrobison Jun 6, 2021
ce8e659
fix syncing claim to es where channel is in the same block
jackrobison Jun 6, 2021
7896e17
fix putting spent unactivated supports in removed_active_support
jackrobison Jun 6, 2021
1bdaddb
fix clearing pending_support caches upon abandon
jackrobison Jun 6, 2021
1b325b9
fix flush id
jackrobison Jun 6, 2021
8a555ec
remove extra open functions
jackrobison Jun 6, 2021
18b5f03
filter supported claim hashes for claims that dont exist from early t…
jackrobison Jun 6, 2021
ce031dc
only do early takeover on a larger amount (fix case where they're equal)
jackrobison Jun 6, 2021
adb188e
filter abandoned claims from those considered for early activation
jackrobison Jun 7, 2021
07c8650
refactor ClaimToTXO prefix
jackrobison Jun 9, 2021
962dc1b
debug
jackrobison Jun 15, 2021
4a1b2be
leveldb tuning
jackrobison Jun 15, 2021
9f3604d
debug
jackrobison Jun 15, 2021
1b94dfd
fix removing unactivated support
jackrobison Jun 15, 2021
9cbb19c
_cached_get_active_amount
jackrobison Jun 15, 2021
8bea109
disable es (revert)
jackrobison Jun 15, 2021
42d07fd
fix
jackrobison Jun 16, 2021
a2619f8
genesis_bytes attribute
jackrobison Jun 16, 2021
d0d6e35
use default sync=False during write_batch
jackrobison Jun 16, 2021
7c34e4b
logging
jackrobison Jun 16, 2021
65700e7
_prepare_claim_for_sync generators
jackrobison Jun 18, 2021
d6758fd
invalidate channel signatures upon channel abandon
jackrobison Jun 18, 2021
3450275
update elastic sync
jackrobison Jun 18, 2021
458f853
try default block size
jackrobison Jun 18, 2021
7688293
close db in sync script
jackrobison Jun 18, 2021
218be22
imports
jackrobison Jun 18, 2021
ba4f320
faster claim producer
jackrobison Jun 18, 2021
8b37a66
fix fee amount overflow in es
jackrobison Jun 18, 2021
4d35737
add RevertableOpStack to verify consistency of ops as they're staged
jackrobison Jun 22, 2021
d119fcf
remove debug prints
jackrobison Jun 22, 2021
1dc961d
use RevertableOpStack in _get_takeover_ops
jackrobison Jun 28, 2021
ed652c0
fix updating resolve by effective amount after abandoning support
jackrobison Jun 28, 2021
bb2a34d
fix duplicate activate
jackrobison Jun 28, 2021
bfb9d69
pretty print
jackrobison Jul 1, 2021
2ee419f
fix
jackrobison Jul 1, 2021
cf66c2a
rename things
jackrobison Jul 1, 2021
0c30838
fix mismatch in claim_to_txo<->txo_to_claim
jackrobison Jul 2, 2021
814699e
cleanup
jackrobison Jul 2, 2021
52ff1a1
fix undeleted claim_to_channel record
jackrobison Jul 3, 2021
821be29
rename effective_amount prefix
jackrobison Jul 3, 2021
dc2f22f
cleanup
jackrobison Jul 3, 2021
3b96bd7
fix
jackrobison Jul 5, 2021
290be69
typing
jackrobison Jul 5, 2021
a8f2036
fix RepostKey
jackrobison Jul 5, 2021
310c483
missing channel_to_claim delete
jackrobison Jul 5, 2021
f8eceb4
update staged txo_to_claim after invalidating channel sig
jackrobison Jul 5, 2021
6416ee8
typing and fix error string
jackrobison Jul 5, 2021
8bcfff0
update channel_to_claim and claim_to_channel at the same time
jackrobison Jul 5, 2021
e5c22fa
fix has_no_source for reposts
jackrobison Jul 5, 2021
229cb85
extra deletes
jackrobison Jul 6, 2021
c68f9f6
fix signed claim invalidation corner cases
jackrobison Jul 6, 2021
615e489
fix `stream_update` --clear_channel flag
jackrobison Jul 6, 2021
c91a47f
improve channel invalidation test
jackrobison Jul 7, 2021
b9c2ee7
fix non localhost elasticsearch
jackrobison Jul 8, 2021
a84b9ee
fix es sync
jackrobison Jul 8, 2021
68474e4
skip es sync during initial hub sync, halt the hub upon finishing ini…
jackrobison Jul 8, 2021
a1ddd76
cleanup
jackrobison Jul 8, 2021
6f3342e
update plyvel to 1.3.0
jackrobison Jul 12, 2021
677b8cb
add remaining db prefixes
jackrobison Jul 14, 2021
b344f17
update RevertableOpStack
jackrobison Jul 14, 2021
f94e6ac
update lookup_utxos
jackrobison Jul 14, 2021
2bb55d6
update limited_history
jackrobison Jul 14, 2021
3955b64
simplify advance and reorg
jackrobison Jul 14, 2021
7de06aa
delete stale code
jackrobison Jul 14, 2021
07e182a
rename
jackrobison Jul 14, 2021
7a56eff
small fixes
jackrobison Jul 16, 2021
496f89f
reorg claims in the search index
jackrobison Jul 16, 2021
a6ee8dc
fix touched hashXs notifications
jackrobison Jul 16, 2021
292d272
combine MemPool and Notifications classes
jackrobison Jul 16, 2021
1ac7831
move MemPool into BlockProcessor
jackrobison Jul 16, 2021
8927a48
tests
jackrobison Jul 16, 2021
df5662d
fix resolve by short id
jackrobison Jul 18, 2021
ca57dcf
handle failure to generate a short id
jackrobison Jul 20, 2021
c26a99e
fix abandoning signed claims in the same tx as their channel
jackrobison Jul 20, 2021
c28aae9
fix expiring channels
jackrobison Jul 21, 2021
a35dfd1
faster es sync
jackrobison Jul 21, 2021
ac82617
fix spends in address histories
jackrobison Jul 22, 2021
e33e767
fix test
jackrobison Jul 22, 2021
c632a7a
fix getting block hash during reorg
jackrobison Jul 22, 2021
077ca98
cleanup
jackrobison Jul 22, 2021
813e506
threadpool
jackrobison Jul 22, 2021
1a59128
faster get_future_activated
jackrobison Jul 24, 2021
73ba381
faster spend_utxo
jackrobison Jul 24, 2021
30b923b
rename extend_ops
jackrobison Jul 24, 2021
5a01dbf
split flush from advance_block
jackrobison Jul 24, 2021
4e4e899
fix spend_utxo
jackrobison Jul 26, 2021
0fb6f05
in memory claim_to_txo and txo_to_claim dictionaries
jackrobison Jul 26, 2021
25147d8
handle claims that dont exist in ES sync
jackrobison Jul 26, 2021
f8d2f02
clear claim_to_txo cache before reading
jackrobison Jul 26, 2021
0273a4e
fix claim search by fee for claims without fees
jackrobison Jul 26, 2021
def2903
faster _cached_get_active_amount for claims
jackrobison Jul 26, 2021
f944671
use claim_to_txo cache
jackrobison Jul 26, 2021
180ba27
run advance_block in threadpool
jackrobison Jul 26, 2021
f0a195a
faster es sync
jackrobison Jul 27, 2021
f7622f2
non blocking mempool loop
jackrobison Jul 27, 2021
98bc7d1
remove dead code
jackrobison Jul 27, 2021
fb1a774
delete lbry/wallet/server/storage.py
jackrobison Jul 28, 2021
fab9c90
update iterators to use pack_partial_key
jackrobison Jul 29, 2021
ffbe59e
fix applying expiration fork
jackrobison Jul 29, 2021
b4d6c4f
fix _get_pending_claim_name
jackrobison Jul 29, 2021
d413742
implement blocking and filtering
shyba Jul 30, 2021
09bb1ba
fix keeping claim_hash_to_txo and txo_to_claim in sync
jackrobison Jul 30, 2021
8f9e7f7
handle invalid claim update
jackrobison Jul 30, 2021
722b42a
fix tests
jackrobison Jul 30, 2021
af22646
fix tests
jackrobison Jul 30, 2021
2d48e93
fix bulk es sync
jackrobison Aug 2, 2021
54461df
fix merge conflicts and simplify extract_doc
jackrobison Aug 6, 2021
c51e344
fix missing fields in reposts
jackrobison Aug 9, 2021
28aa7da
merge conflicts
jackrobison Aug 10, 2021
59db5e7
update test
jackrobison Aug 10, 2021
234c03d
fix claims not having non-normalized names
jackrobison Aug 12, 2021
0c0e36b
trending
eggplantbren Aug 15, 2021
3a1baf0
prefix db
jackrobison Aug 14, 2021
54903fc
handle unicode error for unnormalized names
jackrobison Aug 15, 2021
231eabb
fix non normalized canonical urls
jackrobison Aug 16, 2021
388724f
Mark claims as touched
eggplantbren Aug 17, 2021
53bd2bc
Put trending score into ES
eggplantbren Aug 17, 2021
65c0668
constants
eggplantbren Aug 17, 2021
34576e8
update trending in elasticsearch
jackrobison Aug 30, 2021
1940301
skip integrity errors for trending spikes
jackrobison Aug 30, 2021
acaf299
log time to update and decay trending in elasticsearch
jackrobison Aug 30, 2021
db27899
make app backward compatible with `trending_score`
jackrobison Aug 30, 2021
0ba7515
trending fixes
jackrobison Aug 30, 2021
165f3bb
refactor trending
jackrobison Sep 3, 2021
3a16edd
fix trending overflow
jackrobison Sep 7, 2021
57028ea
add trending integration test
jackrobison Sep 7, 2021
32f8c9e
renormalization
jackrobison Sep 7, 2021
2138e7e
fix tests
jackrobison Sep 8, 2021
58ad1f3
non blocking claim producer
jackrobison Sep 8, 2021
701b39b
test_spec_example
jackrobison Sep 9, 2021
d23a0a8
delete unused code
jackrobison Sep 9, 2021
9365708
fix release_time and creation_timestamp
jackrobison Sep 9, 2021
1ff7b77
claim search fixes
jackrobison Sep 13, 2021
6231861
merge conflicts
jackrobison Sep 13, 2021
a567326
fix all_claims_producer
jackrobison Sep 13, 2021
1ee1a5f
fix es sync.py
jackrobison Sep 13, 2021
ece2d1e
`name` and `normalized` -> `claim_name` and `normalized_name`
jackrobison Sep 15, 2021
be6b72e
handle invalid release time
jackrobison Sep 15, 2021
b2f9ef2
use hub binary from https://github.com/lbryio/hub/pull/13
jackrobison Sep 15, 2021
709f5e9
fix update that initiates takeover not being delayed
jackrobison Sep 16, 2021
91a07cf
fix logging number of notified sessions
jackrobison Sep 20, 2021
aa50e6e
fix test
jackrobison Sep 20, 2021
82fe2a4
fix blocking and filtering
shyba Sep 21, 2021
37ec9ab
remove unused executor
jackrobison Sep 21, 2021
72500f6
faster read_claim_txos
jackrobison Sep 21, 2021
8c75098
fix filtering error upon abandon
jackrobison Sep 21, 2021
6ec7019
refactor reload_blocking_filtering_streams
jackrobison Sep 21, 2021
02cf478
improve leveldb caching
jackrobison Sep 22, 2021
18e1256
batch address history notifications
jackrobison Sep 22, 2021
89cd6a9
add tests for takeovers from amount changes in updates before/on/afte…
jackrobison Sep 25, 2021
86f21da
fix activating non existent claim
jackrobison Sep 25, 2021
11dcb16
fix test
jackrobison Sep 27, 2021
33e8ef7
fix bug with early takeover by an update
jackrobison Sep 27, 2021
09db868
fix ES index name so it stays the same within a test case
jackrobison Sep 29, 2021
b198f79
fix test_sqlite_coin_chooser
jackrobison Sep 29, 2021
01ee4b2
fix and add test for abandoning a controlling in the same block a new…
jackrobison Oct 1, 2021
4cf7612
block processor db refactoring
jackrobison Oct 4, 2021
8167af9
sort touched or deleted claim hashes
jackrobison Oct 5, 2021
0939589
move test_claim_commands and test_resolve_command into new directory
jackrobison Oct 5, 2021
e03f01e
try to fix test_sqlite_coin_chooser
jackrobison Oct 5, 2021
a7c45da
fix channel count
jackrobison Oct 6, 2021
ccf03fc
only save undo info for blocks within reorg limit
jackrobison Oct 6, 2021
b2922d1
move test_transaction_commands, test_internal_transaction_api , and t…
jackrobison Oct 6, 2021
d64a5bc
fix test
jackrobison Oct 6, 2021
43432a9
fix compactify script
jackrobison Oct 7, 2021
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
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ jobs:
test:
- datanetwork
- blockchain
- blockchain_legacy_search
- claims
- takeovers
- transactions
- claims_legacy_search
- takeovers_legacy_search
- other
steps:
- name: Configure sysctl limits
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ __pycache__
_trial_temp/
trending*.log

/tests/integration/blockchain/files
/tests/integration/claims/files
/tests/.coverage.*

/lbry/wallet/bin
Expand Down
3 changes: 2 additions & 1 deletion lbry/error/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,10 @@ def __init__(self, url):

class ResolveCensoredError(WalletError):

def __init__(self, url, censor_id):
def __init__(self, url, censor_id, censor_row):
self.url = url
self.censor_id = censor_id
self.censor_row = censor_row
super().__init__(f"Resolve of '{url}' was censored by channel with claim id '{censor_id}'.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will get overwritten when the error file is re-generated from the lbry/error/README.md.



Expand Down
14 changes: 8 additions & 6 deletions lbry/extras/daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ async def jsonrpc_purchase_create(
accounts = wallet.get_accounts_or_all(funding_account_ids)
txo = None
if claim_id:
txo = await self.ledger.get_claim_by_claim_id(accounts, claim_id, include_purchase_receipt=True)
txo = await self.ledger.get_claim_by_claim_id(claim_id, accounts, include_purchase_receipt=True)
if not isinstance(txo, Output) or not txo.is_claim:
# TODO: use error from lbry.error
raise Exception(f"Could not find claim with claim_id '{claim_id}'.")
Expand Down Expand Up @@ -3616,7 +3616,7 @@ async def jsonrpc_stream_update(
claim_address = old_txo.get_address(account.ledger)

channel = None
if channel_id or channel_name:
if not clear_channel and (channel_id or channel_name):
channel = await self.get_channel_or_error(
wallet, channel_account_id, channel_id, channel_name, for_signing=True)
elif old_txo.claim.is_signed and not clear_channel and not replace:
Expand Down Expand Up @@ -3646,11 +3646,13 @@ async def jsonrpc_stream_update(
else:
claim = Claim.from_bytes(old_txo.claim.to_bytes())
claim.stream.update(file_path=file_path, **kwargs)
if clear_channel:
claim.clear_signature()
tx = await Transaction.claim_update(
old_txo, claim, amount, claim_address, funding_accounts, funding_accounts[0], channel
old_txo, claim, amount, claim_address, funding_accounts, funding_accounts[0],
channel if not clear_channel else None
)
new_txo = tx.outputs[0]

stream_hash = None
if not preview:
old_stream = self.file_manager.get_filtered(sd_hash=old_txo.claim.stream.source.sd_hash)
Expand Down Expand Up @@ -4148,7 +4150,7 @@ async def jsonrpc_collection_resolve(
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)

if claim_id:
txo = await self.ledger.get_claim_by_claim_id(wallet.accounts, claim_id)
txo = await self.ledger.get_claim_by_claim_id(claim_id, wallet.accounts)
if not isinstance(txo, Output) or not txo.is_claim:
# TODO: use error from lbry.error
raise Exception(f"Could not find collection with claim_id '{claim_id}'.")
Expand Down Expand Up @@ -4215,7 +4217,7 @@ async def jsonrpc_support_create(
funding_accounts = wallet.get_accounts_or_all(funding_account_ids)
channel = await self.get_channel_or_none(wallet, channel_account_id, channel_id, channel_name, for_signing=True)
amount = self.get_dewies_or_error("amount", amount)
claim = await self.ledger.get_claim_by_claim_id(wallet.accounts, claim_id)
claim = await self.ledger.get_claim_by_claim_id(claim_id)
claim_address = claim.get_address(self.ledger)
if not tip:
account = wallet.get_account_or_default(account_id)
Expand Down
105 changes: 56 additions & 49 deletions lbry/schema/result.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import base64
import struct
from typing import List
from typing import List, TYPE_CHECKING, Union, Optional
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.leveldb import ResolveResult

INVALID = ErrorMessage.Code.Name(ErrorMessage.INVALID)
NOT_FOUND = ErrorMessage.Code.Name(ErrorMessage.NOT_FOUND)
BLOCKED = ErrorMessage.Code.Name(ErrorMessage.BLOCKED)


def set_reference(reference, txo_row):
if txo_row:
reference.tx_hash = txo_row['txo_hash'][:32]
reference.nout = struct.unpack('<I', txo_row['txo_hash'][32:])[0]
reference.height = txo_row['height']
def set_reference(reference, claim_hash, rows):
if claim_hash:
for txo in rows:
if claim_hash == txo.claim_hash:
reference.tx_hash = txo.tx_hash
reference.nout = txo.position
reference.height = txo.height
return


class Censor:
Expand All @@ -38,19 +42,19 @@ def is_censored(self, row):
def apply(self, rows):
return [row for row in rows if not self.censor(row)]

def censor(self, row) -> bool:
def censor(self, row) -> Optional[bytes]:
if self.is_censored(row):
censoring_channel_hash = bytes.fromhex(row['censoring_channel_id'])[::-1]
self.censored.setdefault(censoring_channel_hash, set())
self.censored[censoring_channel_hash].add(row['tx_hash'])
return True
return False
return censoring_channel_hash
return None

def to_message(self, outputs: OutputsMessage, extra_txo_rows: dict):
for censoring_channel_hash, count in self.censored.items():
blocked = outputs.blocked.add()
blocked.count = len(count)
set_reference(blocked.channel, extra_txo_rows.get(censoring_channel_hash))
set_reference(blocked.channel, censoring_channel_hash, extra_txo_rows)
outputs.blocked_total += len(count)


Expand Down Expand Up @@ -115,10 +119,10 @@ def message_to_txo(self, txo_message, tx_map):
'expiration_height': claim.expiration_height,
'effective_amount': claim.effective_amount,
'support_amount': claim.support_amount,
'trending_group': claim.trending_group,
'trending_mixed': claim.trending_mixed,
'trending_local': claim.trending_local,
'trending_global': claim.trending_global,
# 'trending_group': claim.trending_group,
# 'trending_mixed': claim.trending_mixed,
# 'trending_local': claim.trending_local,
# 'trending_global': claim.trending_global,
}
if claim.HasField('channel'):
txo.channel = tx_map[claim.channel.tx_hash].outputs[claim.channel.nout]
Expand Down Expand Up @@ -169,51 +173,54 @@ def to_base64(cls, txo_rows, extra_txo_rows, offset=0, total=None, blocked=None)

@classmethod
def to_bytes(cls, txo_rows, extra_txo_rows, offset=0, total=None, blocked: Censor = None) -> bytes:
extra_txo_rows = {row['claim_hash']: row for row in extra_txo_rows}
page = OutputsMessage()
page.offset = offset
if total is not None:
page.total = total
if blocked is not None:
blocked.to_message(page, extra_txo_rows)
for row in extra_txo_rows:
cls.encode_txo(page.extra_txos.add(), row)

for row in txo_rows:
cls.row_to_message(row, page.txos.add(), extra_txo_rows)
for row in extra_txo_rows.values():
cls.row_to_message(row, page.extra_txos.add(), extra_txo_rows)
# cls.row_to_message(row, page.txos.add(), extra_txo_rows)
txo_message: 'OutputsMessage' = page.txos.add()
cls.encode_txo(txo_message, row)
if not isinstance(row, Exception):
if row.channel_hash:
set_reference(txo_message.claim.channel, row.channel_hash, extra_txo_rows)
if row.reposted_claim_hash:
set_reference(txo_message.claim.repost, row.reposted_claim_hash, extra_txo_rows)
elif isinstance(row, ResolveCensoredError):
set_reference(txo_message.error.blocked.channel, row.censor_id, extra_txo_rows)
return page.SerializeToString()

@classmethod
def row_to_message(cls, txo, txo_message, extra_row_dict: dict):
if isinstance(txo, Exception):
txo_message.error.text = txo.args[0]
if isinstance(txo, ValueError):
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):
txo_message.error.code = ErrorMessage.INVALID
elif isinstance(txo, LookupError):
elif isinstance(resolve_result, LookupError):
txo_message.error.code = ErrorMessage.NOT_FOUND
elif isinstance(txo, ResolveCensoredError):
elif isinstance(resolve_result, ResolveCensoredError):
txo_message.error.code = ErrorMessage.BLOCKED
set_reference(txo_message.error.blocked.channel, extra_row_dict.get(bytes.fromhex(txo.censor_id)[::-1]))
return
txo_message.tx_hash = txo['txo_hash'][:32]
txo_message.nout, = struct.unpack('<I', txo['txo_hash'][32:])
txo_message.height = txo['height']
txo_message.claim.short_url = txo['short_url']
txo_message.claim.reposted = txo['reposted']
if txo['canonical_url'] is not None:
txo_message.claim.canonical_url = txo['canonical_url']
txo_message.claim.is_controlling = bool(txo['is_controlling'])
if txo['last_take_over_height'] is not None:
txo_message.claim.take_over_height = txo['last_take_over_height']
txo_message.claim.creation_height = txo['creation_height']
txo_message.claim.activation_height = txo['activation_height']
txo_message.claim.expiration_height = txo['expiration_height']
if txo['claims_in_channel'] is not None:
txo_message.claim.claims_in_channel = txo['claims_in_channel']
txo_message.claim.effective_amount = txo['effective_amount']
txo_message.claim.support_amount = txo['support_amount']
txo_message.claim.trending_group = txo['trending_group']
txo_message.claim.trending_mixed = txo['trending_mixed']
txo_message.claim.trending_local = txo['trending_local']
txo_message.claim.trending_global = txo['trending_global']
set_reference(txo_message.claim.channel, extra_row_dict.get(txo['channel_hash']))
set_reference(txo_message.claim.repost, extra_row_dict.get(txo['reposted_claim_hash']))
txo_message.tx_hash = resolve_result.tx_hash
txo_message.nout = resolve_result.position
txo_message.height = resolve_result.height
txo_message.claim.short_url = resolve_result.short_url
txo_message.claim.reposted = resolve_result.reposted
txo_message.claim.is_controlling = resolve_result.is_controlling
txo_message.claim.creation_height = resolve_result.creation_height
txo_message.claim.activation_height = resolve_result.activation_height
txo_message.claim.expiration_height = resolve_result.expiration_height
txo_message.claim.effective_amount = resolve_result.effective_amount
txo_message.claim.support_amount = resolve_result.support_amount

if resolve_result.canonical_url is not None:
txo_message.claim.canonical_url = resolve_result.canonical_url
if resolve_result.last_takeover_height is not None:
txo_message.claim.take_over_height = resolve_result.last_takeover_height
if resolve_result.claims_in_channel is not None:
txo_message.claim.claims_in_channel = resolve_result.claims_in_channel
Loading