Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-edge committed Jan 9, 2025
1 parent 9ca3f12 commit aaf6364
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
10 changes: 8 additions & 2 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 json', 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 @@ -464,6 +466,7 @@ export class SolanaEngine extends CurrencyEngine<
})
}
)
try {
const txResponse: Array<
TransactionResponse | VersionedTransactionResponse
> = await asyncWaterfall(funcs)
Expand Down Expand Up @@ -511,6 +514,9 @@ export class SolanaEngine extends CurrencyEngine<
}
}
}
} catch (e: any) {
this.error('getTransactions failed with error: ', e)
}
}

this.walletLocalDataDirty = true
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
5 changes: 3 additions & 2 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://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://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 aaf6364

Please sign in to comment.