Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static async Task <ApiResponse> GetTxSettings()
        {
            ApiResponse response = new ApiResponse();

            try
            {
                TransactionFeeSetting setting = new TransactionFeeSetting();
                Transaction           trans   = new Transaction();

                TransactionFeeSettingOM result = await trans.GetTxSettings();

                if (result != null)
                {
                    setting.Confirmations = result.Confirmations;
                    setting.FeePerKB      = result.FeePerKB;
                    setting.Encrypt       = result.Encrypt;
                    response.Result       = Newtonsoft.Json.Linq.JToken.FromObject(setting);
                }
                else
                {
                    response.Result = null;
                }
            }
            catch (ApiCustomException ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.ErrorCode, ex.ToString());
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.ToString());
                response.Error = new ApiError(ex.HResult, ex.ToString());
            }
            return(response);
        }
Example #2
0
        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);
                        }
                    }
                }
            }
        }