listen method
Future<PactResponse>
listen({
- required PactListenRequest request,
- String? chainId,
- String? nodeUrl,
- String? networkId,
- String? url,
override
Listen for a pact command to be included in a block
This will block until the command has been committed to a block.
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<PactResponse> listen({
required PactListenRequest request,
String? chainId,
String? nodeUrl,
String? networkId,
String? url,
}) async {
Uri uri = url == null
? buildEndpoint(
endpoint: PactApiV1Endpoints.listen,
chainId: chainId!,
nodeUrl: nodeUrl,
networkId: networkId,
)
: buildEndpoint(
endpoint: PactApiV1Endpoints.listen,
url: url,
);
http.Response response = await http.post(
uri,
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(request),
);
try {
return PactResponse.fromJson(
jsonDecode(
response.body,
),
);
} catch (e) {
throw PactApiError(
error: response.body,
);
}
}