Skip to content

Commit

Permalink
Update NuGet versions of all modules (neo-project#174)
Browse files Browse the repository at this point in the history
* Update-package-rpc-client

* Update nuget

* Update Crypto.ECDsaVerify

* Update TransactionManager.cs

* Some fixes

* Change from public to protected as in level db (neo-project#177)

* Change from public to protected as in level db

* Update RocksDBStore.csproj

Co-authored-by: Shargon <[email protected]>

* Update neo nuget

* change network fee calculation (neo-project#178)

* change network fee calculation

* update to CI00847

* fix fee issue

* add UT for network fee

* Update versions

* Update src/RpcClient/TransactionManager.cs

Co-authored-by: Shargon <[email protected]>
Co-authored-by: Krain Chen <[email protected]>
  • Loading branch information
3 people authored and 陈志同 committed Oct 13, 2020
1 parent e0f838c commit e5e728f
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/ApplicationLogs/ApplicationLogs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-preview1</Version>
<Version>3.0.0-CI00847</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/LevelDBStore/LevelDBStore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-CI00817</Version>
<Version>3.0.0-CI00847</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI00817" />
<PackageReference Include="Neo" Version="3.0.0-CI00847" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/RocksDBStore/Plugins/Storage/RocksDBStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class RocksDBStore : Plugin, IStoragePlugin
/// <summary>
/// Configure
/// </summary>
public override void Configure()
protected override void Configure()
{
Settings.Load(GetConfiguration());
}
Expand Down
4 changes: 2 additions & 2 deletions src/RocksDBStore/RocksDBStore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-CI00810</Version>
<Version>3.0.0-CI00847</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins.Storage</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI00810" />
<PackageReference Include="Neo" Version="3.0.0-CI00847" />
<PackageReference Include="RocksDbNative" Version="6.2.2" />
<PackageReference Include="RocksDbSharp" Version="6.2.2" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/RpcClient/ContractClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Transaction CreateDeployContractTx(byte[] contractScript, ContractManifes
byte[] script;
using (ScriptBuilder sb = new ScriptBuilder())
{
sb.EmitSysCall(InteropService.Neo_Contract_Create, contractScript, manifest.ToString());
sb.EmitSysCall(InteropService.Contract.Create, contractScript, manifest.ToString());
script = sb.ToArray();
}

Expand Down
4 changes: 2 additions & 2 deletions src/RpcClient/RpcClient.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-CI00825</Version>
<Version>3.0.0-CI00847</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Network.RPC</RootNamespace>
<Authors>The Neo Project</Authors>
Expand All @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI00825" />
<PackageReference Include="Neo" Version="3.0.0-CI00847" />
</ItemGroup>

</Project>
67 changes: 31 additions & 36 deletions src/RpcClient/TransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using Neo.Network.RPC.Models;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using System;
using System.Linq;

namespace Neo.Network.RPC
{
Expand Down Expand Up @@ -62,9 +62,9 @@ public TransactionManager MakeTransaction(byte[] script, TransactionAttribute[]
Script = script,
Sender = sender,
ValidUntilBlock = height + Transaction.MaxValidUntilBlockIncrement,
Attributes = attributes ?? new TransactionAttribute[0],
Cosigners = cosigners ?? new Cosigner[0],
Witnesses = new Witness[0]
Attributes = attributes ?? Array.Empty<TransactionAttribute>(),
Cosigners = cosigners ?? Array.Empty<Cosigner>(),
Witnesses = Array.Empty<Witness>()
};

// Add witness hashes parameter to pass CheckWitness
Expand All @@ -84,56 +84,51 @@ public TransactionManager MakeTransaction(byte[] script, TransactionAttribute[]
context = new ContractParametersContext(Tx);

// set networkfee to estimate value when networkFee is 0
Tx.NetworkFee = networkFee == 0 ? EstimateNetworkFee() : networkFee;
Tx.NetworkFee = networkFee == 0 ? CalculateNetworkFee(true) : networkFee;

var gasBalance = nep5API.BalanceOf(NativeContract.GAS.Hash, sender);
if (gasBalance >= Tx.SystemFee + Tx.NetworkFee) return this;
throw new InvalidOperationException($"Insufficient GAS in address: {sender.ToAddress()}");
}

/// <summary>
/// Estimate NetworkFee, assuming the witnesses are basic Signature Contract
/// Calculate NetworkFee
/// </summary>
private long EstimateNetworkFee()
{
long networkFee = 0;
UInt160[] hashes = Tx.GetScriptHashesForVerifying(null);
int size = Transaction.HeaderSize + Tx.Attributes.GetVarSize() + Tx.Script.GetVarSize() + IO.Helper.GetVarSize(hashes.Length);

// assume the hashes are single Signature
foreach (var hash in hashes)
{
size += 166;
networkFee += ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES64] + ApplicationEngine.OpCodePrices[OpCode.PUSHBYTES33] + InteropService.GetPrice(InteropService.Neo_Crypto_ECDsaVerify, null);
}

networkFee += size * policyAPI.GetFeePerByte();
return networkFee;
}

/// <summary>
/// Calculate NetworkFee with context items
/// </summary>
private long CalculateNetworkFee()
/// <param name="isEstimate">assuming the witnesses are basic Signature Contract if set to true</param>
/// <returns></returns>
private long CalculateNetworkFee(bool isEstimate = false)
{
long networkFee = 0;
UInt160[] hashes = Tx.GetScriptHashesForVerifying(null);
int size = Transaction.HeaderSize + Tx.Attributes.GetVarSize() + Tx.Script.GetVarSize() + IO.Helper.GetVarSize(hashes.Length);
int size = Transaction.HeaderSize + Tx.Attributes.GetVarSize() + Tx.Cosigners.GetVarSize() + Tx.Script.GetVarSize() + IO.Helper.GetVarSize(hashes.Length);
foreach (UInt160 hash in hashes)
{
byte[] witness_script = context.GetScript(hash);
if (witness_script is null || witness_script.Length == 0)
byte[] witness_script = null;
if (isEstimate)
{
try
// assuming the witnesses are basic Signature Contract
var dummyKey = new byte[32];
dummyKey[31] = 0x01;
KeyPair one = new KeyPair(dummyKey);
witness_script = Contract.CreateSignatureRedeemScript(one.PublicKey);
}
else
{
// calculate NetworkFee with context items
witness_script = context.GetScript(hash);
if (witness_script is null || witness_script.Length == 0)
{
witness_script = rpcClient.GetContractState(hash.ToString())?.Script;
try
{
witness_script = rpcClient.GetContractState(hash.ToString())?.Script;
}
catch { }
}
catch { }
}

if (witness_script is null) continue;
if (witness_script is null) continue;
}

networkFee += Wallet.CalculateNetWorkFee(witness_script, ref size);
networkFee += Wallet.CalculateNetworkFee(witness_script, ref size);
}
networkFee += size * policyAPI.GetFeePerByte();
return networkFee;
Expand Down
2 changes: 1 addition & 1 deletion src/RpcNep5Tracker/RpcNep5Tracker.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>3.0.0-preview1</Version>
<Version>3.0.0-CI00847</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/RpcServer/RpcServer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-preview1</Version>
<Version>3.0.0-CI00847</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />
<PackageReference Include="Neo" Version="3.0.0-CI00828" />
<PackageReference Include="Neo" Version="3.0.0-CI00847" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/StatesDumper/StatesDumper.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-preview1</Version>
<Version>3.0.0-CI00847</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI00817" />
<PackageReference Include="Neo" Version="3.0.0-CI00847" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/SystemLog/SystemLog.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>3.0.0-preview1</Version>
<Version>3.0.0-CI00847</Version>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Neo.Plugins</RootNamespace>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.0-CI00817" />
<PackageReference Include="Neo" Version="3.0.0-CI00847" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion tests/Neo.Network.RPC.Tests/UT_ContractClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void TestDeployContract()
manifest.Features = ContractFeatures.HasStorage | ContractFeatures.Payable;
using (ScriptBuilder sb = new ScriptBuilder())
{
sb.EmitSysCall(InteropService.Neo_Contract_Create, new byte[1], manifest.ToString());
sb.EmitSysCall(InteropService.Contract.Create, new byte[1], manifest.ToString());
script = sb.ToArray();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.Network.RPC.Tests/UT_RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void TestGetContractState()
byte[] script;
using (var sb = new ScriptBuilder())
{
sb.EmitSysCall(InteropService.System_Runtime_GetInvocationCounter);
sb.EmitSysCall(InteropService.Runtime.GetInvocationCounter);
script = sb.ToArray();
}

Expand Down
14 changes: 12 additions & 2 deletions tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,26 @@ public void TestSign()
}
};

Cosigner[] cosigners = new Cosigner[1] {
new Cosigner{
Account = sender,
Scopes = WitnessScope.Global
}
};

byte[] script = new byte[1];
txManager.MakeTransaction(script, attributes)
txManager.MakeTransaction(script, attributes, cosigners)
.AddSignature(keyPair1)
.Sign();

// get signature from Witnesses
var tx = txManager.Tx;
byte[] signature = tx.Witnesses[0].InvocationScript.Skip(1).ToArray();
byte[] signature = tx.Witnesses[0].InvocationScript.Skip(2).ToArray();

Assert.IsTrue(Crypto.VerifySignature(tx.GetHashData(), signature, keyPair1.PublicKey.EncodePoint(false).Skip(1).ToArray()));
// verify network fee
long networkFee = tx.Size * (long)1000 + ApplicationEngine.OpCodePrices[OpCode.PUSHDATA1] + ApplicationEngine.OpCodePrices[OpCode.PUSHDATA1] + ApplicationEngine.OpCodePrices[OpCode.PUSHNULL] + InteropService.GetPrice(InteropService.Crypto.ECDsaVerify, null);
Assert.AreEqual(networkFee, tx.NetworkFee);

// duplicate sign should not add new witness
txManager.AddSignature(keyPair1).Sign();
Expand Down

0 comments on commit e5e728f

Please sign in to comment.