diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..9067a15 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @KuphJr @zeuslawyer \ No newline at end of file diff --git a/README.md b/README.md index a8b2a87..f2f3451 100644 --- a/README.md +++ b/README.md @@ -465,6 +465,20 @@ const response: FunctionsResponse = await responseListener.listenForResponseFrom ) ``` +`listenForResponseFromTransaction()` returns a response with the following structure: +``` +{ + requestId: string // Request ID of the fulfilled request represented as a bytes32 hex string + subscriptionId: number // Subscription ID billed for request + totalCostInJuels: bigint // Actual cost of request in Juels (1,000,000,000,000,000,000 (1e18) Juels are equal to 1 LINK) + responseBytesHexstring: string // Response bytes sent to client contract represented as a hex string ("0x" if no response) + errorString: string // Error sent to client contract interpreted as a UTF-8 string ("" if no error) + returnDataBytesHexstring: string // Data returned by consumer contract's handleOracleFulfillment method represented as a hex string + fulfillmentCode: FulfillmentCode // Indicates whether the request was fulfilled successfully or not +} + +``` + Alternatively, to listen using a request ID, use the `listenForResponse()` method. **Notes:** diff --git a/package-lock.json b/package-lock.json index d5260d4..0c149a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13879,4 +13879,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/ResponseListener.ts b/src/ResponseListener.ts index a4456f4..96118ea 100644 --- a/src/ResponseListener.ts +++ b/src/ResponseListener.ts @@ -68,7 +68,7 @@ export class ResponseListener { ): Promise { return new Promise((resolve, reject) => { ;(async () => { - let requestID: string + let requestId: string // eslint-disable-next-line prefer-const let checkTimeout: NodeJS.Timeout const expirationTimeout = setTimeout(() => { @@ -77,11 +77,11 @@ export class ResponseListener { const check = async () => { const receipt = await this.provider.waitForTransaction(txHash, confirmations, timeout) - const updatedID = receipt.logs[0].topics[1] - if (updatedID !== requestID) { - requestID = updatedID - const response = await this.listenForResponse(receipt.logs[0].topics[1], timeout) - if (updatedID === requestID) { + const updatedId = receipt.logs[0].topics[1] + if (updatedId !== requestId) { + requestId = updatedId + const response = await this.listenForResponse(requestId, timeout) + if (updatedId === requestId) { // Resolve only if the ID hasn't changed in the meantime clearTimeout(expirationTimeout) clearInterval(checkTimeout) @@ -90,7 +90,7 @@ export class ResponseListener { } } - // Check periodically if the transaction has been re-orged and requestID changed + // Check periodically if the transaction has been re-orged and requestId changed checkTimeout = setInterval(check, checkInterval) check() diff --git a/src/types.ts b/src/types.ts index 0c0c9ea..db22332 100644 --- a/src/types.ts +++ b/src/types.ts @@ -184,7 +184,7 @@ export type FunctionsResponse = { requestId: string // Request ID of the fulfilled request represented as a bytes32 hex string subscriptionId: number // Subscription ID billed for request totalCostInJuels: bigint // Actual cost of request in Juels (1,000,000,000,000,000,000 (1e18) Juels are equal to 1 LINK) - responseBytesHexstring: string // Response bytes sent to client contract represented as a hex string ("0x" if no response) + responseBytesHexstring: string // Response sent to client contract represented as a hex string ("0x" if no response) errorString: string // Error bytes sent to client contract interpreted as a UTF-8 string ("" if no error) returnDataBytesHexstring: string // Data returned by consumer contract's handleOracleFulfillment method represented as a hex string fulfillmentCode: FulfillmentCode // Indicates whether the request was fulfilled successfully or not diff --git a/yarn.lock b/yarn.lock index cc2db79..8ca8c93 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5865,4 +5865,4 @@ yargs@^17.3.1, yargs@^17.7.1: yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" - integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== + integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== \ No newline at end of file