Add supply / mint step

This commit is contained in:
nolash 2021-10-12 19:39:18 +02:00
parent 95483d4c79
commit ab4976d809
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 21 additions and 5 deletions

View File

@ -3,6 +3,6 @@
"symbol": "",
"precision": 0,
"code": null,
"supply": 0,
"extra": {}
}

View File

@ -25,6 +25,7 @@ from hexathon import add_0x
from eth_token_index import TokenUniqueSymbolIndex
from eth_address_declarator import Declarator
from eth_address_declarator.declarator import AddressDeclarator
from giftable_erc20_token import GiftableToken
# local imports
from cic.ext.eth.rpc import parse_adapter
@ -155,10 +156,22 @@ class CICEth(Extension):
if r == None:
r = code
writer.write('token_address', self.token_address.encode('utf-8'))
writer.write('token', r.encode('utf-8'))
writer.write('token_address', self.token_address.encode('utf-8'))
self.add_outputs('token', r.encode('utf-8'))
if self.token_details['supply'] > 0:
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=self.fee_oracle)
o = c.mint_to(self.token_address, self.resources['token']['key_account'], self.resources['token']['key_account'], self.token_details['supply'])
r = None
if self.rpc != None:
r = self.rpc.do(o[1])
self.rpc.wait(r)
elif self.signer != None:
r = o[1]
else:
r = o
writer.write('token_supply', r.encode('utf-8'))
return r

View File

@ -23,15 +23,16 @@ class Extension:
# TODO: apply / prepare token can be factored out
def apply_token(self, token):
return self.prepare_token(token.name, token.symbol, token.precision, token.code)
return self.prepare_token(token.name, token.symbol, token.precision, token.code, token.supply)
def prepare_token(self, name, symbol, precision, code, extra=[], extra_types=[], positions=None):
def prepare_token(self, name, symbol, precision, code, supply, extra=[], extra_types=[], positions=None):
self.token_details = {
'name': name,
'symbol': symbol,
'precision': precision,
'code': code,
'supply': supply,
'extra': extra,
'extra_types': extra_types,
'positions': positions,

View File

@ -33,6 +33,7 @@ class Token(Data):
self.symbol = o['symbol']
self.precision = o['precision']
self.code = o['code']
self.supply = o['supply']
self.extra_args = o['extra']
self.inited = True
@ -51,6 +52,7 @@ class Token(Data):
o['symbol'] = self.symbol
o['precision'] = self.precision
o['code'] = self.code
o['supply'] = self.supply
f = open(self.token_path, 'w')
json.dump(o, f)