diff --git a/RpcWallet/RpcWallet.cs b/RpcWallet/RpcWallet.cs index ff9e91cb8..98bbfea80 100644 --- a/RpcWallet/RpcWallet.cs +++ b/RpcWallet/RpcWallet.cs @@ -21,6 +21,7 @@ public class RpcWallet : Plugin, IRpcPlugin public override void Configure() { + Settings.Load(GetConfiguration()); } public void PreProcess(HttpContext context, string method, JArray _params) @@ -309,7 +310,7 @@ private JObject SendFrom(UIntBase assetId, UInt160 from, UInt160 to, string valu }, from: from, change_address: change_address, fee: fee); if (tx.Size > 1024) { - fee += Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + fee = Fixed8.Max(Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m), fee); tx = Wallet.MakeTransaction(null, new[] { new TransferOutput @@ -322,6 +323,8 @@ private JObject SendFrom(UIntBase assetId, UInt160 from, UInt160 to, string valu } 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); } @@ -349,11 +352,13 @@ private JObject SendMany(UInt160 from, JArray to, Fixed8 fee, UInt160 change_add Transaction tx = Wallet.MakeTransaction(null, outputs, from: from, change_address: change_address, fee: fee); if (tx.Size > 1024) { - fee += Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + fee = Fixed8.Max(Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m), fee); 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); } @@ -377,7 +382,7 @@ private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value }, change_address: change_address, fee: fee); if (tx.Size > 1024) { - fee += Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + fee = Fixed8.Max(Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m), fee); tx = Wallet.MakeTransaction(null, new[] { new TransferOutput @@ -390,6 +395,8 @@ private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value } 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); } } diff --git a/RpcWallet/RpcWallet.csproj b/RpcWallet/RpcWallet.csproj index a88f11518..24a002d34 100644 --- a/RpcWallet/RpcWallet.csproj +++ b/RpcWallet/RpcWallet.csproj @@ -5,6 +5,13 @@ netstandard2.0 Neo.Plugins + + + + PreserveNewest + PreserveNewest + + diff --git a/RpcWallet/RpcWallet/config.json b/RpcWallet/RpcWallet/config.json new file mode 100644 index 000000000..752d78ff9 --- /dev/null +++ b/RpcWallet/RpcWallet/config.json @@ -0,0 +1,5 @@ +{ + "PluginConfiguration": { + "MaxFee": 0.1 + } +} diff --git a/RpcWallet/Settings.cs b/RpcWallet/Settings.cs new file mode 100644 index 000000000..1e94b2224 --- /dev/null +++ b/RpcWallet/Settings.cs @@ -0,0 +1,21 @@ +using Microsoft.Extensions.Configuration; + +namespace Neo.Plugins +{ + internal class Settings + { + public Fixed8 MaxFee { get; } + + public static Settings Default { get; private set; } + + private Settings(IConfigurationSection section) + { + this.MaxFee = Fixed8.Parse(section.GetValue("MaxFee", "0.1")); + } + + public static void Load(IConfigurationSection section) + { + Default = new Settings(section); + } + } +}