Skip to content

Commit 630e339

Browse files
committed
Comments: Add detail description for RPC Method
1 parent 1328bb4 commit 630e339

File tree

7 files changed

+724
-17
lines changed

7 files changed

+724
-17
lines changed

src/Plugins/RpcServer/RpcMethodAttribute.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace Neo.Plugins.RpcServer
1515
{
16+
/// <summary>
17+
/// Indicates that the method is an RPC method.
18+
/// </summary>
1619
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
1720
public class RpcMethodAttribute : Attribute
1821
{

src/Plugins/RpcServer/RpcMethodWithParamsAttribute.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace Neo.Plugins.RpcServer
1515
{
16+
/// <summary>
17+
/// Indicates that the method is an RPC method with parameters.
18+
/// </summary>
1619
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
1720
public class RpcMethodWithParamsAttribute : Attribute
1821
{

src/Plugins/RpcServer/RpcServer.Blockchain.cs

Lines changed: 223 additions & 5 deletions
Large diffs are not rendered by default.

src/Plugins/RpcServer/RpcServer.Node.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ partial class RpcServer
2626

2727
/// <summary>
2828
/// Gets the current number of connections to the node.
29+
/// <para>Request format:</para>
30+
/// <code>{ "jsonrpc": "2.0", "id": 1,"method": "getconnectioncount"}
31+
/// </code>
32+
/// <para>Response format:</para>
33+
/// <code>{"jsonrpc": "2.0", "id": 1, "result": 10}</code>
2934
/// </summary>
3035
/// <returns>The number of connections as a JToken.</returns>
3136
[RpcMethodWithParams]
@@ -36,6 +41,19 @@ protected internal virtual JToken GetConnectionCount()
3641

3742
/// <summary>
3843
/// Gets information about the peers connected to the node.
44+
/// <para>Request format:</para>
45+
/// <code>{ "jsonrpc": "2.0", "id": 1,"method": "getpeers"}
46+
/// </code>
47+
/// <para>Response format:</para>
48+
/// <code>{
49+
/// "jsonrpc": "2.0",
50+
/// "id": 1,
51+
/// "result": {
52+
/// "unconnected": [{"address": "The address", "port": "The port"}],
53+
/// "bad": [],
54+
/// "connected": [{"address": "The address", "port": "The port"}]
55+
/// }
56+
/// }</code>
3957
/// </summary>
4058
/// <returns>A JObject containing information about unconnected, bad, and connected peers.</returns>
4159
[RpcMethodWithParams]
@@ -95,6 +113,37 @@ private static JObject GetRelayResult(VerifyResult reason, UInt256 hash)
95113

96114
/// <summary>
97115
/// Gets version information about the node, including network, protocol, and RPC settings.
116+
/// <para>Request format:</para>
117+
/// <code>{ "jsonrpc": "2.0", "id": 1,"method": "getversion"}
118+
/// </code>
119+
/// <para>Response format:</para>
120+
/// <code>{
121+
/// "jsonrpc": "2.0",
122+
/// "id": 1,
123+
/// "result": {
124+
/// "tcpport": 10333, // The TCP port,
125+
/// "nonce": 1, // The nonce,
126+
/// "useragent": "The user agent",
127+
/// "rpc": {
128+
/// "maxiteratorresultitems": 100, // The maximum number of items in the iterator result,
129+
/// "sessionenabled": false // Whether session is enabled,
130+
/// },
131+
/// "protocol": {
132+
/// "addressversion": 0x35, // The address version,
133+
/// "network": 5195086, // The network,
134+
/// "validatorscount": 0, // The number of validators,
135+
/// "msperblock": 15000, // The time per block in milliseconds,
136+
/// "maxtraceableblocks": 2102400, // The maximum traceable blocks,
137+
/// "maxvaliduntilblockincrement": 86400000 / 15000, // The maximum valid until block increment,
138+
/// "maxtransactionsperblock": 512, // The maximum number of transactions per block,
139+
/// "memorypoolmaxtransactions": 50000, // The maximum number of transactions in the memory pool,
140+
/// "initialgasdistribution": 5200000000000000, // The initial gas distribution,
141+
/// "hardforks": [{"name": "The hardfork name", "blockheight": 0/*The block height*/ }],
142+
/// "standbycommittee": ["The public key"],
143+
/// "seedlist": ["The seed list"]
144+
/// }
145+
/// }
146+
/// }</code>
98147
/// </summary>
99148
/// <returns>A JObject containing detailed version and configuration information.</returns>
100149
[RpcMethodWithParams]
@@ -147,6 +196,12 @@ private static string StripPrefix(string s, string prefix)
147196

148197
/// <summary>
149198
/// Sends a raw transaction to the network.
199+
/// <para>Request format:</para>
200+
/// <code>
201+
/// {"jsonrpc": "2.0", "id": 1,"method": "sendrawtransaction", "params": ["A Base64-encoded transaction"]}
202+
/// </code>
203+
/// <para>Response format:</para>
204+
/// <code>{"jsonrpc": "2.0", "id": 1, "result": {"hash": "The hash of the transaction"}}</code>
150205
/// </summary>
151206
/// <param name="base64Tx">The base64-encoded transaction.</param>
152207
/// <returns>A JToken containing the result of the transaction relay.</returns>
@@ -160,6 +215,11 @@ protected internal virtual JToken SendRawTransaction(string base64Tx)
160215

161216
/// <summary>
162217
/// Submits a new block to the network.
218+
/// <para>Request format:</para>
219+
/// <code>{"jsonrpc": "2.0", "id": 1,"method": "submitblock", "params": ["A Base64-encoded block"]}
220+
/// </code>
221+
/// <para>Response format:</para>
222+
/// <code>{"jsonrpc": "2.0", "id": 1, "result": {"hash": "The hash of the block"}}</code>
163223
/// </summary>
164224
/// <param name="base64Block">The base64-encoded block.</param>
165225
/// <returns>A JToken containing the result of the block submission.</returns>

src/Plugins/RpcServer/RpcServer.SmartContract.cs

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,61 @@ private static Witness[] WitnessesFromJson(JArray _params)
212212
}).ToArray();
213213
}
214214

215+
/// <summary>
216+
/// Invokes a function on a contract.
217+
/// <para>Request format:</para>
218+
/// <code>{
219+
/// "jsonrpc": "2.0",
220+
/// "id": 1,
221+
/// "method": "invokefunction",
222+
/// "params": [
223+
/// "An UInt160 ScriptHash", // the contract address
224+
/// "operation", // the operation to invoke
225+
/// [{"type": "ContractParameterType", "value": "The parameter value"}], // ContractParameter, the arguments
226+
/// [{
227+
/// "account": "An UInt160 or Base58Check address",
228+
/// "scopes": "WitnessScope", // WitnessScope
229+
/// "allowedcontracts": ["The contract hash(UInt160)"], // optional
230+
/// "allowedgroups": ["PublicKey"], // ECPoint, i.e. ECC PublicKey, optional
231+
/// "rules": [{"action": "WitnessRuleAction", "condition": {A json of WitnessCondition}}] // WitnessRule
232+
/// }], // A Signer array, optional
233+
/// [{"invocation": "A Base64-encoded string","verification": "A Base64-encoded string"}] // A Witness array, optional
234+
/// false // useDiagnostic, a bool value indicating whether to use diagnostic information, optional
235+
/// ]
236+
/// }</code>
237+
/// <para>Response format:</para>
238+
/// <code>{
239+
/// "jsonrpc": "2.0",
240+
/// "id": 1,
241+
/// "result": {
242+
/// "script": "A Base64-encoded string",
243+
/// "state": "A string of VMState",
244+
/// "gasconsumed": "An integer number in string",
245+
/// "exception": "The exception message",
246+
/// "stack": [{"type": "The stack item type", "value": "The stack item value"}],
247+
/// "notifications": [
248+
/// {"eventname": "The event name", "contract": "The contract hash", "state": {"interface": "A string", "id": "The GUID string"}}
249+
/// ], // The notifications, optional
250+
/// "diagnostics": {
251+
/// "invokedcontracts": {"hash": "The contract hash","call": [{"hash": "The contract hash"}]},
252+
/// "storagechanges": [{"state": "The state", "key": "The key", "value": "The value"}]
253+
/// }, // The diagnostics, optional, if useDiagnostic is true
254+
/// "session": "A GUID string" // The session id, optional
255+
/// }
256+
/// }</code>
257+
/// </summary>
258+
/// <param name="_params">An array containing the following elements:
259+
/// [0]: The script hash of the contract to invoke as a string.
260+
/// [1]: The operation to invoke as a string.
261+
/// [2]: The arguments to pass to the function as an array of ContractParameter. Optional.
262+
/// [3]: The signers as an array of Signer. Optional.
263+
/// [4]: The witnesses as an array of Witness. Optional.
264+
/// [5]: A boolean value indicating whether to use diagnostic information. Optional.
265+
/// </param>
266+
/// <returns>The result of the function invocation.</returns>
267+
/// <exception cref="RpcException">
268+
/// Thrown when the script hash is invalid, the contract is not found, or the verification fails.
269+
/// </exception>
215270
[RpcMethod]
216271
protected internal virtual JToken InvokeFunction(JArray _params)
217272
{
@@ -230,6 +285,57 @@ protected internal virtual JToken InvokeFunction(JArray _params)
230285
return GetInvokeResult(script, signers, witnesses, useDiagnostic);
231286
}
232287

288+
/// <summary>
289+
/// Invokes a script.
290+
/// <para>Request format:</para>
291+
/// <code>{
292+
/// "jsonrpc": "2.0",
293+
/// "id": 1,
294+
/// "method": "invokescript",
295+
/// "params": [
296+
/// "A Base64-encoded string", // the script to invoke
297+
/// [{
298+
/// "account": "An UInt160 or Base58Check address",
299+
/// "scopes": "WitnessScope", // WitnessScope
300+
/// "allowedcontracts": ["The contract hash(UInt160)"], // optional
301+
/// "allowedgroups": ["PublicKey"], // ECPoint, i.e. ECC PublicKey, optional
302+
/// "rules": [{"action": "WitnessRuleAction", "condition": {A json of WitnessCondition}}] // WitnessRule
303+
/// }], // A Signer array, optional
304+
/// [{"invocation": "A Base64-encoded string","verification": "A Base64-encoded string"}] // A Witness array, optional
305+
/// false // useDiagnostic, a bool value indicating whether to use diagnostic information, optional
306+
/// ]
307+
/// }</code>
308+
/// <para>Response format:</para>
309+
/// <code>{
310+
/// "jsonrpc": "2.0",
311+
/// "id": 1,
312+
/// "result": {
313+
/// "script": "A Base64-encoded string",
314+
/// "state": "A string of VMState",
315+
/// "gasconsumed": "An integer number in string",
316+
/// "exception": "The exception message",
317+
/// "stack": [{"type": "The stack item type", "value": "The stack item value"}],
318+
/// "notifications": [
319+
/// {"eventname": "The event name", "contract": "The contract hash", "state": {"interface": "A string", "id": "The GUID string"}}
320+
/// ], // The notifications, optional
321+
/// "diagnostics": {
322+
/// "invokedcontracts": {"hash": "The contract hash","call": [{"hash": "The contract hash"}]},
323+
/// "storagechanges": [{"state": "The state", "key": "The key", "value": "The value"}]
324+
/// }, // The diagnostics, optional, if useDiagnostic is true
325+
/// "session": "A GUID string" // The session id, optional
326+
/// }
327+
/// }</code>
328+
/// </summary>
329+
/// <param name="_params">An array containing the following elements:
330+
/// [0]: The script as a Base64-encoded string.
331+
/// [1]: The signers as an array of Signer. Optional.
332+
/// [2]: The witnesses as an array of Witness. Optional.
333+
/// [3]: A boolean value indicating whether to use diagnostic information. Optional.
334+
/// </param>
335+
/// <returns>The result of the script invocation.</returns>
336+
/// <exception cref="RpcException">
337+
/// Thrown when the script is invalid, the verification fails, or the script hash is invalid.
338+
/// </exception>
233339
[RpcMethod]
234340
protected internal virtual JToken InvokeScript(JArray _params)
235341
{
@@ -240,6 +346,27 @@ protected internal virtual JToken InvokeScript(JArray _params)
240346
return GetInvokeResult(script, signers, witnesses, useDiagnostic);
241347
}
242348

349+
/// <summary>
350+
/// <para>Request format:</para>
351+
/// <code>{
352+
/// "jsonrpc": "2.0",
353+
/// "id": 1,
354+
/// "method": "traverseiterator",
355+
/// "params": [
356+
/// "A GUID string(The session id)",
357+
/// "A GUID string(The iterator id)",
358+
/// "An integer number(The number of items to traverse)"
359+
/// ]
360+
/// }</code>
361+
/// <para>Response format:</para>
362+
/// <code>{
363+
/// "jsonrpc": "2.0",
364+
/// "id": 1,
365+
/// "result": [{"type": "The stack item type", "value": "The stack item value"}]
366+
/// }</code>
367+
/// </summary>
368+
/// <param name="_params"></param>
369+
/// <returns></returns>
243370
[RpcMethod]
244371
protected internal virtual JToken TraverseIterator(JArray _params)
245372
{
@@ -261,6 +388,21 @@ protected internal virtual JToken TraverseIterator(JArray _params)
261388
return json;
262389
}
263390

391+
/// <summary>
392+
/// Terminates a session.
393+
/// <para>Request format:</para>
394+
/// <code>{
395+
/// "jsonrpc": "2.0",
396+
/// "id": 1,
397+
/// "method": "terminatesession",
398+
/// "params": ["A GUID string(The session id)"]
399+
/// }</code>
400+
/// <para>Response format:</para>
401+
/// <code>{"jsonrpc": "2.0", "id": 1, "result": true}</code>
402+
/// </summary>
403+
/// <param name="_params">A 1-element array containing the session id as a GUID string.</param>
404+
/// <returns>True if the session is terminated successfully, otherwise false.</returns>
405+
/// <exception cref="RpcException">Thrown when the session id is invalid.</exception>
264406
[RpcMethod]
265407
protected internal virtual JToken TerminateSession(JArray _params)
266408
{
@@ -277,6 +419,25 @@ protected internal virtual JToken TerminateSession(JArray _params)
277419
return result;
278420
}
279421

422+
/// <summary>
423+
/// Gets the unclaimed gas of an address.
424+
/// <para>Request format:</para>
425+
/// <code>{
426+
/// "jsonrpc": "2.0",
427+
/// "id": 1,
428+
/// "method": "getunclaimedgas",
429+
/// "params": ["An UInt160 or Base58Check address"]
430+
/// }</code>
431+
/// <para>Response format:</para>
432+
/// <code>{"jsonrpc": "2.0", "id": 1, "result": {"unclaimed": "An integer in string", "address": "The address"}}</code>
433+
/// </summary>
434+
/// <param name="_params">An array containing the following elements:
435+
/// [0]: The address as a UInt160 or Base58Check address.
436+
/// </param>
437+
/// <returns>A JSON object containing the unclaimed gas and the address.</returns>
438+
/// <exception cref="RpcException">
439+
/// Thrown when the address is invalid.
440+
/// </exception>
280441
[RpcMethod]
281442
protected internal virtual JToken GetUnclaimedGas(JArray _params)
282443
{

src/Plugins/RpcServer/RpcServer.Utilities.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ namespace Neo.Plugins.RpcServer
1717
{
1818
partial class RpcServer
1919
{
20+
/// <summary>
21+
/// Lists all plugins.
22+
/// <para>Request format:</para>
23+
/// <code>{"jsonrpc": "2.0", "id": 1, "method": "listplugins"}</code>
24+
/// <para>Response format:</para>
25+
/// <code>{
26+
/// "jsonrpc": "2.0",
27+
/// "id": 1,
28+
/// "result": [
29+
/// {"name": "The plugin name", "version": "The plugin version", "interfaces": ["The plugin method name"]}
30+
/// ]
31+
/// }</code>
32+
/// </summary>
33+
/// <param name="_params">A empty array.</param>
34+
/// <returns>A JSON array containing the plugin information.</returns>
2035
[RpcMethod]
2136
protected internal virtual JToken ListPlugins(JArray _params)
2237
{
@@ -33,6 +48,19 @@ protected internal virtual JToken ListPlugins(JArray _params)
3348
}));
3449
}
3550

51+
/// <summary>
52+
/// Validates an address.
53+
/// <para>Request format:</para>
54+
/// <code>{"jsonrpc": "2.0", "id": 1, "method": "validateaddress", "params": ["The address"]}</code>
55+
/// <para>Response format:</para>
56+
/// <code>{
57+
/// "jsonrpc": "2.0",
58+
/// "id": 1,
59+
/// "result": {"address": "The address", "isvalid": true}
60+
/// }</code>
61+
/// </summary>
62+
/// <param name="_params">A 1-element array containing the address as a string.</param>
63+
/// <returns>A JSON object containing the address and whether it is valid.</returns>
3664
[RpcMethod]
3765
protected internal virtual JToken ValidateAddress(JArray _params)
3866
{

0 commit comments

Comments
 (0)