-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from all commits
03c9a20
4f84a63
16c1471
79523dd
fe06992
b5b2cd6
efd27a8
c78e965
cf7a184
66b269c
26b4334
8c0c37f
b2705be
3ae6480
5de69a0
ca1048e
af6d7e0
2f58594
d5fa4a7
90b225c
a08d5e9
238abd5
7c193b5
71dad15
e2b187b
0d58ad6
0d5f720
6ecf691
cfa4622
663111e
a8df8e7
8cb2413
789eb26
3064b9e
8d27ccb
ad33da2
ec12ede
afae7b1
53d9ef3
dc46b10
058819b
4fd233b
4710d14
4b630b2
403b38d
5920a48
10a0597
a289067
664ca6c
51088ee
2442fe7
137ddb5
ac169c6
8ff77b6
4bc742d
b958970
ea0b6b4
b01b353
0d9b99a
4d3e3a2
73a53ac
eee837a
7da09eb
2214846
51e30f3
881af0b
b7403ec
c5c0de1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
using Neo.Ledger; | ||
using Neo.IO.Json; | ||
using Neo.Ledger; | ||
using Neo.Wallets; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Neo.Network.P2P.Payloads | ||
{ | ||
|
@@ -51,5 +54,14 @@ public TrimmedBlock Trim() | |
Hashes = new UInt256[0] | ||
}; | ||
} | ||
|
||
public new static Header FromJson(JObject json) | ||
{ | ||
Header header = new Header(); | ||
BlockBase blockBase = header; | ||
blockBase.FromJson(json); | ||
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. ((BlockBase)header).FromJson 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 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. @lock9 what is wrong here? |
||
return header; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -177,6 +177,21 @@ public JObject ToJson() | |||
return json; | ||||
} | ||||
|
||||
public static Transaction FromJson(JObject json) | ||||
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 think the easiest way to recover neo/neo/Network/RPC/RpcServer.cs Line 173 in 897df9c
Then you can easily get the The block is the same. 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 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. Yes. But in SDK, you just receive it and convert it into a 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. @erikzhang dalao, so we only need to provide the GetRawTransaction() method with verbose set to false inside, and let the developers using this method to decide if they need to deserialize Transaction from the HEX, am I understanding this right? 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 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. This SDK is intended to be used mainly by code? 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. Yes, this is an SDK for developers. |
||||
{ | ||||
Transaction tx = new Transaction(); | ||||
tx.Version = byte.Parse(json["version"].AsString()); | ||||
tx.Nonce = uint.Parse(json["nonce"].AsString()); | ||||
tx.Sender = json["sender"].AsString().ToScriptHash(); | ||||
tx.SystemFee = long.Parse(json["sys_fee"].AsString()); | ||||
tx.NetworkFee = long.Parse(json["net_fee"].AsString()); | ||||
tx.ValidUntilBlock = uint.Parse(json["valid_until_block"].AsString()); | ||||
tx.Attributes = ((JArray)json["attributes"]).Select(p => TransactionAttribute.FromJson(p)).ToArray(); | ||||
tx.Script = json["script"].AsString().HexToBytes(); | ||||
tx.Witnesses = ((JArray)json["witnesses"]).Select(p => Witness.FromJson(p)).ToArray(); | ||||
return tx; | ||||
} | ||||
|
||||
bool IInventory.Verify(Snapshot snapshot) | ||||
{ | ||||
return Verify(snapshot, Enumerable.Empty<Transaction>()); | ||||
|
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; | ||
} | ||
} | ||
} |
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; | ||
} | ||
} | ||
} |
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; | ||
} | ||
} | ||
} |
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; | ||
} | ||
} | ||
} |
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.
((BlockBase)block).FromJson