MCPcopy Create free account
hub / github.com/api3dao/airnode / waitForFulfillment

Function waitForFulfillment

packages/airnode-examples/src/scripts/make-request.ts:11–30  ·  view source on GitHub ↗
(requestId: string)

Source from the content-addressed store, hash-verified

9} from '../';
10
11const waitForFulfillment = async (requestId: string) => {
12 const airnodeRrp = await getDeployedContract('@api3/airnode-protocol/contracts/rrp/AirnodeRrpV0.sol');
13 const provider = getProvider();
14
15 const fulfilled = new Promise((resolve) =>
16 provider.once(airnodeRrp.filters.FulfilledRequest(null, requestId), resolve)
17 );
18 const failed = new Promise((resolve) =>
19 provider.once(airnodeRrp.filters.FailedRequest(null, requestId), resolve)
20 ).then((rawRequestFailedLog) => {
21 const log = airnodeRrp.interface.parseLog(rawRequestFailedLog as ethers.Event);
22 throw new Error(`Request failed. Reason:\n${log.args.errorMessage}`);
23 });
24
25 // Airnode request can either:
26 // 1) be fulfilled - in that case this promise resolves
27 // 2) fail - in that case, this promise rejects and this function throws an error
28 // 3) never be processed - this means the request is invalid or a bug in Airnode. This should not happen.
29 await Promise.race([fulfilled, failed]);
30};
31
32const makeRequest = async (): Promise<string> => {
33 const integrationInfo = readIntegrationInfo();

Callers 1

mainFunction · 0.70

Calls 2

getDeployedContractFunction · 0.85
getProviderFunction · 0.85

Tested by

no test coverage detected