copyWith method

JsonRpcRequest copyWith({
  1. Enum? method,
  2. List<Object>? params,
  3. int? id,
})

Creates a JSON JsonRpcRequest to invoke a method.

The method's parameters are passed using the params list and config object.

JsonRpcRequest.build(                                   // {
  Method.getAccountInfo,                            //   'jsonrpc': '2.0',
  [                                                 //   'id': 1,
    '3C4iYswhNe7Z2LJvxc9qQmF55rsKDUGdiuKVUGpTbRsK', //   'method': 'getAccountInfo',
  ],                                                //   'params': [
  GetAccountInfoConfig(                             //     '3C4iYswh...UGpTbRsK',
    id: 1,                                          //     {
    encoding: AccountEncoding.base64,               //       'encoding': 'base64',
  ),                                                //     },
);                                                  //   ],
                                                    // }

Creates a copy of this instance, applying the provided parameters to the new instance.

const JsonRpcRequest request = JsonRpcRequest(
  Method.getAccountInfo, 
  params: ['4fGh...GTh6'],
  id: 0,
);
final JsonRpcRequest newRequest = request.copyWith(id: 1);
print(newRequest.toJson()); // { 
                            //    'jsonrpc': '2.0', 
                            //    'method': 'getAccountInfo', 
                            //    'params': ['4fGh...GTh6'], 
                            //    'id': 1, 
                            // }

Implementation

// factory JsonRpcRequest.build(
//   final Method method,
//   final List<Object> params,
//   final JsonRpcRequestConfig config,
// ) {
//   final Map<String, dynamic> object = config.object();
//   final List<Object>? parameters = object.isEmpty ? params : params..add(object);
//   return JsonRpcRequest._(method, params: parameters, id: config.id);
// }

/// Creates a copy of `this` instance, applying the provided parameters to the new instance.
///
/// ```
/// const JsonRpcRequest request = JsonRpcRequest(
///   Method.getAccountInfo,
///   params: ['4fGh...GTh6'],
///   id: 0,
/// );
/// final JsonRpcRequest newRequest = request.copyWith(id: 1);
/// print(newRequest.toJson()); // {
///                             //    'jsonrpc': '2.0',
///                             //    'method': 'getAccountInfo',
///                             //    'params': ['4fGh...GTh6'],
///                             //    'id': 1,
///                             // }
/// ```
JsonRpcRequest copyWith({
  Enum? method,
  List<Object>? params,
  int? id,
}) => JsonRpcRequest(
  method ?? this.method,
  params: params ?? this.params,
  id: id ?? this.id,
);