Skip to content
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

Add NEO SDK RPC module #850

Merged
merged 68 commits into from
Jul 30, 2019
Merged

Add NEO SDK RPC module #850

merged 68 commits into from
Jul 30, 2019

Conversation

chenquanyu
Copy link
Contributor

#849 NEO SDK based on RPC interfaces
Add NEO SDK RPC module
This PR contains the rpc client module for neo3 and the unit tests for all the methods

@codecov-io
Copy link

codecov-io commented Jun 21, 2019

Codecov Report

Merging #850 into master will increase coverage by 1.03%.
The diff coverage is 76.19%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #850      +/-   ##
==========================================
+ Coverage   52.59%   53.62%   +1.03%     
==========================================
  Files         179      193      +14     
  Lines       12707    13211     +504     
==========================================
+ Hits         6683     7085     +402     
- Misses       6024     6126     +102
Impacted Files Coverage Δ
neo/Network/RPC/Models/RpcNep5Balances.cs 0% <0%> (ø)
neo/Network/P2P/Payloads/TransactionAttribute.cs 21.73% <0%> (-7.68%) ⬇️
neo/Network/P2P/Payloads/Header.cs 58.97% <100%> (+7.45%) ⬆️
neo/Network/P2P/Payloads/Witness.cs 100% <100%> (ø) ⬆️
neo/Network/P2P/Payloads/BlockBase.cs 75% <100%> (+3%) ⬆️
neo/Network/P2P/Payloads/Block.cs 89.77% <100%> (+1.02%) ⬆️
neo/Network/RPC/Models/RpcPlugin.cs 100% <100%> (ø)
neo/Network/RPC/Models/RpcTransaction.cs 100% <100%> (ø)
neo/Network/RPC/Models/RpcValidateAddressResult.cs 100% <100%> (ø)
neo/Network/RPC/Models/RpcInvokeResult.cs 100% <100%> (ø)
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e2faf5...eee837a. Read the comment docs.

@erikzhang
Copy link
Member

We can move most of the classes to the Neo.Network.RPC namespace. And, do we really need the models? Such as Model/GetBlock.cs, Model/GetBlockHeader.cs. Can we just use Block and Header?

@chenquanyu
Copy link
Contributor Author

chenquanyu commented Jun 21, 2019

We can move most of the classes to the Neo.Network.RPC namespace. And, do we really need the models? Such as Model/GetBlock.cs, Model/GetBlockHeader.cs. Can we just use Block and Header?

Yes, we can inherit from 'Block' to add property "confirmations" and "nextblockhash".
I will make up FromJson method for the existing models.

Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks clear, nice design.

I think @jsolman will like.
What do you think @igormcoelho?

neo/SDK/RPC/RpcClient.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@igormcoelho igormcoelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work being done here... SDK is fundamental for any dev platform.
I recommend renaming quite a few things... GetBlock for example could be ModelBlock or SDKBlock, or in the worst case, Block using different namespace.. but it's confusing. This applies to all other classes.

@shargon shargon requested a review from erikzhang July 25, 2019 07:59
using System.Threading;
using System.Threading.Tasks;

namespace Neo.UnitTests.SDK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RpcClient has been moved to Neo.Network.RPC. So this namespace should be changed too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put it the same place with others


