From 30bde20648a613848cd866939a69f31e1dbb1e76 Mon Sep 17 00:00:00 2001 From: erikzhang Date: Mon, 22 Apr 2019 23:15:07 +0800 Subject: [PATCH] format --- RpcWallet/RpcWallet.cs | 93 ++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/RpcWallet/RpcWallet.cs b/RpcWallet/RpcWallet.cs index a6a71d4f7..bae634a48 100644 --- a/RpcWallet/RpcWallet.cs +++ b/RpcWallet/RpcWallet.cs @@ -313,17 +313,17 @@ private JObject SendFrom(UIntBase assetId, UInt160 from, UInt160 to, string valu ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); - if (transContext.Completed) + if (!transContext.Completed) + return transContext.ToJson(); + tx.Witnesses = transContext.GetWitnesses(); + if (tx.Size > 1024) { - tx.Witnesses = transContext.GetWitnesses(); - if (tx.Size > 1024) + Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + if (fee < calFee) { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) + fee = calFee; + tx = Wallet.MakeTransaction(null, new[] { - fee = calFee; - tx = Wallet.MakeTransaction(null, new[] - { new TransferOutput { AssetId = assetId, @@ -331,18 +331,13 @@ private JObject SendFrom(UIntBase assetId, UInt160 from, UInt160 to, string valu ScriptHash = to } }, from: from, change_address: change_address, fee: fee); - if (tx == null) - throw new RpcException(-300, "Insufficient funds"); - } + if (tx == null) + throw new RpcException(-300, "Insufficient funds"); } - if (fee > Settings.Default.MaxFee) - throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); - return SignAndRelay(tx); - } - else - { - return transContext.ToJson(); } + if (fee > Settings.Default.MaxFee) + throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); + return SignAndRelay(tx); } private JObject SendMany(UInt160 from, JArray to, Fixed8 fee, UInt160 change_address) @@ -372,28 +367,23 @@ private JObject SendMany(UInt160 from, JArray to, Fixed8 fee, UInt160 change_add ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); - if (transContext.Completed) + if (!transContext.Completed) + return transContext.ToJson(); + tx.Witnesses = transContext.GetWitnesses(); + if (tx.Size > 1024) { - tx.Witnesses = transContext.GetWitnesses(); - if (tx.Size > 1024) + Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + if (fee < calFee) { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) - { - fee = calFee; - tx = Wallet.MakeTransaction(null, outputs, from: from, change_address: change_address, fee: fee); - if (tx == null) - throw new RpcException(-300, "Insufficient funds"); - } + fee = calFee; + tx = Wallet.MakeTransaction(null, outputs, from: from, change_address: change_address, fee: fee); + if (tx == null) + throw new RpcException(-300, "Insufficient funds"); } - if (fee > Settings.Default.MaxFee) - throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); - return SignAndRelay(tx); - } - else - { - return transContext.ToJson(); } + if (fee > Settings.Default.MaxFee) + throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); + return SignAndRelay(tx); } private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value, Fixed8 fee, UInt160 change_address) @@ -419,17 +409,17 @@ private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); - if(transContext.Completed) + if (!transContext.Completed) + return transContext.ToJson(); + tx.Witnesses = transContext.GetWitnesses(); + if (tx.Size > 1024) { - tx.Witnesses = transContext.GetWitnesses(); - if (tx.Size > 1024) + Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + if (fee < calFee) { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) + fee = calFee; + tx = Wallet.MakeTransaction(null, new[] { - fee = calFee; - tx = Wallet.MakeTransaction(null, new[] - { new TransferOutput { AssetId = assetId, @@ -437,18 +427,13 @@ private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value ScriptHash = scriptHash } }, change_address: change_address, fee: fee); - if (tx == null) - throw new RpcException(-300, "Insufficient funds"); - } + if (tx == null) + throw new RpcException(-300, "Insufficient funds"); } - if (fee > Settings.Default.MaxFee) - throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); - return SignAndRelay(tx); - } - else - { - return transContext.ToJson(); } + if (fee > Settings.Default.MaxFee) + throw new RpcException(-301, "The necessary fee is more than the Max_fee, this transaction is failed. Please increase your Max_fee value."); + return SignAndRelay(tx); } } }