JsonRpcMethod<S, T> class abstract

JSON RPC Method

An interface for JSON RPC methods.

Defines a JsonRpcMethod to invoke method with params (See JsonRpcContextMethod for response-context methods).

Use request to generate a new JSON RPC request and response to handle the result.

The decoder defines how the result property of a successful JSON RPC response is mapped from S to T.

Example

class GetBlockHeight extends JsonRpcMethod<int, int> {
  GetBlockHeight(): super('getBlockHeight');
  @override int decoder(final int value) => value;
  @override Object? params([Commitment? commitment]) => null;
}

final client = JsonRpcHttpClient(Cluster.devnet.uri);
final method = GetBlockHeight();
final response = await client.send(method.request(), method.response);
print(jsonEncode(response)); // {"jsonrpc":"2.0", "result":197469478, "id":1}
Implementers

Constructors

JsonRpcMethod.new(String method)
Creates a handler to invoke method with params.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
method String
The JSON RPC method name,
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

decoder(S value) → T
Decodes the result property of a successful JSON RPC response.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
params([Commitment? commitment]) Object?
Returns the JSON RPC request's params property value.
request([Commitment? commitment]) JsonRpcRequest
Creates a JsonRpcRequest to invoke method with params. The commitment level is provided as a default value to all methods that query bank state.
response(Map<String, dynamic> json) JsonRpcResponse<T>
Parses the json RPC response and returns the result.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited