pretty print
This commit is contained in:
parent
bb2a34dd6b
commit
bfb9d696d7
2 changed files with 70 additions and 1 deletions
|
@ -48,6 +48,9 @@ class PrefixRow:
|
||||||
class ClaimToTXOKey(typing.NamedTuple):
|
class ClaimToTXOKey(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
|
||||||
|
|
||||||
|
|
||||||
class ClaimToTXOValue(typing.NamedTuple):
|
class ClaimToTXOValue(typing.NamedTuple):
|
||||||
tx_num: int
|
tx_num: int
|
||||||
|
@ -69,6 +72,9 @@ class TXOToClaimValue(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, name={self.name})"
|
||||||
|
|
||||||
|
|
||||||
class ClaimShortIDKey(typing.NamedTuple):
|
class ClaimShortIDKey(typing.NamedTuple):
|
||||||
name: str
|
name: str
|
||||||
|
@ -76,6 +82,10 @@ class ClaimShortIDKey(typing.NamedTuple):
|
||||||
root_tx_num: int
|
root_tx_num: int
|
||||||
root_position: 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):
|
class ClaimShortIDValue(typing.NamedTuple):
|
||||||
tx_num: int
|
tx_num: int
|
||||||
|
@ -87,10 +97,17 @@ class ClaimToChannelKey(typing.NamedTuple):
|
||||||
tx_num: int
|
tx_num: int
|
||||||
position: 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):
|
class ClaimToChannelValue(typing.NamedTuple):
|
||||||
signing_hash: bytes
|
signing_hash: bytes
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(signing_hash={self.signing_hash.hex()})"
|
||||||
|
|
||||||
|
|
||||||
class ChannelToClaimKey(typing.NamedTuple):
|
class ChannelToClaimKey(typing.NamedTuple):
|
||||||
signing_hash: bytes
|
signing_hash: bytes
|
||||||
|
@ -98,16 +115,27 @@ class ChannelToClaimKey(typing.NamedTuple):
|
||||||
tx_num: int
|
tx_num: int
|
||||||
position: 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):
|
class ChannelToClaimValue(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
|
||||||
|
|
||||||
|
|
||||||
class ClaimToSupportKey(typing.NamedTuple):
|
class ClaimToSupportKey(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
tx_num: int
|
tx_num: int
|
||||||
position: 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):
|
class ClaimToSupportValue(typing.NamedTuple):
|
||||||
amount: int
|
amount: int
|
||||||
|
@ -121,6 +149,9 @@ class SupportToClaimKey(typing.NamedTuple):
|
||||||
class SupportToClaimValue(typing.NamedTuple):
|
class SupportToClaimValue(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
|
||||||
|
|
||||||
|
|
||||||
class ClaimExpirationKey(typing.NamedTuple):
|
class ClaimExpirationKey(typing.NamedTuple):
|
||||||
expiration: int
|
expiration: int
|
||||||
|
@ -132,6 +163,9 @@ class ClaimExpirationValue(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, name={self.name})"
|
||||||
|
|
||||||
|
|
||||||
class ClaimTakeoverKey(typing.NamedTuple):
|
class ClaimTakeoverKey(typing.NamedTuple):
|
||||||
name: str
|
name: str
|
||||||
|
@ -141,6 +175,9 @@ class ClaimTakeoverValue(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
height: int
|
height: int
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, height={self.height})"
|
||||||
|
|
||||||
|
|
||||||
class PendingActivationKey(typing.NamedTuple):
|
class PendingActivationKey(typing.NamedTuple):
|
||||||
height: int
|
height: int
|
||||||
|
@ -161,6 +198,9 @@ class PendingActivationValue(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()}, name={self.name})"
|
||||||
|
|
||||||
|
|
||||||
class ActivationKey(typing.NamedTuple):
|
class ActivationKey(typing.NamedTuple):
|
||||||
txo_type: int
|
txo_type: int
|
||||||
|
@ -173,6 +213,9 @@ class ActivationValue(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
name: str
|
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):
|
class ActiveAmountKey(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
|
@ -181,6 +224,10 @@ class ActiveAmountKey(typing.NamedTuple):
|
||||||
tx_num: int
|
tx_num: int
|
||||||
position: 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):
|
class ActiveAmountValue(typing.NamedTuple):
|
||||||
amount: int
|
amount: int
|
||||||
|
@ -196,24 +243,40 @@ class EffectiveAmountKey(typing.NamedTuple):
|
||||||
class EffectiveAmountValue(typing.NamedTuple):
|
class EffectiveAmountValue(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
|
||||||
|
|
||||||
|
|
||||||
class RepostKey(typing.NamedTuple):
|
class RepostKey(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
|
||||||
|
|
||||||
|
|
||||||
class RepostValue(typing.NamedTuple):
|
class RepostValue(typing.NamedTuple):
|
||||||
reposted_claim_hash: bytes
|
reposted_claim_hash: bytes
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(reposted_claim_hash={self.reposted_claim_hash.hex()})"
|
||||||
|
|
||||||
|
|
||||||
class RepostedKey(typing.NamedTuple):
|
class RepostedKey(typing.NamedTuple):
|
||||||
reposted_claim_hash: bytes
|
reposted_claim_hash: bytes
|
||||||
tx_num: int
|
tx_num: int
|
||||||
position: 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):
|
class RepostedValue(typing.NamedTuple):
|
||||||
claim_hash: bytes
|
claim_hash: bytes
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.__class__.__name__}(claim_hash={self.claim_hash.hex()})"
|
||||||
|
|
||||||
|
|
||||||
class ActiveAmountPrefixRow(PrefixRow):
|
class ActiveAmountPrefixRow(PrefixRow):
|
||||||
prefix = DB_PREFIXES.active_amount.value
|
prefix = DB_PREFIXES.active_amount.value
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import struct
|
import struct
|
||||||
|
from string import printable
|
||||||
from collections import OrderedDict, defaultdict
|
from collections import OrderedDict, defaultdict
|
||||||
from typing import Tuple, List, Iterable, Callable, Optional
|
from typing import Tuple, List, Iterable, Callable, Optional
|
||||||
from lbry.wallet.server.db import DB_PREFIXES
|
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)
|
return (self.is_put, self.key, self.value) == (other.is_put, other.key, other.value)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
return str(self)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
from lbry.wallet.server.db.prefixes import auto_decode_item
|
from lbry.wallet.server.db.prefixes import auto_decode_item
|
||||||
k, v = auto_decode_item(self.key, self.value)
|
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):
|
class RevertableDelete(RevertableOp):
|
||||||
|
|
Loading…
Reference in a new issue