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 RPC method getnativecontracts #462

Merged
merged 32 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
19866ff
Merge pull request #14 from neo-project/master
Nov 25, 2020
6dd0c37
[RpcServer] Querying contracts by ID/name (#378)
Nov 26, 2020
c7d1961
MPT in StateService from core (#410)
ZhangTao1596 Nov 27, 2020
0799d85
Unify GetUnclaimedGas and GetWalletUnclaimedGas with decimal (#413)
superboyiii Nov 27, 2020
b522dce
Fixed UT (Neo CI01089) (#416)
Dec 2, 2020
bd80d9e
Nep17 (#412)
Dec 7, 2020
3f1e022
a
Dec 17, 2020
0cb8a83
merge
Dec 17, 2020
f05644f
clear
Dec 17, 2020
615b974
Transfer bug fix (#429)
Dec 17, 2020
33141c1
Preview4 (#430)
superboyiii Dec 18, 2020
c5af4ea
Merge pull request #22 from neo-project/master
chenzhitong Dec 22, 2020
215a8cc
dotnet 5.0 (#407)
chenzhitong Dec 22, 2020
8780e1a
CI01123 (#435)
erikzhang Dec 22, 2020
417002a
Merge pull request #24 from neo-project/master
chenzhitong Dec 22, 2020
5774c81
Fix dotnet5 (#442)
Ashuaidehao Dec 25, 2020
c88b717
Merge pull request #28 from neo-project/master
chenzhitong Dec 29, 2020
7dcf459
Merge pull request #29 from neo-project/master
chenzhitong Dec 30, 2020
9ce4618
Merge pull request #30 from neo-project/master
chenzhitong Dec 30, 2020
865a000
Merge pull request #31 from neo-project/master
chenzhitong Jan 7, 2021
a0a0fc4
Merge branch 'master' into getnativecontract
chenzhitong Jan 13, 2021
5811343
Add RPC method getnativecontracts
chenzhitong Jan 13, 2021
4f4d31d
Add UT
chenzhitong Jan 13, 2021
dfda5de
Update src/RpcServer/Utility.cs
shargon Jan 13, 2021
849e2f9
Update src/RpcClient/Models/RpcNativeContract.cs
shargon Jan 13, 2021
93a1fba
()
chenzhitong Jan 13, 2021
3ee0a04
Merge branch 'getnativecontract' of https://github.com/chenzhitong/ne…
chenzhitong Jan 13, 2021
704260e
Update RpcTestCases.json
chenzhitong Jan 13, 2021
1dda4f8
Merge branch 'master' into getnativecontract
chenzhitong Jan 13, 2021
f27f79d
Merge branch 'master' into getnativecontract
superboyiii Jan 14, 2021
d0ac57a
Remove extra properties
shargon Jan 14, 2021
1147f72
Reorder
shargon Jan 14, 2021
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
39 changes: 39 additions & 0 deletions src/RpcClient/Models/RpcNativeContract.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.SmartContract.Manifest;

namespace Neo.Network.RPC.Models
{
public class RpcNativeContract
{
public int Id { get; set; }
public UInt160 Hash { get; set; }
public NefFile Nef { get; set; }
public ContractManifest Manifest { get; set; }
public uint ActiveBlockIndex { get; set; }

public static RpcNativeContract FromJson(JObject json)
{
return new RpcNativeContract
{
Id = (int)json["id"].AsNumber(),
Hash = UInt160.Parse(json["hash"].AsString()),
Nef = RpcNefFile.FromJson(json["nef"]),
Manifest = ContractManifest.FromJson(json["manifest"]),
ActiveBlockIndex = (uint)(json["activeblockindex"]?.AsNumber() ?? 0)
};
}

public JObject ToJson()
{
return new JObject
{
["id"] = Id,
["hash"] = Hash.ToString(),
["nef"] = Nef.ToJson(),
["manifest"] = Manifest.ToJson(),
["activeblockindex"] = ActiveBlockIndex
};
}
}
}
9 changes: 9 additions & 0 deletions src/RpcClient/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ public static ContractState ContractStateFromJson(JObject json)
};
}

/// <summary>
/// Get all native contracts.
/// </summary>
public async Task<RpcNativeContract[]> GetNativeContractsAsync()
{
var result = await RpcSendAsync(GetRpcName()).ConfigureAwait(false);
return ((JArray)result).Select(p => RpcNativeContract.FromJson(p)).ToArray();
}

/// <summary>
/// Obtains the list of unconfirmed transactions in memory.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/RpcServer/RpcServer.Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,11 @@ protected virtual JObject GetCommittee(JArray _params)
using SnapshotView snapshot = Blockchain.Singleton.GetSnapshot();
return new JArray(NativeContract.NEO.GetCommittee(snapshot).Select(p => (JObject)p.ToString()));
}

[RpcMethod]
protected virtual JObject GetNativeContracts(JArray _params)
{
return new JArray(NativeContract.Contracts.Select(p => p.NativeContractToJson()));
}
}
}
15 changes: 12 additions & 3 deletions src/RpcServer/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Neo.IO.Json;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract.Native;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Neo.Plugins
{
Expand All @@ -24,5 +21,17 @@ public static JObject TransactionToJson(Transaction tx)
json["netfee"] = new BigDecimal(tx.NetworkFee, NativeContract.GAS.Decimals).ToString();
return json;
}

public static JObject NativeContractToJson(this NativeContract contract)
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
{
return new JObject
{
["id"] = contract.Id,
["hash"] = contract.Hash.ToString(),
["nef"] = contract.Nef.ToJson(),
["manifest"] = contract.Manifest.ToJson(),
["activeblockindex"] = contract.ActiveBlockIndex
};
}
}
}
Loading