Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-edge committed Jan 3, 2025
1 parent 9ca3f12 commit 32bbc78
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/solana/SolanaEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ export class SolanaEngine extends CurrencyEngine<
const funcs = rpcNodes.map(serverUrl => async () => {
serverUrl = this.tools.rpcWithApiKey(serverUrl)
const res = await this.fetch(serverUrl, options)
if (!res.ok) {
const json = await res.json()
if (!res.ok || json.error != null) {
this.log.warn('fetchRpc error', json)
throw new Error(
`fetchRpc ${options.method} failed error: ${res.status}`
`fetchRpc ${options.method} failed error: ${json.error ?? res.status}`
)
}
const out = await res.json()
Expand Down Expand Up @@ -177,7 +179,9 @@ export class SolanaEngine extends CurrencyEngine<
})
}

const balances: any = await this.fetchRpcBulk(requests)
const res = await this.fetchRpcBulk(requests)
this.log.warn('queryBalance res', res)
const balances: any = res

const [mainnetBal, ...tokenBals]: [AccountBalance, TokenAmount[]] =
balances
Expand Down
12 changes: 10 additions & 2 deletions src/solana/SolanaTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,19 @@ export class SolanaTools implements EdgeCurrencyTools {
}

makeConnections(rpcUrls: string[]): Connection[] {
const fetchCorsBypassed: EdgeFetchFunction = async (uri, opts) =>
await this.io.fetch(uri, {
const fetchCorsBypassed: EdgeFetchFunction = async (uri, opts) => {
const res = await this.io.fetch(uri, {
...opts,
corsBypass: 'always'
})
// Alchemy returns status 200 (ok) for failed requests
const json = await res.json()
if (json.error != null) {
throw new Error(`fetchCorsBypassed: ${json.error}`)
}

return res
}
const connectionConfig: ConnectionConfig = {
commitment: this.networkInfo.commitment,
fetch: fetchCorsBypassed as FetchFn
Expand Down
9 changes: 5 additions & 4 deletions src/solana/solanaInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,16 @@ const builtinTokens: EdgeTokenMap = {
const networkInfo: SolanaNetworkInfo = {
rpcNodes: [
// 'https://api.mainnet-beta.solana.com',
// 'https://solana-mainnet.rpc.grove.city/v1/{{poktPortalApiKey}}', // fails to return some transactions
'https://mainnet.helius-rpc.com/?api-key={{heliusApiKey}}'
'https://solana-mainnet.rpc.grove.city/v1/{{poktPortalApiKey}}' // fails to return some transactions
// 'https://mainnet.helius-rpc.com/?api-key={{heliusApiKey}}'
],
rpcNodesArchival: [
// 'https://api.mainnet-beta.solana.com',
// 'https://solana-mainnet.g.alchemy.com/v2/{{alchemyApiKey}}',
'https://mainnet.helius-rpc.com/?api-key={{heliusApiKey}}'
'https://solana-mainnet.g.alchemy.com/v2/{{alchemyApiKey}}'
// 'https://mainnet.helius-rpc.com/?api-key={{heliusApiKey}}'
],
stakedConnectionRpcNodes: [
// has some staked solana to broadcast
'https://staked.helius-rpc.com?api-key={{heliusApiKey}}'
],
commitment: 'confirmed', // confirmed is faster, finalized is safer. Even faster processed is unsupported for tx querys
Expand Down

0 comments on commit 32bbc78

Please sign in to comment.