Skip to content

Commit 8dfecbe

Browse files
authored
Merge pull request #42 from smartcontractkit/listener-patches
2 parents 887d556 + 826b8ef commit 8dfecbe

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,18 @@ const response: FunctionsResponse = await responseListener.listenForResponseFrom
465465
)
466466
```
467467

468+
`listenForResponseFromTransaction()` returns a response with the following structure:
469+
```
470+
{
471+
requestId: string // Request ID of the fulfilled request represented as a bytes32 hex string
472+
subscriptionId: number // Subscription ID billed for request
473+
totalCostInJuels: bigint // Actual cost of request in Juels (1,000,000,000,000,000,000 (1e18) Juels are equal to 1 LINK)
474+
responseBytesHexstring: string // Response bytes sent to client contract represented as a hex string ("0x" if no response)
475+
errorString: string // Error sent to client contract interpreted as a UTF-8 string ("" if no error)
476+
returnDataBytesHexstring: string // Data returned by consumer contract's handleOracleFulfillment method represented as a hex string
477+
fulfillmentCode: FulfillmentCode // Indicates whether the request was fulfilled successfully or not
478+
}
479+
468480
Alternatively, to listen using a request ID, use the `listenForResponse()` method.
469481
470482
**Notes:**

src/ResponseListener.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class ResponseListener {
6868
): Promise<FunctionsResponse> {
6969
return new Promise<FunctionsResponse>((resolve, reject) => {
7070
;(async () => {
71-
let requestID: string
71+
let requestId: string
7272
// eslint-disable-next-line prefer-const
7373
let checkTimeout: NodeJS.Timeout
7474
const expirationTimeout = setTimeout(() => {
@@ -77,11 +77,11 @@ export class ResponseListener {
7777

7878
const check = async () => {
7979
const receipt = await this.provider.waitForTransaction(txHash, confirmations, timeout)
80-
const updatedID = receipt.logs[0].topics[1]
81-
if (updatedID !== requestID) {
82-
requestID = updatedID
83-
const response = await this.listenForResponse(receipt.logs[0].topics[1], timeout)
84-
if (updatedID === requestID) {
80+
const updatedId = receipt.logs[0].topics[1]
81+
if (updatedId !== requestId) {
82+
requestId = updatedId
83+
const response = await this.listenForResponse(requestId, timeout)
84+
if (updatedId === requestId) {
8585
// Resolve only if the ID hasn't changed in the meantime
8686
clearTimeout(expirationTimeout)
8787
clearInterval(checkTimeout)

0 commit comments

Comments
 (0)