-
Notifications
You must be signed in to change notification settings - Fork 722
Feature/jsonrpc #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5889613
5174e7e
455e182
fc20927
3939de7
29d2dde
709cba9
903425d
0bbf2a3
2459679
d019715
d5353f0
41e4bc7
c9cf19e
4ee6777
fb2caa3
37c721a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ namespace Nevermind.Blockchain | |
| public interface IBlockchainProcessor | ||
| { | ||
| Block HeadBlock { get; } | ||
| //Currently processing block | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use /// comments instead |
||
| Block SuggestedBlock { get; } | ||
| BigInteger TotalDifficulty { get; } | ||
| void Process(Rlp blockRlp); // TODO: potentially do not return anything | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,12 +26,15 @@ public class PrivateKey | |
| private const int PrivateKeyLengthInBytes = 32; | ||
| private PublicKey _publicKey; | ||
|
|
||
| public PrivateKey() | ||
| :this(Random.GeneratePrivateKey()) | ||
| public PrivateKey() :this(Random.GeneratePrivateKey(), Guid.NewGuid()) | ||
| { | ||
| } | ||
|
|
||
| public PrivateKey(Hex key) | ||
| public PrivateKey(Hex key) : this(key, Guid.NewGuid()) | ||
| { | ||
| } | ||
|
|
||
| public PrivateKey(Hex key, Guid id) | ||
| { | ||
| if (key == null) | ||
| { | ||
|
|
@@ -44,6 +47,7 @@ public PrivateKey(Hex key) | |
| } | ||
|
|
||
| Hex = key; | ||
| Id = id; | ||
| } | ||
|
|
||
| public Hex Hex { get; } | ||
|
|
@@ -57,6 +61,8 @@ private PublicKey ComputePublicKey() | |
|
|
||
| public Address Address => PublicKey.Address; | ||
|
|
||
| public Guid Id { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we will need to review how we pass private key around in memory (need to be protected and overwritten), separately - let us discuss why we need Guid - can't we store by public key? (or is it to cover all the scenarios when public key is same? - rare) |
||
|
|
||
| public override string ToString() | ||
| { | ||
| return Hex.ToString(true); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,14 @@ public static class Random | |
|
|
||
| public static byte[] GeneratePrivateKey() | ||
| { | ||
| byte[] bytes = new byte[32]; | ||
| var bytes = new byte[32]; | ||
| SecureRandom.GetBytes(bytes); | ||
| return bytes; | ||
| } | ||
|
|
||
| public static byte[] GenerateRandomBytes(int lenght) | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if not behind interface then equally we can use SecureRandom.GetBytes directly, otherwise let us push it behind ISecureRandom so we can test with this class wherever used |
||
| var bytes = new byte[lenght]; | ||
| SecureRandom.GetBytes(bytes); | ||
| return bytes; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ internal Transaction Decode(object[] data) | |
| transaction.Signature = signature; | ||
| } | ||
|
|
||
| transaction.RecomputeHash(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any suggestion how to do that nicer? I did not like it in my code (for block header) and wanted to refactor
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe some change tracking and getter for hash that would always recompute when onvoked and any changes were made... |
||
| return transaction; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,11 @@ public bool Equals(Hex obj) | |
| return false; | ||
| } | ||
|
|
||
| public byte[] ToBytes() | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is implicit conversion operator, not sure if we need it ever
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not a great fan of the Hex class any more by the way, we will review when alpha version fiinished |
||
| return _bytes ?? (_bytes = ToBytes(_hexString)); | ||
| } | ||
|
|
||
| public override string ToString() | ||
| { | ||
| return ToString(true); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
|
|
||
| using System; | ||
|
|
||
| /* | ||
| * Copyright (c) 2018 Demerzel Solutions Limited | ||
| * This file is part of the Nethermind library. | ||
|
|
@@ -21,5 +24,7 @@ namespace Nevermind.Core | |
| public interface ILogger | ||
| { | ||
| void Log(string text); | ||
| void Debug(string text); | ||
| void Error(string text, Exception ex = null); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe better Error(string text) and Error(Exception ex) separately? |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| using System.Numerics; | ||
| using Nevermind.Core.Crypto; | ||
| using Nevermind.Core.Encoding; | ||
|
|
||
| namespace Nevermind.Core | ||
| { | ||
|
|
@@ -37,5 +38,11 @@ public class Transaction | |
| public bool IsMessageCall => Data != null; | ||
| public bool IsTransfer => !IsContractCreation && !IsMessageCall; | ||
| public bool IsValid { get; set; } | ||
| public Keccak Hash { get; set; } | ||
|
|
||
| public void RecomputeHash() | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have a single test for this (not that I never neglected it) |
||
| Hash = Keccak.Compute(Rlp.Encode(this)); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,5 +35,6 @@ public class TransactionReceipt | |
| public long GasUsed { get; set; } | ||
| public Bloom Bloom { get; set; } | ||
| public LogEntry[] Logs { get; set; } | ||
| public Address Recipient { get; set; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to learn more - this I guess is only in the network version but not in the one created by EVM |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using Nevermind.Core; | ||
| using Nevermind.Core.Crypto; | ||
|
|
||
| namespace Nevermind.Evm | ||
| { | ||
| public interface ITransactionStore | ||
| { | ||
| void AddTransaction(Transaction transaction); | ||
| void AddTransactionReceipt(Keccak transactionHash, TransactionReceipt transactionReceipt, Keccak blockhash); | ||
| Transaction GetTransaction(Keccak transactionHash); | ||
| TransactionReceipt GetTransactionReceipt(Keccak transactionHash); | ||
| bool WasProcessed(Keccak transactionHash); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does it mean? it may not be on the main chain even if it was added, maybe worth to clarify the API, let us discuss |
||
| //get hash of the block transaction was in | ||
| Keccak? GetBlockHash(Keccak transactionHash); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,7 +258,7 @@ public TransactionReceipt Execute( | |
| _stateProvider.Commit(); | ||
|
|
||
| block.GasUsed += spentGas; | ||
| return BuildTransactionReceipt(statusCode, logEntries, block.GasUsed); | ||
| return BuildTransactionReceipt(statusCode, logEntries, block.GasUsed, recipient); | ||
| } | ||
|
|
||
| private long Refund(long gasLimit, long unspentGas, TransactionSubstate substate, Address sender, BigInteger gasPrice) | ||
|
|
@@ -271,14 +271,15 @@ private long Refund(long gasLimit, long unspentGas, TransactionSubstate substate | |
| return spentGas; | ||
| } | ||
|
|
||
| private TransactionReceipt BuildTransactionReceipt(byte statusCode, List<LogEntry> logEntries, long gasUsedSoFar) | ||
| private TransactionReceipt BuildTransactionReceipt(byte statusCode, List<LogEntry> logEntries, long gasUsedSoFar, Address recipient) | ||
| { | ||
| TransactionReceipt transactionReceipt = new TransactionReceipt(); | ||
| transactionReceipt.Logs = logEntries.ToArray(); | ||
| transactionReceipt.Bloom = BuildBloom(logEntries); | ||
| transactionReceipt.GasUsed = gasUsedSoFar; | ||
| transactionReceipt.PostTransactionState = _stateProvider.StateRoot; | ||
| transactionReceipt.StatusCode = statusCode; | ||
| transactionReceipt.Recipient = recipient; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool but I guess it was never tested so worth adding a test if not there yet |
||
| return transactionReceipt; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finally instead