Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix size calculation (neo-project#75)
Browse files Browse the repository at this point in the history
superboyiii authored and 陈志同 committed Oct 13, 2020

Verified

This commit was signed with the committer’s verified signature.
simeonschaub Simeon David Schaub
1 parent b0e5e1c commit df34356
Showing 1 changed file with 56 additions and 26 deletions.
82 changes: 56 additions & 26 deletions RpcWallet/RpcWallet.cs
Original file line number Diff line number Diff line change
@@ -308,21 +308,31 @@ 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");

ContractParametersContext transContext = new ContractParametersContext(tx);
Wallet.Sign(transContext);
tx.Witnesses = transContext.GetWitnesses();
if (tx.Size > 1024)
{
fee = Fixed8.Max(Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m), fee);
tx = Wallet.MakeTransaction(null, new[]
Fixed8 calFee = Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m);
if (fee < calFee)
{
new TransferOutput
{
AssetId = assetId,
Value = amount,
ScriptHash = to
}
}, from: from, change_address: change_address, fee: fee);
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");
}
}
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);
@@ -350,13 +360,23 @@ 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 == null)
throw new RpcException(-300, "Insufficient funds");

ContractParametersContext transContext = new ContractParametersContext(tx);
Wallet.Sign(transContext);
tx.Witnesses = transContext.GetWitnesses();
if (tx.Size > 1024)
{
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);
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 (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);
@@ -380,21 +400,31 @@ 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");

ContractParametersContext transContext = new ContractParametersContext(tx);
Wallet.Sign(transContext);
tx.Witnesses = transContext.GetWitnesses();
if (tx.Size > 1024)
{
fee = Fixed8.Max(Fixed8.FromDecimal(tx.Size * 0.00001m + 0.001m), fee);
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");
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);

0 comments on commit df34356

Please sign in to comment.