From ad71e7df50dfca84bbc7a39523c754cc423b431c Mon Sep 17 00:00:00 2001 From: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Date: Thu, 21 Mar 2019 16:32:41 +0800 Subject: [PATCH] Make calculation for extra gas on "send*" RPC (#70) * Make calculation for extra gas on "send*" RPC * Fix for the calculation when little overstep --- RpcWallet/RpcWallet.cs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/RpcWallet/RpcWallet.cs b/RpcWallet/RpcWallet.cs index 6c33f92b1..ff9e91cb8 100644 --- a/RpcWallet/RpcWallet.cs +++ b/RpcWallet/RpcWallet.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Microsoft.AspNetCore.Http; using Neo.IO; using Neo.IO.Json; @@ -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); @@ -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); @@ -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);