pretty print

This commit is contained in:
Jack Robison 2021-06-30 20:07:19 -04:00
parent bb2a34dd6b
commit bfb9d696d7
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 70 additions and 1 deletions

View file

@ -48,6 +48,9 @@ class PrefixRow:
class ClaimToTXOKey(typing.NamedTuple):
claim_hash: bytes
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
class ClaimToTXOValue(typing.NamedTuple):
tx_num: int
@ -69,6 +72,9 @@ class TXOToClaimValue(typing.NamedTuple):
claim_hash: bytes
name: str
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, name={self.name})"
class ClaimShortIDKey(typing.NamedTuple):
name: str
@ -76,6 +82,10 @@ class ClaimShortIDKey(typing.NamedTuple):
root_tx_num: int
root_position: int
def __str__(self):
return f"{self.__class__.__name__}(name={self.name}, claim_hash={self.claim_hash.hex()}, " \
f"root_tx_num={self.root_tx_num}, root_position={self.root_position})"
class ClaimShortIDValue(typing.NamedTuple):
tx_num: int
@ -87,10 +97,17 @@ class ClaimToChannelKey(typing.NamedTuple):
tx_num: int
position: int
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, " \
f"tx_num={self.tx_num}, position={self.position})"
class ClaimToChannelValue(typing.NamedTuple):
signing_hash: bytes
def __str__(self):
return f"{self.__class__.__name__}(signing_hash={self.signing_hash.hex()})"
class ChannelToClaimKey(typing.NamedTuple):
signing_hash: bytes
@ -98,16 +115,27 @@ class ChannelToClaimKey(typing.NamedTuple):
tx_num: int
position: int
def __str__(self):
return f"{self.__class__.__name__}(signing_hash={self.signing_hash.hex()}, name={self.name}, " \
f"tx_num={self.tx_num}, position={self.position})"
class ChannelToClaimValue(typing.NamedTuple):
claim_hash: bytes
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
class ClaimToSupportKey(typing.NamedTuple):
claim_hash: bytes
tx_num: int
position: int
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, tx_num={self.tx_num}, " \
f"position={self.position})"
class ClaimToSupportValue(typing.NamedTuple):
amount: int
@ -121,6 +149,9 @@ class SupportToClaimKey(typing.NamedTuple):
class SupportToClaimValue(typing.NamedTuple):
claim_hash: bytes
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
class ClaimExpirationKey(typing.NamedTuple):
expiration: int
@ -132,6 +163,9 @@ class ClaimExpirationValue(typing.NamedTuple):
claim_hash: bytes
name: str
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, name={self.name})"
class ClaimTakeoverKey(typing.NamedTuple):
name: str
@ -141,6 +175,9 @@ class ClaimTakeoverValue(typing.NamedTuple):
claim_hash: bytes
height: int
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, height={self.height})"
class PendingActivationKey(typing.NamedTuple):
height: int
@ -161,6 +198,9 @@ class PendingActivationValue(typing.NamedTuple):
claim_hash: bytes
name: str
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, name={self.name})"
class ActivationKey(typing.NamedTuple):
txo_type: int
@ -173,6 +213,9 @@ class ActivationValue(typing.NamedTuple):
claim_hash: bytes
name: str
def __str__(self):
return f"{self.__class__.__name__}(height={self.height}, claim_hash={self.claim_hash.hex()}, name={self.name})"
class ActiveAmountKey(typing.NamedTuple):
claim_hash: bytes
@ -181,6 +224,10 @@ class ActiveAmountKey(typing.NamedTuple):
tx_num: int
position: int
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, txo_type={self.txo_type}, " \
f"activation_height={self.activation_height}, tx_num={self.tx_num}, position={self.position})"
class ActiveAmountValue(typing.NamedTuple):
amount: int
@ -196,24 +243,40 @@ class EffectiveAmountKey(typing.NamedTuple):
class EffectiveAmountValue(typing.NamedTuple):
claim_hash: bytes
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
class RepostKey(typing.NamedTuple):
claim_hash: bytes
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
class RepostValue(typing.NamedTuple):
reposted_claim_hash: bytes
def __str__(self):
return f"{self.__class__.__name__}(reposted_claim_hash={self.reposted_claim_hash.hex()})"
class RepostedKey(typing.NamedTuple):
reposted_claim_hash: bytes
tx_num: int
position: int
def __str__(self):
return f"{self.__class__.__name__}(reposted_claim_hash={self.reposted_claim_hash.hex()}, " \
f"tx_num={self.tx_num}, position={self.position})"
class RepostedValue(typing.NamedTuple):
claim_hash: bytes
def __str__(self):
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
class ActiveAmountPrefixRow(PrefixRow):
prefix = DB_PREFIXES.active_amount.value

View file

@ -1,4 +1,5 @@
import struct
from string import printable
from collections import OrderedDict, defaultdict
from typing import Tuple, List, Iterable, Callable, Optional
from lbry.wallet.server.db import DB_PREFIXES
@ -59,9 +60,14 @@ class RevertableOp:
return (self.is_put, self.key, self.value) == (other.is_put, other.key, other.value)
def __repr__(self) -> str:
return str(self)
def __str__(self) -> str:
from lbry.wallet.server.db.prefixes import auto_decode_item
k, v = auto_decode_item(self.key, self.value)
return f"{'PUT' if self.is_put else 'DELETE'} {DB_PREFIXES(self.key[:1]).name}: {k} | {v}"
key = ''.join(c if c in printable else '.' for c in str(k))
val = ''.join(c if c in printable else '.' for c in str(v))
return f"{'PUT' if self.is_put else 'DELETE'} {DB_PREFIXES(self.key[:1]).name}: {key} | {val}"
class RevertableDelete(RevertableOp):