Use explicit pre-release signer
This commit is contained in:
		
							parent
							
								
									0e1613c5f6
								
							
						
					
					
						commit
						43b3d2b488
					
				@ -28,8 +28,10 @@ from chainlib.eth.gas import (
 | 
			
		||||
from chainlib.eth.connection import EthHTTPConnection
 | 
			
		||||
from chainlib.eth.tx import receipt
 | 
			
		||||
from chainlib.eth.constant import ZERO_ADDRESS
 | 
			
		||||
import chainlib.eth.cli
 | 
			
		||||
 | 
			
		||||
# local imports
 | 
			
		||||
import erc20_demurrage_token
 | 
			
		||||
from erc20_demurrage_token import (
 | 
			
		||||
        DemurrageToken,
 | 
			
		||||
        DemurrageTokenSettings,
 | 
			
		||||
@ -41,57 +43,37 @@ logg = logging.getLogger()
 | 
			
		||||
script_dir = os.path.dirname(__file__)
 | 
			
		||||
data_dir = os.path.join(script_dir, '..', 'data')
 | 
			
		||||
 | 
			
		||||
default_config_dir = os.environ.get('CONFINI_DIR', os.path.join(data_dir, 'config'))
 | 
			
		||||
config_dir = os.path.join(data_dir, 'config')
 | 
			
		||||
 | 
			
		||||
argparser = argparse.ArgumentParser()
 | 
			
		||||
argparser.add_argument('-c', '--config', dest='c', type=str, default=default_config_dir, help='configuration directory')
 | 
			
		||||
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
 | 
			
		||||
argparser.add_argument('-w', action='store_true', help='Wait for the last transaction to be confirmed')
 | 
			
		||||
argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
 | 
			
		||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string')
 | 
			
		||||
argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
 | 
			
		||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
 | 
			
		||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
 | 
			
		||||
argparser.add_argument('-d', action='store_true', help='Dump RPC calls to terminal and do not send')
 | 
			
		||||
argparser.add_argument('--name', type=str, help='Token name')
 | 
			
		||||
argparser.add_argument('--decimals', default=6, type=int, help='Token decimals')
 | 
			
		||||
argparser.add_argument('--gas-price', type=int, dest='gas_price', help='Override gas price')
 | 
			
		||||
argparser.add_argument('--nonce', type=int, help='Override transaction nonce')
 | 
			
		||||
arg_flags = chainlib.eth.cli.argflag_std_write
 | 
			
		||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
 | 
			
		||||
argparser.add_argument('--name', dest='token_name', 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')
 | 
			
		||||
argparser.add_argument('--sink-address', dest='sink_address', default=ZERO_ADDRESS, type=str, help='demurrage level,ppm per minute') 
 | 
			
		||||
argparser.add_argument('--supply-limit', dest='supply_limit', type=int, help='token supply limit (0 = no limit)')
 | 
			
		||||
argparser.add_argument('--redistribution-period', type=int, help='redistribution period, minutes (0 = deactivate)') # default 10080 = week
 | 
			
		||||
argparser.add_argument('--multi', action='store_true', help='automatic redistribution')
 | 
			
		||||
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
 | 
			
		||||
argparser.add_argument('--symbol', type=str, help='Token symbol')
 | 
			
		||||
argparser.add_argument('--demurrage-level', dest='demurrage_level', type=int, help='demurrage level, ppm per minute') 
 | 
			
		||||
args = argparser.parse_args()
 | 
			
		||||
 | 
			
		||||
if args.vv:
 | 
			
		||||
    logg.setLevel(logging.DEBUG)
 | 
			
		||||
elif args.v:
 | 
			
		||||
    logg.setLevel(logging.INFO)
 | 
			
		||||
arg_flags = chainlib.eth.cli.argflag_std_write
 | 
			
		||||
 | 
			
		||||
block_all = args.ww
 | 
			
		||||
block_last = args.w or block_all
 | 
			
		||||
 | 
			
		||||
# process config
 | 
			
		||||
config = confini.Config(args.c)
 | 
			
		||||
config.process()
 | 
			
		||||
args_override = {
 | 
			
		||||
            'TOKEN_REDISTRIBUTION_PERIOD': getattr(args, 'redistribution_period'),
 | 
			
		||||
            'TOKEN_DEMURRAGE_LEVEL': getattr(args, 'demurrage_level'),
 | 
			
		||||
            'TOKEN_SUPPLY_LIMIT': getattr(args, 'supply_limit'),
 | 
			
		||||
            'TOKEN_SYMBOL': getattr(args, 'symbol'),
 | 
			
		||||
            'TOKEN_NAME': getattr(args, 'name'),
 | 
			
		||||
            'TOKEN_DECIMALS': getattr(args, 'decimals'),
 | 
			
		||||
            'TOKEN_SINK_ADDRESS': getattr(args, 'sink_address'),
 | 
			
		||||
            'SESSION_CHAIN_SPEC': getattr(args, 'i'),
 | 
			
		||||
            'ETH_PROVIDER': getattr(args, 'p'),
 | 
			
		||||
extra_args = {
 | 
			
		||||
        'redistribution_period': 'TOKEN_REDISTRIBUTION_PERIOD',
 | 
			
		||||
        'demurrage_level': 'TOKEN_DEMURRAGE_LEVEL',
 | 
			
		||||
        'supply_limit': 'TOKEN_SUPPLY_LIMIT',
 | 
			
		||||
        'token_name': 'TOKEN_NAME',
 | 
			
		||||
        'token_symbol': 'TOKEN_SYMBOL',
 | 
			
		||||
        'token_decimals': 'TOKEN_DECIMALS',
 | 
			
		||||
        'sink_address': 'TOKEN_SINK_ADDRESS',
 | 
			
		||||
        'multi': None,
 | 
			
		||||
        }
 | 
			
		||||
if config.get('TOKEN_NAME') == None:
 | 
			
		||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_fee_limit=DemurrageToken.gas(), base_config_dir=config_dir)
 | 
			
		||||
 | 
			
		||||
if not bool(config.get('TOKEN_NAME')):
 | 
			
		||||
    logg.info('token name not set, using symbol {} as name'.format(config.get('TOKEN_SYMBOL')))
 | 
			
		||||
    config.add(config.get('TOKEN_SYMBOL'), 'TOKEN_NAME', True)
 | 
			
		||||
config.dict_override(args_override, 'cli args')
 | 
			
		||||
 | 
			
		||||
if config.get('TOKEN_SUPPLY_LIMIT') == None:
 | 
			
		||||
    config.add(0, 'TOKEN_SUPPLY_LIMIT', True)
 | 
			
		||||
@ -100,46 +82,22 @@ if config.get('TOKEN_REDISTRIBUTION_PERIOD') == None:
 | 
			
		||||
    config.add(10800, 'TOKEN_REDISTRIBUTION_PERIOD', True)
 | 
			
		||||
logg.debug('config loaded:\n{}'.format(config))
 | 
			
		||||
 | 
			
		||||
passphrase_env = 'ETH_PASSPHRASE'
 | 
			
		||||
if args.env_prefix != None:
 | 
			
		||||
    passphrase_env = args.env_prefix + '_' + passphrase_env
 | 
			
		||||
passphrase = os.environ.get(passphrase_env)
 | 
			
		||||
if passphrase == None:
 | 
			
		||||
    logg.warning('no passphrase given')
 | 
			
		||||
    passphrase=''
 | 
			
		||||
wallet = chainlib.eth.cli.Wallet()
 | 
			
		||||
wallet.from_config(config)
 | 
			
		||||
 | 
			
		||||
signer_address = None
 | 
			
		||||
keystore = DictKeystore()
 | 
			
		||||
if args.y != None:
 | 
			
		||||
    logg.debug('loading keystore file {}'.format(args.y))
 | 
			
		||||
    signer_address = keystore.import_keystore_file(args.y, password=passphrase)
 | 
			
		||||
    logg.debug('now have key for signer address {}'.format(signer_address))
 | 
			
		||||
signer = EIP155Signer(keystore)
 | 
			
		||||
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
 | 
			
		||||
conn = rpc.connect_by_config(config)
 | 
			
		||||
 | 
			
		||||
chain_spec = ChainSpec.from_chain_str(args.i)
 | 
			
		||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
 | 
			
		||||
 | 
			
		||||
rpc = EthHTTPConnection(args.p)
 | 
			
		||||
nonce_oracle = None
 | 
			
		||||
if args.nonce != None:
 | 
			
		||||
    nonce_oracle = OverrideNonceOracle(signer_address, args.nonce)
 | 
			
		||||
else:
 | 
			
		||||
    nonce_oracle = RPCNonceOracle(signer_address, rpc)
 | 
			
		||||
 | 
			
		||||
gas_oracle = None
 | 
			
		||||
if args.gas_price !=None:
 | 
			
		||||
    gas_oracle = OverrideGasOracle(price=args.gas_price, conn=rpc, code_callback=DemurrageToken.gas)
 | 
			
		||||
else:
 | 
			
		||||
    gas_oracle = RPCGasOracle(rpc, code_callback=DemurrageToken.gas)
 | 
			
		||||
 | 
			
		||||
dummy = args.d
 | 
			
		||||
 | 
			
		||||
token_name = args.name
 | 
			
		||||
if token_name == None:
 | 
			
		||||
    token_name = args.symbol
 | 
			
		||||
 | 
			
		||||
multi = bool(args.multi)
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
    signer = rpc.get_signer()
 | 
			
		||||
    signer_address = rpc.get_sender_address()
 | 
			
		||||
 | 
			
		||||
    gas_oracle = rpc.get_gas_oracle()
 | 
			
		||||
    nonce_oracle = rpc.get_nonce_oracle()
 | 
			
		||||
 | 
			
		||||
    c = DemurrageToken(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
 | 
			
		||||
    settings = DemurrageTokenSettings()
 | 
			
		||||
    settings.name = config.get('TOKEN_NAME')
 | 
			
		||||
@ -152,17 +110,13 @@ def main():
 | 
			
		||||
    (tx_hash_hex, o) = c.constructor(
 | 
			
		||||
            signer_address,
 | 
			
		||||
            settings,
 | 
			
		||||
            #redistribute=settings.period_minutes > 0,
 | 
			
		||||
            redistribute=multi,
 | 
			
		||||
            redistribute=config.true('_MULTI'),
 | 
			
		||||
            cap=int(config.get('TOKEN_SUPPLY_LIMIT')),
 | 
			
		||||
            )
 | 
			
		||||
    if dummy:
 | 
			
		||||
        print(tx_hash_hex)
 | 
			
		||||
        print(o)
 | 
			
		||||
    else:
 | 
			
		||||
        rpc.do(o)
 | 
			
		||||
        if block_last:
 | 
			
		||||
            r = rpc.wait(tx_hash_hex)
 | 
			
		||||
    if config.get('_RPC_SEND'):
 | 
			
		||||
        conn.do(o)
 | 
			
		||||
        if config.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)
 | 
			
		||||
@ -173,6 +127,9 @@ def main():
 | 
			
		||||
        else:
 | 
			
		||||
            print(tx_hash_hex)
 | 
			
		||||
 | 
			
		||||
    else:
 | 
			
		||||
        print(o)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    main()
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,3 @@
 | 
			
		||||
chainlib>=0.0.7a1,<=0.1.0
 | 
			
		||||
eth-erc20>=0.0.12a1,<0.1.0
 | 
			
		||||
crypto-dev-signer>=0.4.14b7,<=0.4.14
 | 
			
		||||
chainlib>=0.0.9a3,<=0.1.0
 | 
			
		||||
eth-erc20>=0.1.2a1,<0.2.0
 | 
			
		||||
crypto-dev-signer>=0.4.15a1,<=0.4.15
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ done
 | 
			
		||||
modes=(SingleCap) # other contracts need to be updted
 | 
			
		||||
for m in ${modes[@]}; do
 | 
			
		||||
	ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_period.py
 | 
			
		||||
	ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_redistribution_unit.py
 | 
			
		||||
#	ERC20_DEMURRAGE_TOKEN_TEST_MODE=$m python tests/test_redistribution_unit.py
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
modes=(MultiCap SingleCap)
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
[metadata]
 | 
			
		||||
name = erc20-demurrage-token
 | 
			
		||||
version = 0.0.3a1
 | 
			
		||||
version = 0.0.5a2
 | 
			
		||||
description = ERC20 token with redistributed continual demurrage
 | 
			
		||||
author = Louis Holbrook
 | 
			
		||||
author_email = dev@holbrook.no
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user