def add_cmd(ctx): """ Add account to wallet.json. """ project_dir = ctx.obj['PROJECT_DIR'] Account.add_account(project_dir) print('create account successful')
def add_ont_id(project_dir: str): wallet_manager = Account.get_wallet_manager(project_dir) try: pwd = Account.get_password() wallet_manager.create_identity('', pwd) wallet_manager.write_wallet() except PunicaException: pass
def delete_ont_id(project_dir: str, ont_id: str): wallet_manager = Account.get_wallet_manager(project_dir) try: pwd = Account.get_password() for identity in wallet_manager.wallet_in_mem.identities: if identity.ont_id == ont_id: wallet_manager.wallet_in_mem.identities.remove(identity) wallet_manager.write_wallet() print('delete ', identity.ont_id + ' success') return print("there is not the ontid,", ont_id) except PunicaException: pass
def withdraw_ong(project_dir_path: str, claimer: str, to: str, amount, gas_limit, gas_price, network): if project_dir_path == '': project_dir_path = os.getcwd() if not os.path.isdir(project_dir_path): raise PunicaException(PunicaError.dir_path_error) rpc_address = handle_network_config(project_dir_path, network) sdk = OntologySdk() sdk.rpc.set_address(rpc_address) sdk.wallet_manager = Account.get_wallet_manager(project_dir_path) if len(sdk.wallet_manager.wallet_in_mem.accounts) == 0: print('there is not account in the wallet.json') return has_sender = False for acc in sdk.wallet_manager.wallet_in_mem.accounts: if claimer == acc.address: has_sender = True break if not has_sender: print('there is not sender in the wallet.json') return claimer_pwd = getpass.getpass('Please input claimer password: '******'tx_hash: ', tx_hash)
def transfer(project_dir_path, asset: str, sender, to, amount, gas_price, gas_limit, network): if asset == '' or asset.lower() != 'ont' and asset.lower() != 'ong': print('asset should be ont or ong') return if project_dir_path == '': project_dir_path = os.getcwd() if not os.path.isdir(project_dir_path): raise PunicaException(PunicaError.dir_path_error) rpc_address = handle_network_config(project_dir_path, network) sdk = OntologySdk() sdk.set_rpc(rpc_address) wallet_manager = Account.get_wallet_manager(project_dir_path) if len(wallet_manager.wallet_in_mem.accounts) == 0: print('there is not account in the wallet.json') return has_sender = False for acc in wallet_manager.wallet_in_mem.accounts: if sender == acc.address: has_sender = True break if not has_sender: print('there is not sender in the wallet.json') return sender_account = Invoke.unlock_account(sender, wallet_manager) if sender_account is None: return tx_hash = sdk.native_vm().asset().send_transfer(asset, sender_account, to, amount, sender_account, gas_limit, gas_price) print('tx_hash: ', tx_hash)
def list_ont_id(project_dir: str): wallet_manager = Account.get_wallet_manager(project_dir) print('ontId:') for identity in wallet_manager.wallet_in_mem.identities: print('\t', identity.ont_id)
def list_cmd(ctx): """ List all your account address. """ project_dir = ctx.obj['PROJECT_DIR'] Account.list_account(project_dir)
def delete_cmd(ctx, address): """ Delete account by address. """ project_dir = ctx.obj['PROJECT_DIR'] Account.delete_account(project_dir, address)
def import_cmd(ctx, privatekey): """ Import account by private key. """ project_dir = ctx.obj['PROJECT_DIR'] Account.import_account(project_dir, privatekey)