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

add detail to README. Minor changes for consistency #41

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is package-lock.json changing? Can you remove this from the PR?

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 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 All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading