makeRpcRequest method
Make a request, and return deserialized response
Implementation
Future<RPCResponse> makeRpcRequest(BaseRequest request) async {
request.id = id;
String? responseJson = await rpcPost(request.toJson());
if (responseJson == null) {
throw Exception('Did not receive a response');
}
// Parse base response
BaseResponse resp = BaseResponse.fromJson(json.decode(responseJson));
// Determine if error response
if (resp is Map &&
resp.result.containsKey('code') &&
resp.result.containsKey('message')) {
return ErrorResponse.fromJson(resp.result);
}
// Determine correct response type
switch (request.method) {
case 'getaccount':
return PascalAccount.fromJson(resp.result);
case 'getblock':
return PascalBlock.fromJson(resp.result);
case 'findoperation':
case 'getblockoperation':
return PascalOperation.fromJson(resp.result);
case 'getblocks':
return BlocksResponse.fromJson(json.decode(responseJson));
case 'getwalletaccounts':
case 'findaccounts':
return AccountsResponse.fromJson(json.decode(responseJson));
case 'getblockoperations':
case 'getaccountoperations':
case 'getpendings':
case 'executeoperations':
return OperationsResponse.fromJson(json.decode(responseJson));
default:
return BaseResponse.fromJson(resp.result);
}
}