namespace Neo.Network.RPC
{
public class HttpService : IDisposable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this class, and move HttpClient into RpcClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

/// <summary>
/// Wrappar of NEO RPC APIs
/// </summary>
public interface IRpcClient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this interface?

using Neo.IO.Json;
using Neo.Network.P2P.Payloads;

namespace Neo.Network.RPC.Model
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
namespace Neo.Network.RPC.Model
namespace Neo.Network.RPC.Models

And many other classes are the same.

@@ -81,7 +81,7 @@ public RpcServer(NeoSystem system, Wallet wallet = null, long maxGasInvoke = def
this.MaxGasInvoke = maxGasInvoke;
}

private static JObject CreateErrorResponse(JObject id, int code, string message, JObject data = null)
internal static JObject CreateErrorResponse(JObject id, int code, string message, JObject data = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why internal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is covered in unit test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#943 (comment)

According to the discussion here, we don't need to test private methods. Testing for public methods can completely cover private methods.

{
// create block
var block = new Block();
TestUtils.SetupBlockWithValues(block, UInt256.Zero, out UInt256 merkRootVal, out UInt160 val160, out uint timestampVal, out uint indexVal, out Witness scriptVal, out Transaction[] transactionsVal, 0);
Copy link
Member

@shargon shargon Jul 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be ulong now, timestamp is in ms

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed👍

@longfeiWan9
Copy link
Member

@erikzhang should we open a new branch for all NEO3 SDK functions?

  1. RPC module is only the first module for SDK. We will also need to add wallet, transaction and smart contract invocation supports which gets data via RPC request instead of data from full node.
  2. With a new branch, we can avoid adding unfinished/partial SDK function into master branch.
  3. We can keep merging master into this new branch constantly, so we can avoid conflicts when we finally merge mature SDK branch back to master.

@erikzhang
Copy link
Member

should we open a new branch for all NEO3 SDK functions?

No. I don't think it's necessary.

@chenquanyu
Copy link
Contributor Author

chenquanyu commented Jul 25, 2019

We won't have REST in this PR, right?

No, the REST is more about RpcServer reconstruction, we won't have it in this PR.

@longfeiWan9
Copy link
Member

hi, all.
Any outstanding issues or updates for this pr ? We are waiting this PR to be merged, so we can move forward with other modules for SDK functions.

erikzhang
erikzhang previously approved these changes Jul 30, 2019
namespace Neo.UnitTests
{
[TestClass]
public class UT_RpcClient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be moved into a sub folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have moved the file to Network/RPC folder

@codecov-io
Copy link

codecov-io commented Jul 30, 2019

Codecov Report

Merging #850 into master will increase coverage by 1.02%.
The diff coverage is 76.19%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #850      +/-   ##
==========================================
+ Coverage   52.74%   53.76%   +1.02%     
==========================================
  Files         180      194      +14     
  Lines       12749    13253     +504     
==========================================
+ Hits         6724     7126     +402     
- Misses       6025     6127     +102
Impacted Files Coverage Δ
neo/Network/RPC/Models/RpcNep5Balances.cs 0% <0%> (ø)
neo/Network/P2P/Payloads/TransactionAttribute.cs 21.73% <0%> (-7.68%) ⬇️
neo/Network/P2P/Payloads/Header.cs 58.97% <100%> (+7.45%) ⬆️
neo/Network/P2P/Payloads/Witness.cs 100% <100%> (ø) ⬆️
neo/Network/P2P/Payloads/BlockBase.cs 75% <100%> (+3%) ⬆️
neo/Network/P2P/Payloads/Block.cs 89.77% <100%> (+1.02%) ⬆️
neo/Network/P2P/Payloads/ConsensusData.cs 100% <100%> (ø) ⬆️
neo/Network/RPC/Models/RpcTransaction.cs 100% <100%> (ø)
neo/Network/RPC/Models/RpcValidateAddressResult.cs 100% <100%> (ø)
neo/Network/RPC/Models/RpcInvokeResult.cs 100% <100%> (ø)
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 547234a...c5c0de1. Read the comment docs.

Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For maintenance it looks better. A great job!
Hope it also give all the flexibility you want for the SDK RPC module.

@vncoelho vncoelho merged commit cd99489 into neo-project:master Jul 30, 2019
Thacryba pushed a commit to simplitech/neo that referenced this pull request Feb 17, 2020
Tommo-L pushed a commit to Tommo-L/neo that referenced this pull request Jun 22, 2020
* Add NEO SDK based on RPC client

* add rpc interface methods for neo3

* update unit test

* add unit test

* Update TransactionHelper.cs

Changed for neo 3.0, not final yet.

* implement sdk rpc client methods

* backup files

* change class name

* remove uncompleted modules for pull request

* change json deserialize method with Neo JObject

* modified JSON implementation, added FromJson()

* more RPC change

* PR correction

* RPC module fix, remove newton.json

* fix

* fix getblock issue

* PR correction

* PR Correction

* PR Correction: rename RPC models

* PR Correction

* resolve conflicts

* Clean code

* Clean code

* Clean code

* Clean code

* Update RpcValidateAddressResult.cs

* Clean code

* PR correction

* Move test file to the right place
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants