Skip to content

Commit 128650c

Browse files
authored
update connection endpoint parse for solana rpc provider (#4253)
1 parent 6b226e0 commit 128650c

File tree

1 file changed

+20
-9
lines changed
  • backend/native/backpack-api/src/routes/graphql/providers/solana

1 file changed

+20
-9
lines changed

backend/native/backpack-api/src/routes/graphql/providers/solana/rpc.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,11 @@ export class SolanaRpc implements BlockchainDataProvider {
5959
readonly #connection: Connection;
6060
readonly #mpl: Metaplex;
6161

62-
constructor({ context, customRpc, tokenList }: SolanaRpcProviderSettings) {
63-
const rpcUrl =
64-
context?.network.rpc ??
65-
customRpc ??
66-
`https://rpc.helius.xyz/?api-key=${HELIUS_API_KEY}`;
67-
68-
this.#connection = new Connection(rpcUrl, "confirmed");
62+
constructor(opts: SolanaRpcProviderSettings) {
63+
this.#connection = new Connection(this._getRpcUrl(opts), "confirmed");
6964
this.#mpl = Metaplex.make(this.#connection);
70-
this.ctx = context;
71-
this.tokenList = tokenList ?? SolanaTokenList;
65+
this.ctx = opts.context;
66+
this.tokenList = opts.tokenList ?? SolanaTokenList;
7267
}
7368

7469
/**
@@ -431,4 +426,20 @@ export class SolanaRpc implements BlockchainDataProvider {
431426
filters?.before !== undefined
432427
);
433428
}
429+
430+
/**
431+
* Return the target RPC endpoint that should be used based on context.
432+
* @private
433+
* @param {SolanaRpcProviderSettings} settings
434+
* @returns {string}
435+
* @memberof SolanaRpc
436+
*/
437+
private _getRpcUrl({
438+
context,
439+
customRpc,
440+
}: SolanaRpcProviderSettings): string {
441+
return context?.network.rpc ?? customRpc ?? context?.network.devnet
442+
? `https://rpc-devnet.helius.xyz/?api-key=${HELIUS_API_KEY}`
443+
: "https://rpc-proxy.backpack.workers.dev";
444+
}
434445
}

0 commit comments

Comments
 (0)