-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from argentlabs/fix/rpc-public-urls
Fix/rpc public urls
- Loading branch information
Showing
6 changed files
with
34 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import { RPC_NODE_URL_MAINNET, RPC_NODE_URL_TESTNET } from "../constants" | ||
import { getRandomPublicRPCNode } from "../../../helpers/publicRcpNodes" | ||
|
||
export function mapTargetUrlToNodeUrl(target: string): string { | ||
const publicRPCNode = getRandomPublicRPCNode() | ||
try { | ||
const { origin } = new URL(target) | ||
if (origin.includes("localhost") || origin.includes("127.0.0.1")) { | ||
return RPC_NODE_URL_TESTNET | ||
return publicRPCNode.testnet | ||
} | ||
if (origin.includes("hydrogen")) { | ||
return RPC_NODE_URL_TESTNET | ||
return publicRPCNode.testnet | ||
} | ||
if (origin.includes("staging")) { | ||
return RPC_NODE_URL_MAINNET | ||
return publicRPCNode.mainnet | ||
} | ||
if (origin.includes("argent.xyz")) { | ||
return RPC_NODE_URL_MAINNET | ||
return publicRPCNode.mainnet | ||
} | ||
} catch (e) { | ||
console.warn( | ||
"Could not determine rpc nodeUrl from target URL, defaulting to mainnet", | ||
) | ||
} | ||
return RPC_NODE_URL_MAINNET | ||
return publicRPCNode.mainnet | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export type PublicRpcNode = { | ||
mainnet: string | ||
testnet: string | ||
} | ||
|
||
// Public RPC nodes | ||
export const BLAST_RPC_NODE: PublicRpcNode = { | ||
mainnet: "https://starknet-mainnet.public.blastapi.io", | ||
testnet: "https://starknet-testnet.public.blastapi.io", | ||
} as const | ||
|
||
export const LAVA_RPC_NODE: PublicRpcNode = { | ||
mainnet: "https://rpc.starknet.lava.build", | ||
testnet: "https://rpc.starknet-testnet.lava.build", | ||
} as const | ||
|
||
export const PUBLIC_RPC_NODES = [BLAST_RPC_NODE, LAVA_RPC_NODE] as const | ||
|
||
export function getRandomPublicRPCNode() { | ||
const randomIndex = Math.floor(Math.random() * PUBLIC_RPC_NODES.length) | ||
return PUBLIC_RPC_NODES[randomIndex] | ||
} |