Skip to content

Commit f861201

Browse files
authored
Create spice-provider.ts
1 parent f599d6f commit f861201

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"use strict"
2+
3+
import {
4+
UrlJsonRpcProvider,
5+
showThrottleMessage,
6+
} from "@ethersproject/providers"
7+
8+
import { Logger } from "@ethersproject/logger"
9+
const logger = new Logger("providers/5.5.1")
10+
11+
const defaultApiKey = "3439|6806e8faf10643e2bde903920bbcb1ff"
12+
13+
export class SpiceProvider extends UrlJsonRpcProvider {
14+
static getApiKey(apiKey) {
15+
if (apiKey == null) {
16+
return defaultApiKey
17+
}
18+
if (apiKey && typeof apiKey !== "string") {
19+
logger.throwArgumentError("invalid apiKey", "apiKey", apiKey)
20+
}
21+
return apiKey
22+
}
23+
24+
static getUrl(network, apiKey) {
25+
const host = "https://data.spiceai.io"
26+
let path = null
27+
switch (network.name) {
28+
case "homestead":
29+
path = "/eth"
30+
break
31+
default:
32+
logger.throwArgumentError(
33+
"unsupported network",
34+
"network",
35+
arguments[0]
36+
)
37+
}
38+
39+
return {
40+
allowGzip: true,
41+
url: host + path,
42+
throttleCallback: (attempt, url) => {
43+
if (apiKey === defaultApiKey) {
44+
showThrottleMessage()
45+
}
46+
return Promise.resolve(true)
47+
},
48+
}
49+
}
50+
51+
isCommunityResource() {
52+
return this.apiKey === defaultApiKey
53+
}
54+
}

0 commit comments

Comments
 (0)