From b28445016d1bbe6cd3136c0ff9637b00038132c5 Mon Sep 17 00:00:00 2001 From: Dariusz Kedzierski Date: Wed, 10 Jul 2019 16:43:57 +0200 Subject: [PATCH] Script for adding new token --- cd-scripts/add_token.py | 45 +++++++++++++++++++++++++++++++++++++ cd-scripts/eosio_actions.py | 19 ++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 cd-scripts/add_token.py diff --git a/cd-scripts/add_token.py b/cd-scripts/add_token.py new file mode 100755 index 00000000000..bd1fe69811f --- /dev/null +++ b/cd-scripts/add_token.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 +import eosio_actions +import json + +# This is helper script for adding new tokens. +# Usage: +# +# ./add_token.py --total-supply 10000000000.0000 --token-code TESTS --token-description tests +# +# Default values are: +# --total-supply 10000000000.0000 +# --token-code BTSMD +# --token-description btsmd +# +# So it is possible to use this script simply by calling: +# ./add_token.py +# this call is equall calling: +# ./add_token.py --total-supply 10000000000.0000 --token-code BTSMD --token-description btsmd +# + +if __name__ == "__main__": + import argparse + description = "This is helper script for adding new tokens. Usage: ./add_token.py --total-supply 10000000000.0000 --token-code TESTS --token-description tests" + parser = argparse.ArgumentParser(description=description) + parser.add_argument("--total-supply", dest="total_suply", default="10000000000.0000", type=str, help="Total supply of the token (without code)") + parser.add_argument("--token-code", dest="token_code", default="BTSMD", type=str, help="Token code") + parser.add_argument("--token-description", dest="token_description", default="btsmd", type=str, help="Token description") + + args = parser.parse_args() + try: + #./cleos push action eosio.token create '["beos.gateway", "10000000000.0000 BTSMD"]' -p eosio.token + eosio_actions.push_action("eosio.token", "create", '[ "beos.gateway", "{0} {1}"]'.format(args.total_suply, args.token_code), "eosio.token") + + #./cleos get table beos.gateway beos.gateway gatewaystate + output = eosio_actions.get_table('beos.gateway', 'beos.gateway', 'gatewaystate') + new_params = None + if 'rows' in output: + if len(output['rows']) > 0 and 'proxy_assets' in output['rows'][0]: + new_params = output['rows'][0] + new_params['proxy_assets'].append({'proxy_asset' : '{} {}'.format(args.total_suply, args.token_code), 'description' : '{}'.format(args.token_description)}) + + #./cleos push action beos.gateway changeparams '{"new_params": {"proxy_assets":[{"proxy_asset":"10000000000.0000 BTS","description":"bts"},{"proxy_asset":"10000000000.0000 BRNP","description":"brownie.pts"},{"proxy_asset":"10000000000.0000 EOS","description":"eos"},{"proxy_asset":"10000000000.0000 BTSMD","description":"btsmd"}]} }' -p beos.gateway + eosio_actions.push_action("beos.gateway", "changeparams", '{{"new_params": {0}}}'.format(json.dumps(new_params)), "beos.gateway") + except Exception as ex: + print("Error during upgrade {}".format(ex)) \ No newline at end of file diff --git a/cd-scripts/eosio_actions.py b/cd-scripts/eosio_actions.py index e53debb28de..ef995106f8e 100644 --- a/cd-scripts/eosio_actions.py +++ b/cd-scripts/eosio_actions.py @@ -227,6 +227,25 @@ def get_account(_account_name, schema = "http"): logger.info("Executing command: {0}".format(" ".join(parameters))) logger.info(json.dumps(json.loads(eosio_tools.run_command_and_return_output(parameters)),indent=2,separators=(',', ': '))) +def get_table(account, scope, table, schema = "http"): + parameters = [ + config.CLEOS_EXECUTABLE, + ] + + if config.LOG_LEVEL == logging.DEBUG: + parameters = parameters + [ + "--print-request", + "--print-response", + ] + + parameters = parameters + [ + "--url", "{0}://{1}:{2}".format(schema, config.NODEOS_IP_ADDRESS, config.NODEOS_PORT), + "--wallet-url", "{0}://{1}:{2}".format(schema, config.KEOSD_IP_ADDRESS, config.KEOSD_PORT), + "get", "table", account, scope, table + ] + logger.info("Executing command: {0}".format(" ".join(parameters))) + return json.loads(eosio_tools.run_command_and_return_output(parameters)) + BLOCK_TYPE_HEADBLOCK = "head_block_num" BLOCK_TYPE_IRREVERSIBLE = "last_irreversible_block_num" def block_until_transaction_in_block(transaction_id, block_num, block_type = BLOCK_TYPE_HEADBLOCK, timeout = 60.):