From e0b49b5d16c82a2ff67b45af2a6181cfa959f0d2 Mon Sep 17 00:00:00 2001 From: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Date: Thu, 21 Mar 2019 14:15:55 +0800 Subject: [PATCH 1/2] Make calculation for extra gas on "send*" RPC --- RpcWallet/RpcWallet.cs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/RpcWallet/RpcWallet.cs b/RpcWallet/RpcWallet.cs index 6c33f92b1..300583d0c 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); + 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); + 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); + 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); From 32343cbc1246e38e2bcc6feb9558ff40df7725ec Mon Sep 17 00:00:00 2001 From: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Date: Thu, 21 Mar 2019 15:19:37 +0800 Subject: [PATCH 2/2] Fix for the calculation when little overstep --- RpcWallet/RpcWallet.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RpcWallet/RpcWallet.cs b/RpcWallet/RpcWallet.cs index 300583d0c..ff9e91cb8 100644 --- a/RpcWallet/RpcWallet.cs +++ b/RpcWallet/RpcWallet.cs @@ -309,7 +309,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); + fee += Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); tx = Wallet.MakeTransaction(null, new[] { new TransferOutput @@ -349,7 +349,7 @@ 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); + 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) @@ -377,7 +377,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); + fee += Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); tx = Wallet.MakeTransaction(null, new[] { new TransferOutput