Skip to content

Commit

Permalink
Add Max_Fee as the optional for gas limit. (neo-project#74)
Browse files Browse the repository at this point in the history
* Make calculation for extra gas on "send*" RPC (neo-project#70)

* Make calculation for extra gas on "send*" RPC

* Fix for the calculation when little overstep

* Delete the dependency which is for testing purpose

* Choose the max_fee between  fee and extra_fee

* Change error codes

* Update Settings.cs

* format
  • Loading branch information
superboyiii authored and 陈志同 committed Oct 13, 2020
1 parent ad71e7d commit 01dcb2c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
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);
}
}
}

0 comments on commit 01dcb2c

Please sign in to comment.