From 80b831baac8f5a4a3804d788fd07112f004a7522 Mon Sep 17 00:00:00 2001 From: Owen Zhang <38493437+superboyiii@users.noreply.github.com> Date: Mon, 22 Apr 2019 22:25:20 +0800 Subject: [PATCH 1/3] Fix output json for multisigaddress transaction Fix output json for multisigaddress transaction --- RpcWallet/RpcWallet.cs | 109 ++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 44 deletions(-) diff --git a/RpcWallet/RpcWallet.cs b/RpcWallet/RpcWallet.cs index 4807fb3cc..a6a71d4f7 100644 --- a/RpcWallet/RpcWallet.cs +++ b/RpcWallet/RpcWallet.cs @@ -313,29 +313,36 @@ private JObject SendFrom(UIntBase assetId, UInt160 from, UInt160 to, string valu ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); - tx.Witnesses = transContext.GetWitnesses(); - if (tx.Size > 1024) + if (transContext.Completed) { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) + tx.Witnesses = transContext.GetWitnesses(); + if (tx.Size > 1024) { - fee = calFee; - tx = Wallet.MakeTransaction(null, new[] + Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + if (fee < calFee) { - new TransferOutput + fee = calFee; + 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"); + }, 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); + } + else + { + return transContext.ToJson(); } - 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); } private JObject SendMany(UInt160 from, JArray to, Fixed8 fee, UInt160 change_address) @@ -365,21 +372,28 @@ private JObject SendMany(UInt160 from, JArray to, Fixed8 fee, UInt160 change_add ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); - tx.Witnesses = transContext.GetWitnesses(); - if (tx.Size > 1024) + if (transContext.Completed) { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) + tx.Witnesses = transContext.GetWitnesses(); + if (tx.Size > 1024) { - fee = calFee; - tx = Wallet.MakeTransaction(null, outputs, from: from, change_address: change_address, fee: fee); - if (tx == null) - throw new RpcException(-300, "Insufficient funds"); - } + Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + if (fee < calFee) + { + fee = calFee; + 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); + } + else + { + return transContext.ToJson(); } - 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); } private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value, Fixed8 fee, UInt160 change_address) @@ -405,29 +419,36 @@ private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); - tx.Witnesses = transContext.GetWitnesses(); - if (tx.Size > 1024) + if(transContext.Completed) { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) + tx.Witnesses = transContext.GetWitnesses(); + if (tx.Size > 1024) { - fee = calFee; - tx = Wallet.MakeTransaction(null, new[] + Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + if (fee < calFee) { - new TransferOutput + fee = calFee; + tx = Wallet.MakeTransaction(null, new[] { - AssetId = assetId, - Value = amount, - ScriptHash = scriptHash - } - }, 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); + new TransferOutput + { + AssetId = assetId, + Value = amount, + ScriptHash = scriptHash + } + }, 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); + } + else + { + return transContext.ToJson(); + } } } } From 30bde20648a613848cd866939a69f31e1dbb1e76 Mon Sep 17 00:00:00 2001 From: erikzhang Date: Mon, 22 Apr 2019 23:15:07 +0800 Subject: [PATCH 2/3] format --- RpcWallet/RpcWallet.cs | 93 ++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/RpcWallet/RpcWallet.cs b/RpcWallet/RpcWallet.cs index a6a71d4f7..bae634a48 100644 --- a/RpcWallet/RpcWallet.cs +++ b/RpcWallet/RpcWallet.cs @@ -313,17 +313,17 @@ private JObject SendFrom(UIntBase assetId, UInt160 from, UInt160 to, string valu ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); - if (transContext.Completed) + if (!transContext.Completed) + return transContext.ToJson(); + tx.Witnesses = transContext.GetWitnesses(); + if (tx.Size > 1024) { - tx.Witnesses = transContext.GetWitnesses(); - if (tx.Size > 1024) + Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + if (fee < calFee) { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) + fee = calFee; + tx = Wallet.MakeTransaction(null, new[] { - fee = calFee; - tx = Wallet.MakeTransaction(null, new[] - { new TransferOutput { AssetId = assetId, @@ -331,18 +331,13 @@ private JObject SendFrom(UIntBase assetId, UInt160 from, UInt160 to, string valu ScriptHash = to } }, from: from, change_address: change_address, fee: fee); - if (tx == null) - throw new RpcException(-300, "Insufficient funds"); - } + 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); - } - else - { - return transContext.ToJson(); } + 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); } private JObject SendMany(UInt160 from, JArray to, Fixed8 fee, UInt160 change_address) @@ -372,28 +367,23 @@ private JObject SendMany(UInt160 from, JArray to, Fixed8 fee, UInt160 change_add ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); - if (transContext.Completed) + if (!transContext.Completed) + return transContext.ToJson(); + tx.Witnesses = transContext.GetWitnesses(); + if (tx.Size > 1024) { - tx.Witnesses = transContext.GetWitnesses(); - if (tx.Size > 1024) + Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + if (fee < calFee) { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) - { - fee = calFee; - tx = Wallet.MakeTransaction(null, outputs, from: from, change_address: change_address, fee: fee); - if (tx == null) - throw new RpcException(-300, "Insufficient funds"); - } + fee = calFee; + 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); - } - else - { - return transContext.ToJson(); } + 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); } private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value, Fixed8 fee, UInt160 change_address) @@ -419,17 +409,17 @@ private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value ContractParametersContext transContext = new ContractParametersContext(tx); Wallet.Sign(transContext); - if(transContext.Completed) + if (!transContext.Completed) + return transContext.ToJson(); + tx.Witnesses = transContext.GetWitnesses(); + if (tx.Size > 1024) { - tx.Witnesses = transContext.GetWitnesses(); - if (tx.Size > 1024) + Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); + if (fee < calFee) { - Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m); - if (fee < calFee) + fee = calFee; + tx = Wallet.MakeTransaction(null, new[] { - fee = calFee; - tx = Wallet.MakeTransaction(null, new[] - { new TransferOutput { AssetId = assetId, @@ -437,18 +427,13 @@ private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value ScriptHash = scriptHash } }, change_address: change_address, fee: fee); - if (tx == null) - throw new RpcException(-300, "Insufficient funds"); - } + 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); - } - else - { - return transContext.ToJson(); } + 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); } } } From 78d7f7827b318c53d4766f8b4b72e7cf1235c574 Mon Sep 17 00:00:00 2001 From: erikzhang Date: Mon, 22 Apr 2019 23:16:43 +0800 Subject: [PATCH 3/3] format --- RpcWallet/RpcWallet.cs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/RpcWallet/RpcWallet.cs b/RpcWallet/RpcWallet.cs index bae634a48..3d934b8b8 100644 --- a/RpcWallet/RpcWallet.cs +++ b/RpcWallet/RpcWallet.cs @@ -324,13 +324,13 @@ private JObject SendFrom(UIntBase assetId, UInt160 from, UInt160 to, string valu fee = calFee; tx = Wallet.MakeTransaction(null, new[] { - new TransferOutput - { - AssetId = assetId, - Value = amount, - ScriptHash = to - } - }, from: from, change_address: change_address, fee: fee); + 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"); } @@ -420,13 +420,13 @@ private JObject SendToAddress(UIntBase assetId, UInt160 scriptHash, string value fee = calFee; tx = Wallet.MakeTransaction(null, new[] { - new TransferOutput - { - AssetId = assetId, - Value = amount, - ScriptHash = scriptHash - } - }, change_address: change_address, fee: fee); + new TransferOutput + { + AssetId = assetId, + Value = amount, + ScriptHash = scriptHash + } + }, change_address: change_address, fee: fee); if (tx == null) throw new RpcException(-300, "Insufficient funds"); }