mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-17 22:20:22 -04:00
💾
This commit is contained in:
parent
0696b08d04
commit
314bdf533e
94 changed files with 11 additions and 7 deletions
|
@ -1,40 +0,0 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
# This class implements string methods used by the other classes.
|
||||
# author: steinkirch
|
||||
|
||||
from pprint import PrettyPrinter
|
||||
|
||||
from utils.os import log_error
|
||||
from utils.arithmetics import to_decimal
|
||||
|
||||
|
||||
def to_decimal_str(value) -> str:
|
||||
"""Format a reserve amount to a suitable string."""
|
||||
|
||||
return str(to_decimal(value))
|
||||
|
||||
|
||||
def to_wei_str(value, decimals=None) -> str:
|
||||
"""Parse an order string to wei value."""
|
||||
|
||||
decimals = decimals or 18
|
||||
try:
|
||||
return str(value)[:-decimals] + '_' + str(value)[-decimals:]
|
||||
except ValueError as e:
|
||||
log_error(f'Cannot convert to wei: {e}')
|
||||
|
||||
|
||||
def to_solution(value) -> str:
|
||||
"""Format decimal wei with an underscore for easier reading."""
|
||||
|
||||
return to_wei_str(to_decimal_str(value))
|
||||
|
||||
|
||||
def pprint(data, indent=None) -> None:
|
||||
"""Print dicts and data in a suitable format"""
|
||||
|
||||
print()
|
||||
indent = indent or 4
|
||||
pp = PrettyPrinter(indent=indent)
|
||||
pp.pprint(data)
|
||||
print()
|
Loading…
Add table
Add a link
Reference in a new issue