Skip to content

Commit f551919

Browse files
[Coinmetrics-lwba] Updates result to include mid (#3950)
* [Coinmetrics-lwba] Updates result to include mid * Ensures to run the original endpoint validation --------- Co-authored-by: app-token-issuer-data-feeds[bot] <134377064+app-token-issuer-data-feeds[bot]@users.noreply.github.com>
1 parent c260c88 commit f551919

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

.changeset/brave-spoons-explode.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/coinmetrics-lwba-adapter': minor
3+
---
4+
5+
Updates result to include mid

packages/sources/coinmetrics-lwba/src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { makeConfig } from '@chainlink/coinmetrics-adapter/config'
22
import { endpoint } from '@chainlink/coinmetrics-adapter/endpoint/lwba'
33
import { expose, ServerInstance } from '@chainlink/external-adapter-framework'
44
import { Adapter } from '@chainlink/external-adapter-framework/adapter'
5+
import { AdapterResponse } from '@chainlink/external-adapter-framework/util/types'
6+
import { AdapterError } from '@chainlink/external-adapter-framework/validation/error'
57

68
export const config = makeConfig({
79
NAME: 'COINMETRICS_LWBA',
@@ -14,6 +16,20 @@ export const config = makeConfig({
1416

1517
const newEndpoint = Object.assign(Object.create(Object.getPrototypeOf(endpoint)), endpoint)
1618
newEndpoint.aliases.push('crypto', 'price')
19+
const originalValidate = endpoint.customOutputValidation
20+
newEndpoint.customOutputValidation = (resp: AdapterResponse): AdapterError | undefined => {
21+
const err = originalValidate?.(resp)
22+
if (err) {
23+
return err
24+
}
25+
if (!resp.errorMessage) {
26+
const mid = (resp.data as any)?.mid
27+
if (mid !== undefined) {
28+
resp.result = mid
29+
}
30+
}
31+
return undefined // no validation error
32+
}
1733

1834
export const adapter = new Adapter({
1935
defaultEndpoint: newEndpoint.name,

packages/sources/coinmetrics-lwba/test/integration/__snapshots__/adapter-ws.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports[`crypto-lwba websocket happy path returns a successful response 1`] = `
77
"bid": 1562.3384315992228,
88
"mid": 1562.3733948803842,
99
},
10-
"result": null,
10+
"result": 1562.3733948803842,
1111
"statusCode": 200,
1212
"timestamps": {
1313
"providerDataReceivedUnixMs": 1024,
@@ -24,7 +24,7 @@ exports[`crypto-lwba websocket happy path returns a successful response for cryp
2424
"bid": 1562.3384315992228,
2525
"mid": 1562.3733948803842,
2626
},
27-
"result": null,
27+
"result": 1562.3733948803842,
2828
"statusCode": 200,
2929
"timestamps": {
3030
"providerDataReceivedUnixMs": 1024,
@@ -41,7 +41,7 @@ exports[`crypto-lwba websocket happy path returns a successful response for pric
4141
"bid": 1562.3384315992228,
4242
"mid": 1562.3733948803842,
4343
},
44-
"result": null,
44+
"result": 1562.3733948803842,
4545
"statusCode": 200,
4646
"timestamps": {
4747
"providerDataReceivedUnixMs": 1024,

0 commit comments

Comments
 (0)