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}
Constructors
- JsonRpcMethod(String method)
-
Creates a handler to invoke
methodwith params.const
Properties
Methods
-
decoder(
S value) → T -
Decodes the
resultproperty 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
paramsproperty value. -
request(
[Commitment? commitment]) → JsonRpcRequest -
Creates a JsonRpcRequest to invoke method with params. The
commitmentlevel is provided as a default value to all methods that query bank state. -
response(
Map< String, dynamic> json) → JsonRpcResponse<T> -
Parses the
jsonRPC response and returns the result. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited