Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Max_Fee as the optional for gas limit. #74

Merged
merged 7 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions RpcWallet/RpcWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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
Expand All @@ -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);
}
}
Expand Down
7 changes: 7 additions & 0 deletions RpcWallet/RpcWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Update="RpcWallet\config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="2.10.0" />
Expand Down
5 changes: 5 additions & 0 deletions RpcWallet/RpcWallet/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"PluginConfiguration": {
"MaxFee": 0.1
}
}
21 changes: 21 additions & 0 deletions RpcWallet/Settings.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}