public async Task Transfer() { bool isEncrypt = false; //先调用接口判断是否加密 ApiResponse response = await TransactionApi.GetTxSettings(); if (!response.HasError) { TransactionFeeSetting setting = response.GetResult <TransactionFeeSetting>(); isEncrypt = setting.Encrypt; } if (isEncrypt) { //先解锁 string password = "******"; ApiResponse unlockResponse = await WalletManagementApi.WalletPassphrase(password); if (!unlockResponse.HasError) { //write your logic /* 三处需要锁定, * 1、备份前解锁,备份后锁定 * 2、备份还原后需要锁定 * 3、转账交易前解锁,交易后锁定 */ } //锁定 ApiResponse lockResponse = await WalletManagementApi.WalletLock(); } }
public async Task TestGetTxSettings() { ApiResponse response = await TransactionApi.GetTxSettings(); Assert.IsFalse(response.HasError); TransactionFeeSetting result = response.GetResult <TransactionFeeSetting>(); Assert.IsNotNull(result); }
public async Task TestSendToAddress() { ApiResponse blockChainResponse = await BlockChainEngineApi.GetBlockChainStatus(); if (!blockChainResponse.HasError) { //地址 string address = "fiiitCPyohiEPn9q11AXCdvVDouoVvgojXBcVj"; //地址校验 BlockChainStatus blockChainStatus = blockChainResponse.GetResult <BlockChainStatus>(); //验证address if (AddressTools.AddressVerfy(blockChainStatus.ChainNetwork, address)) { //判断是否加密 ApiResponse transactionResponse = await TransactionApi.GetTxSettings(); if (!transactionResponse.HasError) { TransactionFeeSetting settingResult = transactionResponse.GetResult <TransactionFeeSetting>(); if (settingResult.Encrypt) { //先解锁 string password = "******"; ApiResponse unlockResponse = await WalletManagementApi.WalletPassphrase(password); if (!unlockResponse.HasError) { ApiResponse response = await TransactionApi.SendToAddress(address, 50000000, "this is your request", "John", false); Assert.IsFalse(response.HasError); string result = response.GetResult <string>(); Assert.IsNotNull(result); } ApiResponse lockResponse = await WalletManagementApi.WalletLock(); } else { ApiResponse response = await TransactionApi.SendToAddress(address, 50000000, "this is your request", "John", false); Assert.IsFalse(response.HasError); string result = response.GetResult <string>(); Assert.IsNotNull(result); } } } } }
public Result <TransactionFeeSetting> GetTxSettings() { ApiResponse response = GetResponseResult(TransactionApi.GetTxSettings()); return(base.GetResult <TransactionFeeSetting>(response)); }