forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NEO SDK RPC module (neo-project#850)
* 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
- Loading branch information
1 parent
1064e77
commit 81d6754
Showing
23 changed files
with
1,482 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Neo.IO.Json; | ||
using Neo.Network.P2P.Payloads; | ||
|
||
namespace Neo.Network.RPC.Models | ||
{ | ||
public class RpcBlock | ||
{ | ||
public Block Block { get; set; } | ||
|
||
public int? Confirmations { get; set; } | ||
|
||
public UInt256 NextBlockHash { get; set; } | ||
|
||
public JObject ToJson() | ||
{ | ||
JObject json = Block.ToJson(); | ||
if (Confirmations != null) | ||
{ | ||
json["confirmations"] = Confirmations; | ||
json["nextblockhash"] = NextBlockHash.ToString(); | ||
} | ||
return json; | ||
} | ||
|
||
public static RpcBlock FromJson(JObject json) | ||
{ | ||
RpcBlock block = new RpcBlock(); | ||
block.Block = Block.FromJson(json); | ||
if (json["confirmations"] != null) | ||
{ | ||
block.Confirmations = (int)json["confirmations"].AsNumber(); | ||
block.NextBlockHash = UInt256.Parse(json["nextblockhash"].AsString()); | ||
} | ||
return block; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Neo.IO.Json; | ||
using Neo.Network.P2P.Payloads; | ||
|
||
namespace Neo.Network.RPC.Models | ||
{ | ||
public class RpcBlockHeader | ||
{ | ||
public Header Header { get; set; } | ||
|
||
public int? Confirmations { get; set; } | ||
|
||
public UInt256 NextBlockHash { get; set; } | ||
|
||
public JObject ToJson() | ||
{ | ||
JObject json = Header.ToJson(); | ||
if (Confirmations != null) | ||
{ | ||
json["confirmations"] = Confirmations; | ||
json["nextblockhash"] = NextBlockHash.ToString(); | ||
} | ||
return json; | ||
} | ||
|
||
public static RpcBlockHeader FromJson(JObject json) | ||
{ | ||
RpcBlockHeader block = new RpcBlockHeader(); | ||
block.Header = Header.FromJson(json); | ||
if (json["confirmations"] != null) | ||
{ | ||
block.Confirmations = (int)json["confirmations"].AsNumber(); | ||
block.NextBlockHash = UInt256.Parse(json["nextblockhash"].AsString()); | ||
} | ||
return block; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Neo.IO.Json; | ||
using Newtonsoft.Json; | ||
using System.Linq; | ||
|
||
namespace Neo.Network.RPC.Models | ||
{ | ||
public class RpcInvokeResult | ||
{ | ||
[JsonProperty(PropertyName = "script")] | ||
public string Script { get; set; } | ||
|
||
[JsonProperty(PropertyName = "state")] | ||
public string State { get; set; } | ||
|
||
[JsonProperty(PropertyName = "gas_consumed")] | ||
public string GasConsumed { get; set; } | ||
|
||
[JsonProperty(PropertyName = "stack")] | ||
public RpcStack[] Stack { get; set; } | ||
|
||
[JsonProperty(PropertyName = "tx")] | ||
public string Tx { get; set; } | ||
|
||
public JObject ToJson() | ||
{ | ||
JObject json = new JObject(); | ||
json["script"] = Script; | ||
json["state"] = State; | ||
json["gas_consumed"] = GasConsumed; | ||
json["stack"] = new JArray(Stack.Select(p => p.ToJson())); | ||
json["tx"] = Tx; | ||
return json; | ||
} | ||
|
||
public static RpcInvokeResult FromJson(JObject json) | ||
{ | ||
RpcInvokeResult invokeScriptResult = new RpcInvokeResult(); | ||
invokeScriptResult.Script = json["script"].AsString(); | ||
invokeScriptResult.State = json["state"].AsString(); | ||
invokeScriptResult.GasConsumed = json["gas_consumed"].AsString(); | ||
invokeScriptResult.Tx = json["tx"].AsString(); | ||
invokeScriptResult.Stack = ((JArray)json["stack"]).Select(p => RpcStack.FromJson(p)).ToArray(); | ||
return invokeScriptResult; | ||
} | ||
} | ||
|
||
public class RpcStack | ||
{ | ||
public string Type { get; set; } | ||
|
||
public string Value { get; set; } | ||
|
||
public JObject ToJson() | ||
{ | ||
JObject json = new JObject(); | ||
json["type"] = Type; | ||
json["value"] = Value; | ||
return json; | ||
} | ||
|
||
public static RpcStack FromJson(JObject json) | ||
{ | ||
RpcStack stackJson = new RpcStack(); | ||
stackJson.Type = json["type"].AsString(); | ||
stackJson.Value = json["value"].AsString(); | ||
return stackJson; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Neo.IO.Json; | ||
using System.Linq; | ||
using System.Numerics; | ||
|
||
namespace Neo.Network.RPC.Models | ||
{ | ||
public class RpcNep5Balances | ||
{ | ||
public string Address { get; set; } | ||
|
||
public RpcNep5Balance[] Balances { get; set; } | ||
|
||
public JObject ToJson() | ||
{ | ||
JObject json = new JObject(); | ||
json["address"] = Address; | ||
json["balance"] = Balances.Select(p => p.ToJson()).ToArray(); | ||
return json; | ||
} | ||
|
||
public static RpcNep5Balances FromJson(JObject json) | ||
{ | ||
RpcNep5Balances nep5Balance = new RpcNep5Balances(); | ||
nep5Balance.Address = json["address"].AsString(); | ||
//List<Balance> listBalance = new List<Balance>(); | ||
nep5Balance.Balances = ((JArray)json["balance"]).Select(p => RpcNep5Balance.FromJson(p)).ToArray(); | ||
return nep5Balance; | ||
} | ||
} | ||
|
||
public class RpcNep5Balance | ||
{ | ||
public UInt160 AssetHash { get; set; } | ||
|
||
public BigInteger Amount { get; set; } | ||
|
||
public uint LastUpdatedBlock { get; set; } | ||
|
||
public JObject ToJson() | ||
{ | ||
JObject json = new JObject(); | ||
json["asset_hash"] = AssetHash.ToArray().ToHexString(); | ||
json["amount"] = Amount.ToString(); | ||
json["last_updated_block"] = LastUpdatedBlock.ToString(); | ||
return json; | ||
} | ||
|
||
public static RpcNep5Balance FromJson(JObject json) | ||
{ | ||
RpcNep5Balance balance = new RpcNep5Balance(); | ||
balance.AssetHash = UInt160.Parse(json["asset_hash"].AsString()); | ||
balance.Amount = BigInteger.Parse(json["amount"].AsString()); | ||
balance.LastUpdatedBlock = uint.Parse(json["last_updated_block"].AsString()); | ||
return balance; | ||
} | ||
} | ||
} |
Oops, something went wrong.