mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-18 14:40:25 -04:00
clean up and add web3
This commit is contained in:
parent
a0cfa09ec4
commit
fc8d690a51
29 changed files with 3043 additions and 31 deletions
40
web3_python_toolkit/scripts/utils/strings.py
Normal file
40
web3_python_toolkit/scripts/utils/strings.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
# -*- 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