Skip to content

Commit

Permalink
update connection endpoint parse for solana rpc provider (#4253)
Browse files Browse the repository at this point in the history
  • Loading branch information
callensm authored Jun 30, 2023
1 parent 6b226e0 commit 128650c
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,11 @@ export class SolanaRpc implements BlockchainDataProvider {
readonly #connection: Connection;
readonly #mpl: Metaplex;

constructor({ context, customRpc, tokenList }: SolanaRpcProviderSettings) {
const rpcUrl =
context?.network.rpc ??
customRpc ??
`https://rpc.helius.xyz/?api-key=${HELIUS_API_KEY}`;

this.#connection = new Connection(rpcUrl, "confirmed");
constructor(opts: SolanaRpcProviderSettings) {
this.#connection = new Connection(this._getRpcUrl(opts), "confirmed");
this.#mpl = Metaplex.make(this.#connection);
this.ctx = context;
this.tokenList = tokenList ?? SolanaTokenList;
this.ctx = opts.context;
this.tokenList = opts.tokenList ?? SolanaTokenList;
}

/**
Expand Down Expand Up @@ -431,4 +426,20 @@ export class SolanaRpc implements BlockchainDataProvider {
filters?.before !== undefined
);
}

/**
* Return the target RPC endpoint that should be used based on context.
* @private
* @param {SolanaRpcProviderSettings} settings
* @returns {string}
* @memberof SolanaRpc
*/
private _getRpcUrl({
context,
customRpc,
}: SolanaRpcProviderSettings): string {
return context?.network.rpc ?? customRpc ?? context?.network.devnet
? `https://rpc-devnet.helius.xyz/?api-key=${HELIUS_API_KEY}`
: "https://rpc-proxy.backpack.workers.dev";
}
}

1 comment on commit 128650c

@vercel
Copy link

@vercel vercel bot commented on 128650c Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.