Skip to content

Commit

Permalink
ALL-4448 - Add Solana lb for archive methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel committed Feb 12, 2024
1 parent 14a09bd commit f1f897d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [4.2.6] - 2024.2.12

### Added

- Added support for Solana load balancer based on the method name.

## [4.2.5] - 2024.1.31

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "4.2.5",
"version": "4.2.6",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
39 changes: 19 additions & 20 deletions src/e2e/rpc/other/tatum.rpc.solana.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,6 @@ describe('Solana', () => {
})
})

// Too unstable
describe.skip('getBlock', () => {
it('should return a recent block', async () => {
const tatum = await getClient()
const { result: slot } = await tatum.rpc.getSlot()
const { result } = await tatum.rpc.getBlock(slot || 0, {
encoding: Encoding.JsonParsed,
maxSupportedTransactionVersion: 0,
})
await tatum.destroy()
expect(result).toHaveProperty('blockhash')
expect(result?.blockhash).toBeTruthy()
expect(result?.previousBlockhash).toBeTruthy()
expect(result?.blockHeight).toBeGreaterThan(0)
expect(result?.parentSlot).toBeGreaterThan(0)
expect(result?.blockTime).toBeGreaterThan(0)
expect(Array.isArray(result?.transactions)).toBe(true)
})
})

describe('getBlockProduction', () => {
it('should return block production information', async () => {
const tatum = await getClient()
Expand Down Expand Up @@ -410,5 +390,24 @@ describe('Solana', () => {
expect(result?.totalStake).toBeGreaterThan(0)
})
})

describe('getBlock', () => {
it('should return a recent block', async () => {
const tatum = await getClient(true)
const { result: slot } = await tatum.rpc.getSlot()
const { result } = await tatum.rpc.getBlock(slot || 0, {
encoding: Encoding.JsonParsed,
maxSupportedTransactionVersion: 0,
})
await tatum.destroy()
expect(result).toHaveProperty('blockhash')
expect(result?.blockhash).toBeTruthy()
expect(result?.previousBlockhash).toBeTruthy()
expect(result?.blockHeight).toBeGreaterThan(0)
expect(result?.parentSlot).toBeGreaterThan(0)
expect(result?.blockTime).toBeGreaterThan(0)
expect(Array.isArray(result?.transactions)).toBe(true)
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { AbstractSolanaRpc } from './AbstractSolanaRpc'

@Service({
factory: (data: { id: string }) => {
return new SolanaLoadBalancerRpc(data.id)
return new SolanaArchiveLoadBalancerRpc(data.id)
},
transient: true,
})
export class SolanaLoadBalancerRpc extends AbstractSolanaRpc implements SolanaRpcSuite {
export class SolanaArchiveLoadBalancerRpc extends AbstractSolanaRpc implements SolanaRpcSuite {
protected readonly loadBalancer: LoadBalancer

constructor(id: string) {
Expand All @@ -22,7 +22,22 @@ export class SolanaLoadBalancerRpc extends AbstractSolanaRpc implements SolanaRp

protected async rpcCall<T>(method: string, params?: unknown[]): Promise<T> {
const preparedCall = Utils.prepareRpcCall(method, params)
return (await this.loadBalancer.rawRpcCall(preparedCall)) as T
const isArchive = this.isArchiveMethod(preparedCall)
return (await this.loadBalancer.rawRpcCall(preparedCall, isArchive)) as T
}

private isArchiveMethod(body: JsonRpcCall): boolean {
const archiveMethods = [
'getBlock',
'getBlocks',
'getBlocksWithLimit',
'getBlockTime',
'getInflationReward',
'getProgramAccounts',
'getSignaturesForAddress',
'getConfirmedSignaturesForAddress2',
]
return archiveMethods.some((method) => body.method.includes(method))
}

async rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<any>> {
Expand Down
4 changes: 2 additions & 2 deletions src/util/util.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import { BnbLoadBalancerRpc } from '../service/rpc/other/BnbLoadBalancerRpc'
import { CardanoLoadBalancerRpc } from '../service/rpc/other/CardanoLoadBalancerRpc'
import { EosLoadBalancerRpc } from '../service/rpc/other/EosLoadBalancerRpc'
import { EosRpc } from '../service/rpc/other/EosRpc'
import { SolanaLoadBalancerRpc } from '../service/rpc/other/SolanaLoadBalancerRpc'
import { SolanaArchiveLoadBalancerRpc } from '../service/rpc/other/SolanaArchiveLoadBalancerRpc'
import { StellarLoadBalancerRpc } from '../service/rpc/other/StellarLoadBalancerRpc'
import { StellarRpc } from '../service/rpc/other/StellarRpc'
import { TezosLoadBalancerRpc } from '../service/rpc/other/TezosLoadBalancerRpc'
Expand Down Expand Up @@ -178,7 +178,7 @@ export const Utils = {
}

if (isSolanaNetwork(network)) {
return Container.of(id).get(SolanaLoadBalancerRpc) as T
return Container.of(id).get(SolanaArchiveLoadBalancerRpc) as T
}

if (isTronLoadBalancerNetwork(network)) {
Expand Down

0 comments on commit f1f897d

Please sign in to comment.