Add publish cli
This commit is contained in:
@@ -1,12 +1,48 @@
|
||||
# standard imports
|
||||
import os
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
from giftable_erc20_token import GiftableToken
|
||||
from chainlib.eth.tx import (
|
||||
TxFactory,
|
||||
TxFormat,
|
||||
)
|
||||
from chainlib.eth.contract import (
|
||||
ABIContractEncoder,
|
||||
ABIContractType,
|
||||
)
|
||||
|
||||
|
||||
# local imports
|
||||
from ge_capped_token.data import data_dir
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
class CappedToken(GiftableToken):
|
||||
|
||||
__abi = None
|
||||
__bytecode = None
|
||||
|
||||
def constructor(self, sender_address, name, symbol, decimals, tx_format=TxFormat.JSONRPC, version=None):
|
||||
code = self.cargs(name, symbol, decimals)
|
||||
tx = self.template(sender_address, None, use_nonce=True)
|
||||
tx = self.set_code(tx, code)
|
||||
return self.finalize(tx, tx_format)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def cargs(name, symbol, decimals, version=None):
|
||||
code = CappedToken.bytecode(version=version)
|
||||
enc = ABIContractEncoder()
|
||||
enc.string(name)
|
||||
enc.string(symbol)
|
||||
enc.uint256(decimals)
|
||||
args = enc.get()
|
||||
code += args
|
||||
logg.debug('constructor code: ' + args)
|
||||
return code
|
||||
|
||||
@staticmethod
|
||||
def abi():
|
||||
if CappedToken.__abi == None:
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
109
python/ge_capped_token/runnable/publish.py
Normal file
109
python/ge_capped_token/runnable/publish.py
Normal file
@@ -0,0 +1,109 @@
|
||||
#!python3
|
||||
|
||||
"""Deploys capped token
|
||||
|
||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||
|
||||
"""
|
||||
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# standard imports
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import argparse
|
||||
import logging
|
||||
import time
|
||||
from enum import Enum
|
||||
|
||||
# external imports
|
||||
import chainlib.eth.cli
|
||||
from chainlib.eth.tx import receipt
|
||||
from chainlib.settings import ChainSettings
|
||||
from chainlib.eth.cli.log import process_log
|
||||
from chainlib.eth.settings import process_settings
|
||||
from chainlib.eth.cli.arg import (
|
||||
Arg,
|
||||
ArgFlag,
|
||||
process_args,
|
||||
)
|
||||
from chainlib.eth.cli.config import (
|
||||
Config,
|
||||
process_config,
|
||||
)
|
||||
|
||||
|
||||
# local imports
|
||||
from ge_capped_token import CappedToken
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def process_config_local(config, arg, args, flags):
|
||||
config.add(args.token_name, '_TOKEN_NAME', False)
|
||||
config.add(args.token_symbol, '_TOKEN_SYMBOL', False)
|
||||
config.add(args.token_decimals, '_TOKEN_DECIMALS', False)
|
||||
return config
|
||||
|
||||
|
||||
arg_flags = ArgFlag()
|
||||
arg = Arg(arg_flags)
|
||||
flags = arg_flags.STD_WRITE | arg_flags.WALLET
|
||||
|
||||
argparser = chainlib.eth.cli.ArgumentParser()
|
||||
argparser = process_args(argparser, arg, flags)
|
||||
argparser.add_argument('--name', dest='token_name', required=True, type=str, help='Token name')
|
||||
argparser.add_argument('--symbol', dest='token_symbol', required=True, type=str, help='Token symbol')
|
||||
argparser.add_argument('--decimals', dest='token_decimals', default=18, type=int, help='Token decimals')
|
||||
args = argparser.parse_args()
|
||||
|
||||
logg = process_log(args, logg)
|
||||
|
||||
config = Config()
|
||||
config = process_config(config, arg, args, flags)
|
||||
config = process_config_local(config, arg, args, flags)
|
||||
logg.debug('config loaded:\n{}'.format(config))
|
||||
|
||||
settings = ChainSettings()
|
||||
settings = process_settings(settings, config)
|
||||
logg.debug('settings loaded:\n{}'.format(settings))
|
||||
|
||||
|
||||
def main():
|
||||
signer_address = settings.get('SENDER_ADDRESS')
|
||||
conn = settings.get('CONN')
|
||||
|
||||
c = CappedToken(
|
||||
settings.get('CHAIN_SPEC'),
|
||||
signer=settings.get('SIGNER'),
|
||||
gas_oracle=settings.get('GAS_ORACLE'),
|
||||
nonce_oracle=settings.get('NONCE_ORACLE'),
|
||||
)
|
||||
|
||||
(tx_hash_hex, o) = c.constructor(
|
||||
signer_address,
|
||||
config.get('_TOKEN_NAME'),
|
||||
config.get('_TOKEN_SYMBOL'),
|
||||
config.get('_TOKEN_DECIMALS'),
|
||||
)
|
||||
if settings.get('RPC_SEND'):
|
||||
conn.do(o)
|
||||
if settings.get('WAIT'):
|
||||
r = conn.wait(tx_hash_hex)
|
||||
if r['status'] == 0:
|
||||
sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
|
||||
sys.exit(1)
|
||||
# TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
|
||||
address = r['contractAddress']
|
||||
|
||||
print(address)
|
||||
else:
|
||||
print(tx_hash_hex)
|
||||
else:
|
||||
print(o)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -17,8 +17,6 @@ logg = logging.getLogger(__name__)
|
||||
|
||||
class TestCappedToken(EthTesterCase):
|
||||
|
||||
expire = 0
|
||||
|
||||
def setUp(self):
|
||||
super(TestCappedToken, self).setUp()
|
||||
self.conn = RPCConnection.connect(self.chain_spec, 'default')
|
||||
@@ -27,7 +25,7 @@ class TestCappedToken(EthTesterCase):
|
||||
self.symbol = 'FOO'
|
||||
self.name = 'Foo Token'
|
||||
self.decimals = 16
|
||||
(tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals, expire=self.expire)
|
||||
(tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals)
|
||||
self.rpc.do(o)
|
||||
o = receipt(tx_hash)
|
||||
r = self.rpc.do(o)
|
||||
@@ -37,15 +35,7 @@ class TestCappedToken(EthTesterCase):
|
||||
|
||||
self.initial_supply = 1 << 40
|
||||
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], self.initial_supply)
|
||||
r = self.conn.do(o)
|
||||
self.conn.do(o)
|
||||
o = receipt(tx_hash)
|
||||
r = self.conn.do(o)
|
||||
self.assertEqual(r['status'], 1)
|
||||
|
||||
|
||||
class TestCappedExpireToken(TestCappedToken):
|
||||
|
||||
expire = int(time.time()) + 100000
|
||||
|
||||
def setUp(self):
|
||||
super(TestCappedExpireToken, self).setUp()
|
||||
|
||||
Reference in New Issue
Block a user