def init_wallet(): global psw if not os.path.exists('data-dir/mywallet.wallet'): psw = wallet.create('mywallet') print('wallet password:'******'data-dir/data.pkl', 'wb') as f: print('test wallet password save to data-dir/data.pkl') pickle.dump(psw, f) wallet.open('mywallet') if not psw: with open('data-dir/data.pkl', 'rb') as f: psw = pickle.load(f) wallet.unlock('mywallet', psw) wallet.set_timeout(60 * 60 * 24) priv_keys = [ '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', '5JEcwbckBCdmji5j8ZoMHLEUS8TqQiqBG1DRx1X9DN124GUok9s', '5JbDP55GXN7MLcNYKCnJtfKi9aD2HvHAdY7g8m67zFTAFkY1uBB', '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p' ] keys = wallet.list_keys('mywallet', psw) exist_priv_keys = keys.values() for priv_key in priv_keys: if not priv_key in exist_priv_keys: print('import key:', priv_key) wallet.import_key('mywallet', priv_key)
def init(): psw = 'PW5Kk1h8RqDwf8CB8mKcz7WZ8r6MF9of9CYvrC96XdBL5Z1SwBVx9' if not os.path.exists('data-dir/mywallet.wallet'): psw = wallet.create('mywallet') print(psw) wallet.open('mywallet') wallet.unlock('mywallet', psw) priv_keys = [ '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', '5JEcwbckBCdmji5j8ZoMHLEUS8TqQiqBG1DRx1X9DN124GUok9s', '5JbDP55GXN7MLcNYKCnJtfKi9aD2HvHAdY7g8m67zFTAFkY1uBB' ] keys = wallet.list_keys() exist_priv_keys = keys.values() for priv_key in priv_keys: if not priv_key in exist_priv_keys: wallet.import_key('mywallet', priv_key) src_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(src_dir, '/contracts/cryptokitties')) contracts_path = os.path.join(src_dir, '../../build', 'contracts') for account in ['eosio.bios', 'eosio.msig', 'eosio.system', 'eosio.token']: if not eosapi.get_account(account).permissions: r = eosapi.create_account('eosio', account, key1, key2) assert r if not eosapi.get_code(account): wast = os.path.join(contracts_path, account, account + '.wast') abi = os.path.join(contracts_path, account, account + '.abi') r = eosapi.set_contract(account, wast, abi, 0) eosapi.produce_block()
def load_keys(): keys = {} try: with open('keys.pkl', 'rb') as f: keys = pickle.load(f) except Exception as e: print(e) print(keys) exist_keys = wallet.list_keys() for pub in keys: if pub in exist_keys: continue priv_key = keys[pub] print(priv_key) wallet.import_key('mywallet', priv_key)
def create_multisig_account(): #PW5KKNC8zM2KVLrb1cw4YNXZ69NLK7Fr5B35wHmsPt35tyiYkY4RR test_keys = { 'EOS8mqCBdG8yiaULU3YyiD1ZhySzt64KjNb1gQiy4GdUPMEQMxVJJ': '5KZB2UCfpD3qCEUviXrgMdwDb6TDpuvuWvZKH85u9mBYK85Rqzd', 'EOS8mrwBdRz1zyaBiMexqJw6UybR9gNLzBC1tdLqqcfVdA2TFcgAb': '5KM6MvhsNRUtafGCghEYWXYXqWidaGTKqfsida6h5mNg5ouQUTv', 'EOS8mqgm5kx88XzsxsAAKH5vnq1vGNcSZDfJyar17FnTm1HvBRuXi': '5JiwrohmpRR3PjUcf6NpSLBE2QdAUTJZf1tAHYvK7iAUTWnaGgZ', 'EOS8msM7326VykwCSdEXZrj8U3goUPYWZ84KxBTy6GajGkpQCXQNX': '5K6HPpxgq5qFkRpUcaVdZVr4hmT61EzU1AFEfkm428pEQP59neB', } all_keys = wallet.list_keys() for pub in test_keys: priv = test_keys[pub] if not pub in all_keys: wallet.import_key('mywallet', priv) keys = [ [ initeos.key1, initeos.key2 ], [ 'EOS8mqCBdG8yiaULU3YyiD1ZhySzt64KjNb1gQiy4GdUPMEQMxVJJ', 'EOS8mrwBdRz1zyaBiMexqJw6UybR9gNLzBC1tdLqqcfVdA2TFcgAb' ], [ 'EOS8mqgm5kx88XzsxsAAKH5vnq1vGNcSZDfJyar17FnTm1HvBRuXi', 'EOS8msM7326VykwCSdEXZrj8U3goUPYWZ84KxBTy6GajGkpQCXQNX' ] ] accounts = ['test', 'test1', 'test2'] index = 0 for key in keys: a = accounts[index] if not eosapi.get_account(a): eosapi.create_account('eosio', a, key[0], key[1]) index += 1 eosapi.produce_block() #"test2" must come first to satisfy the tricky verifycation in authority.hpp:validate per = '{"threshold" : 100, "keys" : [], "accounts" : [{"permission":{"actor":"test2","permission":"active"},"weight":50},{"permission":{"actor":"test1","permission":"active"},"weight":50}]}' # key = 'EOS8muoEdY4L9WRYXYB55WmEzYw9A314fW1uMPUqUrFUBMMjWNpxd' auth = eosapi.pack_updateauth('test', 'active', 'owner', per, 0) act = [N('eosio'), N('updateauth'), [[N('test'), N('active')]], auth] r = eosapi.push_transactions2([[act]]) assert r print(r) eosapi.produce_block()
def create_keys(n=100): keys = {} try: with open('keys.pkl', 'rb') as f: keys = pickle.load(f) except Exception as e: print(e) for i in range(n): key_pair = eosapi.create_key() # print(key_pair) keys[key_pair.public] = key_pair.private with open('keys.pkl', 'wb') as f: pickle.dump(keys, f) exist_keys = wallet.list_keys() for pub in keys: if pub in exist_keys: continue priv_key = keys[pub] print(priv_key) wallet.import_key('mywallet', priv_key, False) wallet.save('mywallet')
def init(): psw = 'PW5K87AKbRvFFMJJm4dU7Zco4fi6pQtygEU4iyajwyTvmELUDnFBK' if not os.path.exists('data-dir/mywallet.wallet'): psw = wallet.create('mywallet') print('wallet password:'******'mywallet') wallet.unlock('mywallet', psw) priv_keys = [ '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', '5JEcwbckBCdmji5j8ZoMHLEUS8TqQiqBG1DRx1X9DN124GUok9s', '5JbDP55GXN7MLcNYKCnJtfKi9aD2HvHAdY7g8m67zFTAFkY1uBB' ] keys = wallet.list_keys() exist_priv_keys = keys.values() for priv_key in priv_keys: if not priv_key in exist_priv_keys: wallet.import_key('mywallet', priv_key) if eosapi.is_replay(): return src_dir = os.path.dirname(os.path.abspath(__file__)) ''' r = eosapi.push_message('eosio.token', 'create', {"to":"eosio", "quantity":"10000.0000 EOS", "memo":""},{'eosio':'active'}) r = eosapi.push_message('eosio.token','issue',{"to":"hello","quantity":"1000.0000 EOS","memo":""},{'hello':'active'}) assert r msg = {"from":"eosio", "to":"hello", "quantity":"25.0000 EOS", "memo":"m"} r = eosapi.push_message('eosio.token', 'transfer', msg, {'eosio':'active'}) assert r ''' contracts_path = os.path.join(src_dir, '../../build', 'contracts') sys.path.append(os.getcwd()) for account in ['eosio.bios', 'eosio.msig', 'eosio.system', 'eosio.token']: print('account', account) if not eosapi.get_account(account).permissions: r = eosapi.create_account('eosio', account, key1, key2) assert r eosapi.produce_block() old_code = eosapi.get_code(account)[0] need_update = not old_code if False: #old_code: print('+++++++++old_code[:4]', old_code[:4]) if old_code[:4] != b'\x00asm': old_code = eosapi.wast2wasm(old_code) wast = os.path.join(contracts_path, account, account + '.wast') code = open(wast, 'rb').read() code = eosapi.wast2wasm(code) print(len(code), len(old_code), old_code[:20]) if code == old_code: need_update = False if need_update: wast = os.path.join(contracts_path, account, account + '.wast') abi = os.path.join(contracts_path, account, account + '.abi') r = eosapi.set_contract(account, wast, abi, 0) eosapi.produce_block() if False: #account == 'eosio.token': msg = { "issuer": "eosio", "maximum_supply": "1000000000.0000 EOS", "can_freeze": 0, "can_recall": 0, "can_whitelist": 0 } r = eosapi.push_message('eosio.token', 'create', msg, {'eosio.token': 'active'}) assert r r = eosapi.push_message('eosio.token', 'issue', { "to": "eosio", "quantity": "1000.0000 EOS", "memo": "" }, {'eosio': 'active'}) assert r eosapi.produce_block() from backyard import t t.deploy_mpy() #load common libraries # t.load_all() console = PyEosConsole(locals=globals()) console.interact(banner='Welcome to PyEos')
def import_keys(): keys = wallet.list_keys('mywallet', initeos.psw) for a in accounts: if not a['pub'] in keys: wallet.import_key('mywallet', a['pvt'], False) wallet.save('mywallet')