cic-cli/cic/token.py

69 lines
1.6 KiB
Python
Raw Normal View History

2021-10-10 14:49:22 +02:00
# standard imports
import os
import json
# local imports
from .base import (
Data,
data_dir,
)
class Token(Data):
2021-10-14 15:43:23 +02:00
def __init__(self, path='.', name=None, symbol=None, precision=1, supply=0, code=None):
2021-10-10 14:49:22 +02:00
super(Token, self).__init__()
self.name = name
self.symbol = symbol
2021-10-14 15:43:23 +02:00
self.supply = supply
2021-10-10 14:49:22 +02:00
self.precision = precision
self.code = code
self.extra_args = None
self.path = path
self.token_path = os.path.join(self.path, 'token.json')
def load(self):
super(Token, self).load()
f = open(self.token_path, 'r')
o = json.load(f)
f.close()
self.name = o['name']
self.symbol = o['symbol']
self.precision = o['precision']
self.code = o['code']
2021-10-12 19:39:18 +02:00
self.supply = o['supply']
2021-10-10 14:49:22 +02:00
self.extra_args = o['extra']
self.inited = True
def start(self):
super(Token, self).load()
token_template_file_path = os.path.join(data_dir, 'token_template_v{}.json'.format(self.version()))
f = open(token_template_file_path)
o = json.load(f)
f.close()
o['name'] = self.name
o['symbol'] = self.symbol
o['precision'] = self.precision
o['code'] = self.code
2021-10-12 19:39:18 +02:00
o['supply'] = self.supply
2021-10-10 14:49:22 +02:00
f = open(self.token_path, 'w')
2021-10-18 10:47:48 +02:00
json.dump(o, f, sort_keys=True, indent="\t")
2021-10-10 14:49:22 +02:00
f.close()
def __str__(self):
s = """name = {}
symbol = {}
precision = {}
""".format(self.name, self.symbol, self.precision)
return s