def test_invoke_all_function_in_list(self, password): network = 'privateNet' wallet_file_name = 'wallet.json' password.return_value = 'password' project_path = os.path.join(os.getcwd(), 'test_file', 'test_invoke') Invoke.invoke_all_function_in_list(wallet_file_name, project_path, network, 'Name,BalanceOf')
def invoke_cmd(ctx, network, wallet, functions): """ Invoke the function list in punica-config. """ project_dir = ctx.obj['PROJECT_DIR'] try: Invoke.invoke_all_function_in_list(wallet, project_dir, network, functions) except (PunicaException, SDKException) as e: print('An error occur...') print(e) print('Punica will exist...') exit(1)
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 refund(hashlock, sender): preExec = False params = dict() params["order_id"] = "Hex:" + hashlock.hex() abiFunction = Invoke.get_function(params, 'refund', abi_info) responce = SdkUtils.SendTransaction(contract_address, sender, sender, gas_limit, gas_price, abiFunction, preExec) return responce
def get_ont_balance(): preExec = True params = dict() abiFunction = Invoke.get_function(params, 'get_sin_balance', abi_info) responce = SdkUtils.SendTransaction(contract_address, payer, payer, gas_limit, gas_price, abiFunction, preExec) return parse_neo_vm_contract_return_type_integer(responce)
def invoke_cmd(ctx, network, wallet, functions, config, preexec): """ Invoke the function list in default-config or specify config. """ project_dir = ctx.obj['PROJECT_DIR'] if ctx.invoked_subcommand is None: try: Invoke.invoke_all_function_in_list(wallet, project_dir, network, functions, config, preexec) except (PunicaException, SDKException) as e: print('An error occur...') print(e) print('Punica will exit...') exit(1) else: pass
def Balance(address): params = dict() params["address"] = address abiFunction = Invoke.get_function(params, 'balanceOf', abiInfo) return parse_neo_vm_contract_return_type_integer( SdkUtils.SendTransaction(ContractAddress(), owner, ownerAccount, abiFunction))
def set_buyer_address(hashlock, buyer, sender): preExec = False params = dict() params["order_id"] = "Hex:" + hashlock.hex() params["buyer"] = "ByteArray:" + buyer abiFunction = Invoke.get_function(params, 'set_buyer_address', abi_info) responce = SdkUtils.SendTransaction(contract_address, sender, sender, gas_limit, gas_price, abiFunction, preExec) return responce
def get_refund_timelock(hashlock): preExec = True params = dict() params["order_id"] = "Hex:" + hashlock.hex() abiFunction = Invoke.get_function(params, 'get_refund_timelock', abi_info) responce = SdkUtils.SendTransaction(contract_address, payer, payer, gas_limit, gas_price, abiFunction, preExec) return parse_neo_vm_contract_return_type_integer(responce)
def get_buyer(hashlock): preExec = True params = dict() params["order_id"] = "Hex:" + hashlock.hex() abiFunction = Invoke.get_function(params, 'get_buyer', abi_info) responce = SdkUtils.SendTransaction(contract_address, payer, payer, gas_limit, gas_price, abiFunction, preExec) return responce
def initiate_order(amountOfSinToSell, amountOfUsdtToBuy, hashlock, initiator=singamesAddress, sender=singames): preExec = False params = dict() params["amountOfSinToSell"] = amountOfSinToSell params["amountOfUsdtToBuy"] = amountOfUsdtToBuy params["hashlock"] = "Hex:" + hashlock.hex() params["initiator"] = "ByteArray:" + initiator abiFunction = Invoke.get_function(params, 'intiate_order', abi_info) return SdkUtils.SendTransaction(contract_address, sender, payer, gas_limit, gas_price, abiFunction, preExec)
def Transfer(from_address, to_address, amount, payer): #transfer(from_address, to_address, amount) params = dict() params["from_address"] = from_address params["to_address"] = to_address params["amount"] = amount abiFunction = Invoke.get_function(params, 'transfer', abiInfo) return parse_neo_vm_contract_return_type_bool( SdkUtils.SendTransaction(ContractAddress(), from_address, payer, abiFunction))
def list_cmd(ctx, config): """ List all the function in default-config or specify config. """ project_dir = ctx.obj['PROJECT_DIR'] Invoke.list_all_functions(project_dir, config)
def get_abi_info(abi_dir_path: str): abi_dict = read_abi(abi_dir_path, os.path.basename(abi_dir_path)) return Invoke.generate_abi_info(abi_dict)
def get_abi_info(abi_dir_path: str): abi_dict = read_abi( os.path.abspath(os.path.join(abi_dir_path, os.pardir)), os.path.basename(abi_dir_path)) return Invoke.generate_abi_info(abi_dict)
def Init(): params = dict() abiFunction = Invoke.get_function(params, 'init', abiInfo) return parse_neo_vm_contract_return_type_bool( SdkUtils.SendTransaction(ContractAddress(), owner, ownerAccount, abiFunction))