send method

  1. @override
Future<PactSendResponse> send({
  1. required PactSendRequest commands,
  2. String? chainId,
  3. String? nodeUrl,
  4. String? networkId,
  5. String? url,
})
override

Send a pact command to the node The chainId is the chainId to execute the command on. It is required if url is not provided. The nodeUrl and the networkId are used to override the defaults set by setNodeUrl and setNetworkId when building the url for the pact api. The url is the full node url, example: https://api.chainweb.com/chainweb/0.0/testnet01/chain/0/pact/api/v1 If url is provided, the chainId is not required.

Implementation

@override
Future<PactSendResponse> send({
  required PactSendRequest commands,
  String? chainId,
  String? nodeUrl,
  String? networkId,
  String? url,
}) async {
  Uri uri = url == null
      ? buildEndpoint(
          endpoint: PactApiV1Endpoints.send,
          chainId: chainId!,
          nodeUrl: nodeUrl,
          networkId: networkId,
        )
      : buildEndpoint(
          endpoint: PactApiV1Endpoints.send,
          url: url,
        );
  http.Response response = await http.post(
    uri,
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(commands),
  );

  try {
    return PactSendResponse.fromJson(
      jsonDecode(
        response.body,
      ),
    );
  } catch (e) {
    throw PactApiError(
      error: response.body,
    );
  }
}