Skip to content

Commit

Permalink
change tx for rpc data to quantity on signature (#2745)
Browse files Browse the repository at this point in the history
* change tx for rpc data to quantity on signature

* fixed NDM api
  • Loading branch information
tkstanczak committed Feb 2, 2021
1 parent 2575f80 commit 32a9bf6
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public ITrieStore? TrieStore
set => _nethermindApi.TrieStore = value;
}

public ITrieStore? ReadOnlyTrieStore
public ReadOnlyTrieStore? ReadOnlyTrieStore
{
get => _nethermindApi.ReadOnlyTrieStore;
set => _nethermindApi.ReadOnlyTrieStore = value;
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Db/IRocksDbFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public interface IRocksDbFactory
{
IDb CreateDb(RocksDbSettings rocksDbSettings);

IColumnsDb<T> CreateColumnsDb<T>(RocksDbSettings rocksDbSettings);
IColumnsDb<T> CreateColumnsDb<T>(RocksDbSettings rocksDbSettings) where T : notnull;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
using Nethermind.Logging;
using Nethermind.Serialization.Json;
using Nethermind.Serialization.Rlp;
using Nethermind.Trie;
using Nethermind.TxPool;
using NSubstitute;
using NUnit.Framework;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.

using System;
using FluentAssertions;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.JsonRpc.Data;
using Nethermind.JsonRpc.Test.Data;
using Nethermind.Serialization.Json;
using NUnit.Framework;

namespace Nethermind.JsonRpc.Test.Modules
{
[Parallelizable(ParallelScope.Self)]
[TestFixture]
public class TransactionForRpcConverterTests : SerializationTestBase
{
[Test]
public void R_and_s_are_quantity_and_not_data()
{
byte[] r = new byte[32];
byte[] s = new byte[32];
r[1] = 1;
s[2] = 2;

Transaction tx = new Transaction();
tx.Signature = new Signature(r, s, 27);

TransactionForRpc txForRpc = new TransactionForRpc(tx);

EthereumJsonSerializer serializer = new EthereumJsonSerializer();
string serialized = serializer.Serialize(txForRpc);

serialized.Should().Contain("0x20000000000000000000000000000000000000000000000000000000000");
serialized.Should().Contain("0x1000000000000000000000000000000000000000000000000000000000000");
Console.WriteLine(serialized);
}
}
}
29 changes: 17 additions & 12 deletions src/Nethermind/Nethermind.JsonRpc/Data/TransactionForRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TransactionForRpc
{
public TransactionForRpc(Transaction transaction) : this(null, null, null, transaction) { }

public TransactionForRpc(Keccak blockHash, long? blockNumber, int? txIndex, Transaction transaction)
public TransactionForRpc(Keccak? blockHash, long? blockNumber, int? txIndex, Transaction transaction)
{
Hash = transaction.Hash;
Nonce = transaction.Nonce;
Expand All @@ -39,43 +39,48 @@ public TransactionForRpc(Keccak blockHash, long? blockNumber, int? txIndex, Tran
GasPrice = transaction.GasPrice;
Gas = transaction.GasLimit;
Input = Data = transaction.Data ?? transaction.Init;
R = transaction.Signature?.R;
S = transaction.Signature?.S;
V = (UInt256?) transaction.Signature?.V;

Signature? signature = transaction.Signature;
if (signature != null)
{
R = new UInt256(signature.R, true);
S = new UInt256(signature.S, true);
V = (UInt256?)signature.V;
}
}

// ReSharper disable once UnusedMember.Global
public TransactionForRpc()
{
}

public Keccak Hash { get; set; }
public Keccak? Hash { get; set; }
public UInt256? Nonce { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Include)]
public Keccak BlockHash { get; set; }
public Keccak? BlockHash { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Include)]
public long? BlockNumber { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Include)]
public long? TransactionIndex { get; set; }
public Address From { get; set; }
public Address? From { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Include)]
public Address To { get; set; }
public Address? To { get; set; }
public UInt256? Value { get; set; }
public UInt256? GasPrice { get; set; }
public long? Gas { get; set; }
public byte[] Data { get; set; }
public byte[]? Data { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Include)]
public byte[] Input { get; set; }
public byte[]? Input { get; set; }
public UInt256? V { get; set; }

public byte[] S { get; set; }
public UInt256? S { get; set; }

public byte[] R { get; set; }
public UInt256? R { get; set; }

public Transaction ToTransactionWithDefaults()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<LangVersion>9</LangVersion>
<Deterministic>true</Deterministic>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
Expand Down

0 comments on commit 32a9bf6

Please sign in to comment.