Skip to content

Commit

Permalink
Merge pull request #126 from forta-protocol/add-default-jsonrpcurl
Browse files Browse the repository at this point in the history
Add default jsonrpcurl
  • Loading branch information
haseebrabbani committed Mar 24, 2022
2 parents f717099 + c0a25f2 commit 27d4068
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
11 changes: 5 additions & 6 deletions cli/di.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,17 @@ export default function configureContainer(args: any = {}) {
agentRegistryJsonRpcUrl: asFunction((fortaConfig: FortaConfig) => {
const url = fortaConfig.agentRegistryJsonRpcUrl || "https://polygon-rpc.com/"
if (!url.startsWith("http")) {
throw new Error(`agentRegistryJsonRpcUrl must begin with http or https`)
throw new Error(`agentRegistryJsonRpcUrl must begin with http(s)`)
}
return url
}),

jsonRpcUrl: asFunction((fortaConfig: FortaConfig) => {
if (!fortaConfig.jsonRpcUrl) {
throw new Error(`no jsonRpcUrl provided in config`)
} else if (!fortaConfig.jsonRpcUrl.startsWith("http")) {
throw new Error(`jsonRpcUrl must begin with http or https`)
const jsonRpcUrl = fortaConfig.jsonRpcUrl || "https://cloudflare-eth.com/"
if (!jsonRpcUrl.startsWith("http")) {
throw new Error(`jsonRpcUrl must begin with http(s)`)
}
return fortaConfig.jsonRpcUrl
return jsonRpcUrl
}),
ethersProvider: asFunction((jsonRpcUrl: string) => new ethers.providers.JsonRpcProvider(jsonRpcUrl)).singleton(),
ethersAgentRegistryProvider: asFunction((agentRegistryJsonRpcUrl: string) => new ethers.providers.JsonRpcProvider(agentRegistryJsonRpcUrl)).singleton(),
Expand Down
4 changes: 1 addition & 3 deletions python-sdk/src/forta_agent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ def get_json_rpc_url():
return f'http://{os.environ["JSON_RPC_HOST"]}{":"+os.environ["JSON_RPC_PORT"] if "JSON_RPC_PORT" in os.environ else ""}'

config = get_forta_config()
if os.environ.get('PYTHON_ENV') == "test": # dont throw errors when running tests
return config.get("jsonRpcUrl")
if "jsonRpcUrl" not in config:
raise Exception("no jsonRpcUrl found")
return "https://cloudflare-eth.com/"
if not str(config.get("jsonRpcUrl")).startswith("http"):
raise Exception("jsonRpcUrl must begin with http(s)")
return config.get("jsonRpcUrl")
Expand Down
5 changes: 2 additions & 3 deletions sdk/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ export const getJsonRpcUrl = () => {
}

// else, use the rpc url from forta.config.json
const { jsonRpcUrl } = getFortaConfig()
if (process.env.NODE_ENV === "test") return jsonRpcUrl // dont throw errors when running tests
if (!jsonRpcUrl) throw new Error('no jsonRpcUrl found')
let { jsonRpcUrl } = getFortaConfig()
if (!jsonRpcUrl) return "https://cloudflare-eth.com/"
if (!jsonRpcUrl.startsWith("http")) throw new Error('jsonRpcUrl must begin with http(s)')
return jsonRpcUrl
}
Expand Down

0 comments on commit 27d4068

Please sign in to comment.