def create_account(inst, name, owner='CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K', active='CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K'): ''' create account using below keys: name - name owner - CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K active - CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K pri - 5HsGZoidEURBx8gYzwZMeM2eF8P3F9KC3nVAib2mdGSdj6FqS7h ''' if inst.wallet.locked(): inst.wallet.unlock(CFG['wallet']['test_wallet_pwd']) try: ## private key of nathan, which is the referrer inst.wallet.addPrivateKey(inst.const['master_privkey']) except Exception as e: pass toRegister = { 'name': name, 'owner': owner, 'active': active } account = cybex.Account('nathan') owner_key_authority = [[toRegister["owner"], 1]] active_key_authority = [[toRegister["active"], 1]] owner_accounts_authority = [] active_accounts_authority = [] kwargs = { 'fee':{"amount": 100, "asset_id": "1.3.0"}, 'registrar':account["id"], 'referrer':account["id"], 'referrer_percent':1, 'name':toRegister["name"], 'owner': {'account_auths': owner_accounts_authority, 'key_auths': owner_key_authority, "address_auths": [], 'weight_threshold': 1}, 'active': {'account_auths': active_accounts_authority, 'key_auths': active_key_authority, "address_auths": [], 'weight_threshold': 1}, "options": {"memo_key": toRegister["active"], "voting_account": account["id"], "num_witness": 0, "num_committee": 0, "votes": [], "extensions": [] }, "extensions": {}, "prefix": "CYB" } op = operations.Account_create(**kwargs) ops=[] ops.append(op) inst.finalizeOp(ops, account, "active") return True
def update_active_key(inst, key, account=None, **kwargs): btsAccount.PublicKey(key, prefix='CYB') account = cybex.Account(account) account["active"] = {'weight_threshold': 1, 'account_auths': [], 'key_auths': [[key, 1]], 'address_auths': []} op = operations.Account_update(**{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "account": account["id"], "active": account["active"], "extensions": {} }) return inst.finalizeOp(op, account["name"], "active", **kwargs)
def update_active_keys(inst, obj, account=None, **kwargs): # for testing multi-Sig # need fee to update active keys fee = inst.fee[6]['fee']['fee']/100000 inst.transfer(account, fee, 'CYB', '', 'nathan') account = cybex.Account(account) account["active"] = obj op = operations.Account_update(**{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "account": account["id"], "active": account["active"], "extensions": {} }) return inst.finalizeOp(op, account["name"], "active", **kwargs)
def update_assetSupply(inst, symbol, max_supply): asset = cybex.Asset(symbol) options = asset['options'] account = cybex.Account(inst.const['master_account']) options.update({ "max_supply": max_supply }) op = operations.Asset_update(**{ "fee": {"amount": 0, "asset_id": "1.3.0"}, "issuer": account["id"], "asset_to_update": asset["id"], "new_options": options, "extensions": [], "prefix": inst.prefix }) return inst.finalizeOp(op, account["name"], "active")
def create_buyback_account(name, asset, buyback_markets): """ Only asset issuer can create a buyback account on that asset name: like 'abc-def' asset: like '1.3.2' buyback_markets: like ['1.3.3', '1.3.4'] """ if inst.wallet.locked(): inst.wallet.unlock(TEST_WALLET_PWD) try: ## private key of nathan, which is the referrer inst.wallet.addPrivateKey(private) except Exception as e: pass account = cybex.Account('nathan') kwargs = { 'fee':{"amount": 100, "asset_id": "1.3.0"}, 'registrar':account["id"], 'referrer':account["id"], 'referrer_percent':1, 'name':name, 'owner': {'account_auths': [['1.2.3', 1]], 'key_auths': [], "address_auths": [], 'weight_threshold': 1}, 'active': {'account_auths': [['1.2.3', 1]], 'key_auths': [], "address_auths": [], 'weight_threshold': 1}, "options": {"memo_key": 'CYB8fEEQ19N4LTVpg4wqX6B97ouDaNDDFK5fWbuaoNy4HPF9qnq4K', "voting_account": account["id"], "num_witness": 0, "num_committee": 0, "votes": [], "extensions": [] }, "extensions": {'buyback_options': {'asset_to_buy': asset_id, 'asset_to_buy_issuer': account['id'], 'markets': buyback_markets}}, "prefix": "CYB" } op = operations.Account_create(**kwargs) ops=[] ops.append(op) inst.finalizeOp(ops, account, "active") return True
def cancel_all(INSTANCE, accs): try: for acc in accs: for o in cybex.Account(acc, cybex_instance=INSTANCE).openorders: m = cybex.Market(base=o['base']['asset'], quote=o['quote']['asset'], cybex_instance=INSTANCE) logging.info('Cancel the orders of the account') logging.info(dict(o)) logging.info(o['id']) logging.info(acc) INSTANCE.clear() m.cancel(o['id'], acc) logging.info("cancel finished") except Exception as err: logging.info(err) return False return True
def create_data(INSTANCE): data = {} acc = create_accounts(INSTANCE) assert acc if acc: data['alice'] = acc[0] acc = create_accounts(INSTANCE) assert acc if acc: data['bob'] = acc[0] # data['bob'] = create_accounts(INSTANCE)[0] logging.info("Create account for alice and bob") data['asset1'] = create_asset(INSTANCE) data['asset2'] = create_asset(INSTANCE) assert data['asset1'] assert data['asset2'] logging.info("Create 2 asset") logging.info(data) issue_asset(INSTANCE, data['asset1']) issue_asset(INSTANCE, data['asset2']) logging.info("issue the 2 assets") transfer_asset(INSTANCE, data['alice']['account'], 10000000, data['asset1']) time.sleep(3) print('-------------------------------------') print(cybex.Account(data['alice']['account'])) print('-------------------------------------') transfer_asset(INSTANCE, data['bob']['account'], 10000000, data['asset2']) time.sleep(3) logging.info("transfer 1000000 of %s to alice and 1000000 of %s to bob", data['asset1'], data['asset2']) issue_CYB(INSTANCE, data['alice']['account'], 1) issue_CYB(INSTANCE, data['bob']['account'], 1) logging.info("transfer 1 CYB to the 2 accounts for fee") # add_private_key(INSTANCE,[data['alice']['active']['wif_priv_key'],data['alice']['active']['wif_priv_key']]) # logging.info("add private key in wallet for alice and bob") return data
def get_account_id(acc): a = cybex.Account(acc) return a['id']
def get_latest_history(acc): return next(cybex.Account(acc).history(limit=1))