Skip to content

Commit

Permalink
Make calculation for extra gas on "send*" RPC (neo-project#70)
Browse files Browse the repository at this point in the history
* Make calculation for extra gas on "send*" RPC

* Fix for the calculation when little overstep
  • Loading branch information
superboyiii authored and 陈志同 committed Oct 13, 2020
1 parent ea11186 commit ad71e7d
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion RpcWallet/RpcWallet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Akka.Actor;
using Akka.Actor;
using Microsoft.AspNetCore.Http;
using Neo.IO;
using Neo.IO.Json;
Expand Down Expand Up @@ -307,6 +307,19 @@ private JObject SendFrom(UIntBase assetId, UInt160 from, UInt160 to, string valu
ScriptHash = to
}
}, from: from, change_address: change_address, fee: fee);
if (tx.Size > 1024)
{
fee += Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m);
tx = Wallet.MakeTransaction(null, new[]
{
new TransferOutput
{
AssetId = assetId,
Value = amount,
ScriptHash = to
}
}, from: from, change_address: change_address, fee: fee);
}
if (tx == null)
throw new RpcException(-300, "Insufficient funds");
return SignAndRelay(tx);
Expand Down Expand Up @@ -334,6 +347,11 @@ private JObject SendMany(UInt160 from, JArray to, Fixed8 fee, UInt160 change_add
if (fee < Fixed8.Zero)
throw new RpcException(-32602, "Invalid params");
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);
tx = Wallet.MakeTransaction(null, outputs, from: from, change_address: change_address, fee: fee);
}
if (tx == null)
throw new RpcException(-300, "Insufficient funds");
return SignAndRelay(tx);
Expand All @@ -357,6 +375,19 @@ private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value
ScriptHash = scriptHash
}
}, change_address: change_address, fee: fee);
if (tx.Size > 1024)
{
fee += Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m);
tx = Wallet.MakeTransaction(null, new[]
{
new TransferOutput
{
AssetId = assetId,
Value = amount,
ScriptHash = scriptHash
}
}, change_address: change_address, fee: fee);
}
if (tx == null)
throw new RpcException(-300, "Insufficient funds");
return SignAndRelay(tx);
Expand Down

0 comments on commit ad71e7d

Please sign in to comment.