JsonRpcMethodBuilder<S, T> class

JSON RPC Method Builder

A JSON RPC method handler for batch requests.

A batch request contains multiple JSON RPC requests and returns a response for each request.

Use add to append a method to the request.

For methods with different response types use JsonRpcMethodBuilder<dynamic, dynamic>.

Example

class GetBlockHeight extends JsonRpcMethod<int, int> {
  GetBlockHeight(): super('getBlockHeight');
  @override int decoder(final int value) => value;
}

class GetBalance extends JsonRpcContextMethod<int, int> {
  GetBalance(final String pubkey): super('getBalance', values: [pubkey]);
  @override int valueDecoder(final int value) => value;
}

final client = JsonRpcHttpClient(Cluster.devnet.uri);
final method = JsonRpcMethodBuilder<dynamic, dynamic>([
  GetBlockHeight(),
  GetBalance('83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri')
]);
final response = await client.sendAll(method.request(), method.response);
print(jsonEncode(response));  // [
                              //    {"jsonrpc":"2.0","result":1,"id":1},
                              //    {"jsonrpc":"2.0","result":{"context":{"slot":1},"value":0},"id":1}
                              //  ]

Constructors

JsonRpcMethodBuilder.new([List<JsonRpcMethod<S, T>>? methods])
An additive method builder.

Properties

hashCode int
The hash code for this object.
no setterinherited
length int
Returns the number of methods in the request.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(JsonRpcMethod<S, T> method) → void
Adds a method handler.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
request([Commitment? commitment]) List<JsonRpcRequest>
Creates a batch JsonRpcRequest to invoke multiple methods in a single request. The commitment level is applied as the default value to all methods that query bank state.
response(List<Map<String, dynamic>> json) List<JsonRpcResponse<T>>
Parses the json RPC response and returns the batch result.
toString() String
A string representation of this object.
inherited

Operators

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