Skip to content

Commit

Permalink
update README for response type and minor tidy ups for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
zeuslawyer committed Oct 25, 2023
1 parent 887d556 commit 826b8ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,18 @@ 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:**
Expand Down
12 changes: 6 additions & 6 deletions src/ResponseListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class ResponseListener {
): Promise<FunctionsResponse> {
return new Promise<FunctionsResponse>((resolve, reject) => {
;(async () => {
let requestID: string
let requestId: string
// eslint-disable-next-line prefer-const
let checkTimeout: NodeJS.Timeout
const expirationTimeout = setTimeout(() => {
Expand All @@ -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)
Expand Down

0 comments on commit 826b8ef

Please sign in to comment.