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

Expose counter for getnativecontracts #900

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions src/RpcClient/Models/RpcNativeContract.cs

This file was deleted.

6 changes: 3 additions & 3 deletions src/RpcClient/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static ContractState ContractStateFromJson(JObject json)
return new ContractState
{
Id = (int)json["id"].AsNumber(),
UpdateCounter = (ushort)json["updatecounter"].AsNumber(),
UpdateCounter = (ushort)(json["updatecounter"]?.AsNumber() ?? 0),
Hash = UInt160.Parse(json["hash"].AsString()),
Nef = RpcNefFile.FromJson((JObject)json["nef"]),
Manifest = ContractManifest.FromJson((JObject)json["manifest"])
Expand All @@ -270,10 +270,10 @@ public static ContractState ContractStateFromJson(JObject json)
/// <summary>
/// Get all native contracts.
/// </summary>
public async Task<RpcNativeContract[]> GetNativeContractsAsync()
public async Task<ContractState[]> GetNativeContractsAsync()
{
var result = await RpcSendAsync(GetRpcName()).ConfigureAwait(false);
return ((JArray)result).Select(p => RpcNativeContract.FromJson((JObject)p)).ToArray();
return ((JArray)result).Select(p => ContractStateFromJson((JObject)p)).ToArray();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/RpcServer/RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected virtual JToken GetCommittee(JArray _params)
[RpcMethod]
protected virtual JToken GetNativeContracts(JArray _params)
{
return new JArray(NativeContract.Contracts.Select(p => p.NativeContractToJson(system)));
return new JArray(NativeContract.Contracts.Select(p => NativeContract.ContractManagement.GetContract(system.StoreView, p.Hash).ToJson()));
}
}
}
14 changes: 0 additions & 14 deletions src/RpcServer/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,5 @@ public static JObject TransactionToJson(Transaction tx, ProtocolSettings setting
json["netfee"] = tx.NetworkFee.ToString();
return json;
}

public static JObject NativeContractToJson(this NativeContract contract, NeoSystem system)
{
var state = contract.GetContractState(system.Settings,
NativeContract.Ledger.CurrentIndex(system.StoreView));

return new JObject
{
["id"] = contract.Id,
["hash"] = contract.Hash.ToString(),
["nef"] = state.Nef.ToJson(),
["manifest"] = state.Manifest.ToJson()
};
}
}
}
8 changes: 8 additions & 0 deletions tests/Neo.Network.RPC.Tests/RpcTestCases.json
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@
"result": [
{
"id": -1,
"updatecounter": 0,
"hash": "0xa501d7d7d10983673b61b7a2d3a813b36f9f0e43",
"nef": {
"magic": 860243278,
Expand Down Expand Up @@ -1206,6 +1207,7 @@
},
{
"id": -2,
"updatecounter": 1,
"hash": "0x971d69c6dd10ce88e7dfffec1dc603c6125a8764",
"nef": {
"magic": 860243278,
Expand Down Expand Up @@ -1303,6 +1305,7 @@
},
{
"id": -3,
"updatecounter": 0,
"hash": "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
"nef": {
"magic": 860243278,
Expand Down Expand Up @@ -1507,6 +1510,7 @@
},
{
"id": -4,
"updatecounter": 0,
"hash": "0xd2a4cff31913016155e38e474a2c06d08be276cf",
"nef": {
"magic": 860243278,
Expand Down Expand Up @@ -1615,6 +1619,7 @@
},
{
"id": -5,
"updatecounter": 0,
"hash": "0x79bcd398505eb779df6e67e4be6c14cded08e2f2",
"nef": {
"magic": 860243278,
Expand Down Expand Up @@ -1796,6 +1801,7 @@
},
{
"id": -6,
"updatecounter": 0,
"hash": "0x597b1471bbce497b7809e2c8f10db67050008b02",
"nef": {
"magic": 860243278,
Expand Down Expand Up @@ -1859,6 +1865,7 @@
},
{
"id": -7,
"updatecounter": 0,
"hash": "0x8dc0e742cbdfdeda51ff8a8b78d46829144c80ee",
"nef": {
"magic": 860243278,
Expand Down Expand Up @@ -1967,6 +1974,7 @@
},
{
"id": -8,
"updatecounter": 0,
"hash": "0xa2b524b68dfe43a9d56af84f443c6b9843b8028c",
"nef": {
"magic": 860243278,
Expand Down
Loading