def deploy_micropython_contract(self): logger.info("++++++++deploy_micropython_contract") code_path = os.path.join( self.cur_dir, './contracts/micropython/micropython_uuos.wasm') code_path = os.path.join(self.cur_dir, './contracts/micropython/micropython.wasm') abi_path = os.path.join(self.cur_dir, './contracts/micropython/micropython.abi') code = open(code_path, 'rb').read() abi = open(abi_path, 'rb').read() try: pass #r = eosapi.deploy_contract('hello', code, abi, vm_type=0, compress=True) #r = eosapi.deploy_contract('eosio.mpy', code, abi, vm_type=0, compress=True) except Exception as e: logger.exception(e) return code = ''' def apply(a, b, c): pass ''' account = 'hello' code = eosapi.mp_compile(account, code) account = 'hello' args = eosapi.s2b(account) + code eosapi.push_action(account, 'setcode', args, {account: 'active'}) account = 'eosio.mpy' args = eosapi.s2b(account) + code eosapi.push_action(account, 'setcode', args, {account: 'active'})
def test_push_actions(self): args = { 'from': 'helloworld11', 'to': 'helloworld12', 'quantity': '0.0100 EOS', 'memo': 'hello' } a1 = ['eosio.token', 'transfer', args, {'helloworld11': 'active'}] args = { 'from': 'helloworld12', 'to': 'helloworld11', 'quantity': '0.0100 EOS', 'memo': 'hello' } a2 = ['eosio.token', 'transfer', args, {'helloworld12': 'active'}] balance1 = eosapi.get_balance('helloworld11') r = eosapi.push_actions([a1, a2]) balance2 = eosapi.get_balance('helloworld11') logger.info('+++++%s, %s\n', balance1, balance2) try: eosapi.push_action('token', 'transfer', args, {'helloworld11': 'active'}) except Exception as e: assert e.args[0].find('abi struct not found for token::transfer') >= 0 #test for comporessed transaction eosapi.push_action('eosio.token', 'transfer', args, {'helloworld12': 'active'}, compress=True)
def init_producer(self): if self.single_node: return a = eosapi.get_producers(True, '0', 10) logger.info(a) if len(a['rows']) > 1: return logger.info('++++++register producers...') index = 0 for p in self.producer_accounts: args = { "producer": p, "producer_key": self.producer_keys[index]['public'], "url": '', "location": 0 } eosapi.push_action('eosio', 'regproducer', args, {p: 'active'}) index += 1 logger.info('+++++++vote producers...') args = {"voter": '', "proxy": '', "producers": self.producer_accounts} for account in self.test_accounts: args['voter'] = account eosapi.push_action('eosio', 'voteproducer', args, {account: 'active'})
def test_1sign_transaction(self): eosapi.set_node('http://127.0.0.1:9000') args = { 'from': 'helloworld11', 'to': 'b', 'quantity': '1.0000 EOS', 'memo': 'hello' } eosapi.push_action('eosio.token', 'transfer', args, {'helloworld11': 'active'}, indexes=[0])
def run_test_code(code, abi='', account_name='helloworld11'): publish_contract(account_name, code, abi) try: r = eosapi.push_action(account_name, 'sayhello', b'hello,world', {account_name:'active'}) print(r['processed']['action_traces'][0]['console']) except Exception as e: print(e)
def set_code(account_name, code): m = hashlib.sha256() code = compile(code, "contract", 'exec') code = marshal.dumps(code) m.update(code) code_hash = m.hexdigest() r = eosapi.get_code(account_name) if code_hash == r['code_hash']: return setcode = {"account":account_name, "vmtype": 1, "vmversion":0, "code":code.hex() } eosapi.push_action('eosio', 'setcode', setcode, {account_name:'active'}) return True
def test_deploy_python_code_sync(self): eosapi.set_node('http://127.0.0.1:9000') code = ''' import chain def apply(a, b, c): data = chain.read_action_data() print(data) ''' account = 'helloworld11' config.python_contract = account code = eosapi.mp_compile(account, code) eosapi.deploy_python_contract(account, code, b'') r = eosapi.push_action(account, 'sayhello', b'hellooo,world', {account:'active'}) console = r['processed']['action_traces'][0]['console'] logger.info(console) assert console == "b'hellooo,world'\r\n" r = eosapi.push_action(account, 'sayhello', b'goodbye,world', {account:'active'}) console = r['processed']['action_traces'][0]['console'] logger.info(console) assert console == "b'goodbye,world'\r\n"
def commit(commit_id=None): user_path = os.path.expanduser('~') user_path = os.path.join(user_path, '.cm') if not os.path.exists(user_path): os.mkdir(user_path) wallet.set_dir(user_path) properties_path = os.path.join(user_path, '.properties') commit_path = os.path.join(user_path, '.commit') js = JsonStore(properties_path) psw = js.get('psw') if not psw: psw = wallet.create('.commit') if not psw: raise Exception('create wallet failed!') # print('+++psw:', psw) wallet.import_key('.commit', '5JkRtzuX6JBbfnxkf9iRrqYonhQEaqqCMgRThJpxMsSnAxqBzkJ') js['psw'] = psw else: # print(psw) wallet.unlock('.commit', psw) wallet.import_key('.commit', '5JkRtzuX6JBbfnxkf9iRrqYonhQEaqqCMgRThJpxMsSnAxqBzkJ') try: id = 'aabbccdd' # eosapi.set_node('https://user-api.eoseoul.io') # eosapi.set_node('https://node.eosflare.io') try: r = eosapi.push_action('learnforever', 'sayhello', bytes.fromhex(id), {'learnforever':'sayhello'}) print(r) except Exception as e: import time;time.sleep(3.0) r = httpx.get('https://api.eospowerup.io/freePowerup/learnforever') print(e) except subprocess.CalledProcessError as e: print(e.output.decode('utf8'))
deploy_contract('eosio', 'eosio.bios', contracts_path) feature_digests = ['ad9e3d8f650687709fd68f4b90b41f7d825a365b02c23a636cef88ac2ac00c43',#RESTRICT_ACTION_TO_SELF 'ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99', #REPLACE_DEFERRED '4a90c00d55454dc5b059055ca213579c6ea856967712a56017487886a4d4cc0f', #NO_DUPLICATE_DEFERRED_ID '8ba52fe7a3956c5cd3a656a3174b931d3bb2abb45578befc59f283ecd816a405', #ONLY_BILL_FIRST_AUTHORIZER '299dcb6af692324b899b39f16d5a530a33062804e41f09dc97e9f156b4476707', #WTMSIG_BLOCK_SIGNATURES 'c3a6138c5061cf291310887c0b5c71fcaffeab90d5deb50d3b9e687cead45071', #ACTION_RETURN_VALUE '8431d19ea6d9ce0755c32f89237776f8006204447e8299f102d3273cd6b7ce62', #ETHEREUM_VM ] for digest in feature_digests: try: args = {'feature_digest': digest} logger.info(f'activate {digest}') eosapi.push_action('eosio', 'activate', args, {'eosio':'active'}) except Exception as e: logger.error(e) deploy_contract('eosio.token', 'eosio.token') if not eosapi.get_balance('eosio'): logger.info('issue system token...') msg = {"issuer":"eosio","maximum_supply":f"11000000000.0000 {config.main_token}"} r = eosapi.push_action('eosio.token', 'create', msg, {'eosio.token':'active'}) assert r r = eosapi.push_action('eosio.token','issue',{"to":"eosio","quantity":f"1000000000.0000 {config.main_token}","memo":""},{'eosio':'active'}) assert r try: deploy_contract('eosio.msig', 'eosio.msig')
def init_accounts(self): if eosapi.get_account('helloworld11'): return # formatter = logging.Formatter('%(asctime)s %(levelname)s %(module)s %(lineno)d %(message)s') # handler = logging.StreamHandler() # handler.setFormatter(formatter) # config.setup_eos_network() # if len(sys.argv) == 2: # print(sys.argv) # eosapi.set_nodes([sys.argv[1]]) key1 = 'EOS7ent7keWbVgvptfYaMYeF2cenMBiwYKcwEuc11uCbStsFKsrmV' key2 = 'EOS7ent7keWbVgvptfYaMYeF2cenMBiwYKcwEuc11uCbStsFKsrmV' system_accounts = [ 'eosio.mpy', 'eosio.bpay', 'eosio.msig', 'eosio.names', 'eosio.ram', 'eosio.ramfee', 'eosio.saving', 'eosio.stake', 'eosio.token', 'eosio.vpay', 'eosio.rex', 'eosio.reserv' ] for a in system_accounts: self.create_account(a, key1, key2) pub_keys = ( 'EOS6AjF6hvF7GSuSd4sCgfPKq5uWaXvGM2aQtEUCwmEHygQaqxBSV', 'EOS7sPDxfw5yx5SZgQcVb57zS1XeSWLNpQKhaGjjy2qe61BrAQ49o', 'EOS89jesRgvvnFVuNtLg4rkFXcBg2Qq26wjzppssdHj2a8PSoWMhx', 'EOS73ECcVHVWvuxJVm5ATnqBTCFMtA6WUsdDovdWH5NFHaXNq1hw1', 'EOS8h8TmXCU7Pzo5XQKqyWwXAqLpPj4DPZCv5Wx9Y4yjRrB6R64ok', 'EOS65jj8NPh2EzLwje3YRy4utVAATthteZyhQabpQubxHNJ44mem9', 'EOS65jj8NPh2EzLwje3YRy4utVAATthteZyhQabpQubxHNJ44mem9', 'EOS65jj8NPh2EzLwje3YRy4utVAATthteZyhQabpQubxHNJ44mem9', ) producer_pub_keys = ( 'EOS5fVw435RSwW3YYWAX9qz548JFTWuFiBcHT3PGLryWaAMmxgjp1', 'EOS5fVw435RSwW3YYWAX9qz548JFTWuFiBcHT3PGLryWaAMmxgjp1', 'EOS5fVw435RSwW3YYWAX9qz548JFTWuFiBcHT3PGLryWaAMmxgjp1', 'EOS5fVw435RSwW3YYWAX9qz548JFTWuFiBcHT3PGLryWaAMmxgjp1', 'EOS5fVw435RSwW3YYWAX9qz548JFTWuFiBcHT3PGLryWaAMmxgjp1', ) i = 0 for a in self.test_accounts: key = pub_keys[i] self.create_account(a, key, key) i += 1 i = 0 for a in self.producer_accounts: key = producer_pub_keys[i] self.create_account(a, key, key) i += 1 try: eosapi.schedule_protocol_feature_activations([ '0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd' ]) #PREACTIVATE_FEATURE time.sleep(1.0) logger.info('set PREACTIVATE_FEATURE done!') except Exception as e: logger.exception(e) # try: # eosapi.update_runtime_options(max_transaction_time=230) # time.sleep(2.0) # except Exception as e: # logger.exception(e) contracts_path = os.path.dirname(__file__) contracts_path = os.path.join(contracts_path, 'contracts') if not eosapi.get_raw_code_and_abi('eosio')['wasm']: self.deploy_contract('eosio', 'eosio.bios') time.sleep(1.0) feature_digests = [ '1a99a59d87e06e09ec5b028a9cbb7749b4a5ad8819004365d02dc4379a8b7241', #'ONLY_LINK_TO_EXISTING_PERMISSION' '2652f5f96006294109b3dd0bbde63693f55324af452b799ee137a81a905eed25', #'FORWARD_SETCODE' '299dcb6af692324b899b39f16d5a530a33062804e41f09dc97e9f156b4476707', #'WTMSIG_BLOCK_SIGNATURES' 'ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99', #'REPLACE_DEFERRED' '4a90c00d55454dc5b059055ca213579c6ea856967712a56017487886a4d4cc0f', #'NO_DUPLICATE_DEFERRED_ID' '4e7bf348da00a945489b2a681749eb56f5de00b900014e137ddae39f48f69d67', #'RAM_RESTRICTIONS' '4fca8bd82bbd181e714e283f83e1b45d95ca5af40fb89ad3977b653c448f78c2', #'WEBAUTHN_KEY' '5443fcf88330c586bc0e5f3dee10e7f63c76c00249c87fe4fbf7f38c082006b4', #'BLOCKCHAIN_PARAMETERS' '68dcaa34c0517d19666e6b33add67351d8c5f69e999ca1e37931bc410a297428', #'DISALLOW_EMPTY_PRODUCER_SCHEDULE' '825ee6288fb1373eab1b5187ec2f04f6eacb39cb3a97f356a07c91622dd61d16', #'KV_DATABASE' '8ba52fe7a3956c5cd3a656a3174b931d3bb2abb45578befc59f283ecd816a405', #'ONLY_BILL_FIRST_AUTHORIZER' 'ad9e3d8f650687709fd68f4b90b41f7d825a365b02c23a636cef88ac2ac00c43', #'RESTRICT_ACTION_TO_SELF' 'bf61537fd21c61a60e542a5d66c3f6a78da0589336868307f94a82bccea84e88', #'CONFIGURABLE_WASM_LIMITS' 'c3a6138c5061cf291310887c0b5c71fcaffeab90d5deb50d3b9e687cead45071', #'ACTION_RETURN_VALUE' 'e0fb64b1085cc5538970158d05a009c24e276fb94e1a0bf6a528b48fbc4ff526', #'FIX_LINKAUTH_RESTRICTION' 'f0af56d2c5a48d60a4a5b5c903edfb7db3a736a94ed589d0b797df33ff9d3e1d', #'GET_SENDER' ] for digest in feature_digests: try: args = {'feature_digest': digest} # logger.info(f'activate {digest}') eosapi.push_action('eosio', 'activate', args, {'eosio': 'active'}) except Exception as e: logger.error(e) self.deploy_micropython_contract() try: self.deploy_contract('eosio.token', 'eosio.token') except Exception as e: logger.exception(e) if not eosapi.get_balance('eosio'): logger.info('issue system token...') msg = { "issuer": "eosio", "maximum_supply": f"11000000000.0000 {config.main_token}" } r = eosapi.push_action('eosio.token', 'create', msg, {'eosio.token': 'active'}) assert r r = eosapi.push_action( 'eosio.token', 'issue', { "to": "eosio", "quantity": f"1000000000.0000 {config.main_token}", "memo": "" }, {'eosio': 'active'}) assert r try: self.deploy_contract('eosio.msig', 'eosio.msig') except Exception as e: logger.exception(e) #wait for protocol activation time.sleep(1.0) for i in range(3): try: if self.deploy_contract('eosio', 'eosio.system'): logger.info('deploy eosio.system done!') break except Exception as e: pass # logger.info(e) else: assert False, 'deploy eosio.system failed!' if True: args = dict( version=0, core='4,EOS', # min_bp_staking_amount = 0, # vote_producer_limit = 100, # mini_voting_requirement = 21 ) # args['min_bp_staking_amount'] = 10000000000 try: eosapi.push_action('eosio', 'init', args, {'eosio': 'active'}) except Exception as e: logger.exception(e) if eosapi.get_balance('helloworld11') <= 0: r = eosapi.push_action( 'eosio.token', 'transfer', { "from": "eosio", "to": "helloworld11", "quantity": f"10000000.0000 {config.main_token}", "memo": "" }, {'eosio': 'active'}) if eosapi.get_balance('helloworld12') <= 0: r = eosapi.push_action( 'eosio.token', 'transfer', { "from": "eosio", "to": "helloworld12", "quantity": f"10000000.0000 {config.main_token}", "memo": "" }, {'eosio': 'active'}) if eosapi.get_balance('helloworld13') <= 0: r = eosapi.push_action( 'eosio.token', 'transfer', { "from": "eosio", "to": "helloworld13", "quantity": f"10000000.0000 {config.main_token}", "memo": "" }, {'eosio': 'active'}) if eosapi.get_balance('helloworld14') <= 0: r = eosapi.push_action( 'eosio.token', 'transfer', { "from": "eosio", "to": "helloworld14", "quantity": f"10000000.0000 {config.main_token}", "memo": "" }, {'eosio': 'active'}) if eosapi.get_balance('hello') <= 0: args = { "from": "eosio", "to": "hello", "quantity": f"600000000.0000 {config.main_token}", "memo": "" } r = eosapi.push_action('eosio.token', 'transfer', args, {'eosio': 'active'}) for account in self.test_accounts: eosapi.transfer('eosio', account, 10000.0) utils.buyrambytes('eosio', account, 5 * 1024 * 1024) utils.dbw(account, account, 1.0, 1000) utils.dbw('hello', 'hello', 1.0, 5 * 1e8) if 0: try: args = {'vmtype': 1, 'vmversion': 0} #activate vm python eosapi.push_action('eosio', 'activatevm', args, {'eosio': 'active'}) except Exception as e: logger.info(e) try: args = {'vmtype': 2, 'vmversion': 0} #activate vm python eosapi.push_action('eosio', 'activatevm', args, {'eosio': 'active'}) except Exception as e: logger.info(e) balance = eosapi.get_balance('hello') logger.info(f'++++balance: {balance}') while False: n = random.randint(0, 10000000) elapsed = 0 for i in range(n, n + 10): try: r = eosapi.transfer('hello', 'eosio', 0.0001, str(i)) logger.info(r['processed']['elapsed']) elapsed += int(r['processed']['elapsed']) except Exception as e: logger.exception(e) logger.info(f'AVG: {elapsed/10}') logger.info(eosapi.get_balance('hello')) time.sleep(2.0) for account in self.test_accounts: # print('buy ram', account) utils.buyrambytes('hello', account, 10 * 1024 * 1024) # print('buy cpu', account) utils.dbw('hello', account, 1.0, 1.0) if 0: args = {'owner': 'helloworld11', 'amount': '1.0000 EOS'} eosapi.push_action('eosio', 'deposit', args, {'helloworld11': 'active'})
# send_inline('hello', 'sayhello', b'hello,world', {'hello':'active'}) # play() ''' print(type(code)) abi = b''' { "version": "eosio::abi/1.0", "structs": [{ "name": "message", "base": "", "fields": [ {"name":"msg", "type":"string"} ] } ], "actions": [{ "name": "sayhello", "type": "raw" } ] } ''' r = hello._eosapi.pack_abi(abi) print(r) #import sys;sys.exit(0) eosapi.set_contract('hello', code, abi, 1) r = eosapi.push_action('hello', 'sayhello', b'hello,world', {'hello': 'active'}) print(r)
def set_abi(account, abi): db.set_abi(account, abi) abi = _eosapi.pack_abi(abi) setabi = {'account': account, 'abi': abi.hex()} eosapi.push_action('eosio', 'setabi', setabi, {account: 'active'})
from pyeoskit import eosapi, wallet eosapi.set_node('https://api.eosn.io') #import your account private key here wallet.import_key('mywallet', '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p') payer = 'testaccount1' receiver = 'testaccount2' args = { 'payer': payer, 'receiver': receiver, 'quant':'0.1 EOS' } eosapi.push_action('eosio', 'buyram', args, {payer:'active'})
from pyeoskit import eosapi, wallet eosapi.set_node('https://api.eosn.io') #import your account private key here wallet.import_key('mywallet', '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p') account = 'testaccount1' args = {'account': account, 'bytes': 100 * 1024} r = eosapi.push_action('eosio', 'sellram', args, {account: 'active'})
# transfer example import os from pyeoskit import eosapi, wallet #import your account private key here wallet.import_key('mywallet', '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p') eosapi.set_node('https://api.eosn.io') info = eosapi.get_info() print(info) args = { 'from': 'test1', 'to': 'test2', 'quantity': '1.0000 EOS', 'memo': 'hello,world' } eosapi.push_action('eosio.token', 'transfer', args, {'test1':'active'})
# sign with ledger example from pyeoskit import eosapi from pyeoskit import ledger eosapi.set_node('https://api.eosn.io') args = { 'from': 'test1', 'to': 'test2', 'quantity': '1.0000 EOS', 'memo': 'hello,world' } pub_key = ledger.get_public_key(0) print('++++public key:', pub_key) #indexes is an array of ledger signing key indexes eosapi.push_action('eosio.token', 'transfer', args, {'test1': 'active'}, indexes=[0])
#link authorization example from pyeoskit import eosapi, wallet eosapi.set_node('https://api.eosn.io') #import your account private key here wallet.import_key('mywallet', '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p') account = "testaccount" args = { "account": account, "code": "eosio.token", "type": "transfer", "requirement": "transfer" } eosapi.push_action('eosio', 'linkauth', args, {account: 'active'})
def publish_evm_code(transaction, eos_pub_key=None): global g_chain_id global g_current_account global g_last_trx_ret global g_public_key # transaction['chainId'] = chain_id #Ethereum mainnet # print(transaction) sender = transaction['from'] if sender[:2] == '0x': sender = sender[2:] sender = sender.lower() logger.info(sender) a = EthAccount('helloworld11', sender) logger.info(('+++++++++sender:', sender)) nonce = a.get_nonce() assert nonce >= 0 transaction['nonce'] = nonce transaction['gasPrice'] = 0 transaction['gas'] = 20000000 if sender in keys: priv_key = key_maps[sender] encoded_transaction = Account.sign_transaction(transaction, priv_key) encoded_transaction = encoded_transaction.rawTransaction.hex()[2:] elif g_public_key: transaction = dissoc(transaction, 'from') encoded_transaction = sign_transaction_dict_with_eos_key( transaction, g_chain_id, g_public_key) # logger.info(encoded_transaction) encoded_transaction = encoded_transaction.hex() else: transaction = dissoc(transaction, 'from') unsigned_transaction = serializable_unsigned_transaction_from_dict( transaction) encoded_transaction = encode_transaction(unsigned_transaction, vrs=(g_chain_id, 0, 0)) encoded_transaction = encoded_transaction.hex() if g_current_account: account_name = g_current_account else: account_name = 'helloworld11' if g_contract_name: contract_name = g_contract_name else: contract_name = 'helloworld11' args = {'trx': encoded_transaction, 'sender': sender} ret = eosapi.push_action(contract_name, 'raw', args, {account_name: 'active'}) g_last_trx_ret = ret logs = ret['processed']['action_traces'][0]['console'] # logger.info(logs) logger.info(('++++elapsed:', ret['processed']['elapsed'])) try: logs = bytes.fromhex(logs) logs = rlp.decode(logs) # logger.info(logs) except Exception as e: logger.error(logs) raise e return logs
#import your account private key here wallet.import_key('mywallet', '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p') #account to update authorization account = 'testaccount' #new permission key to add pub_key = 'EOS6wJhZLfAjG9F9nXJL3x5EJRpEBximZqmoST7hskqQ3AYBVv9bm' args = { "account": account, "permission": "active", "parent": "owner", "auth": { "threshold": 1, "keys": [{'key': pub_key, 'weight': 1}], "accounts": [ { "permission": { "actor":account, "permission": "eosio.code" }, "weight":1 } ], "waits": [] } } eosapi.push_action('eosio', 'updateauth', args, {account: 'active'})
def test_push_action(self): r = eosapi.push_action('hello', 'sayhello', b'hello') print(r)