Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update README for response type and minor tidy ups for consistency #42

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading