Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper script for adding new tokens. #4

Open
wants to merge 1 commit into
base: beos-initial-release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions cd-scripts/add_token.py
Original file line number Diff line number Diff line change
@@ -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))
19 changes: 19 additions & 0 deletions cd-scripts/eosio_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.):
Expand Down