Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALL-1512 Fix rpc calls without api key #862

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.5.11] - 2023.07.13
### Changed
- Fix rpc calls without api key & Added haqq archive/non-archive calls

## [1.5.10] - 2023.07.10
### Changed
- Selected Archive/Non-Archive node for Ethereum RPC calls based on method
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": "@tatumcom/js",
"version": "1.5.10",
"version": "1.5.11",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
2 changes: 2 additions & 0 deletions src/dto/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ export const LOAD_BALANCER_NETWORKS = [...UTXO_LOAD_BALANCER_NETWORKS, ...EVM_LO
export const EVM_ARCHIVE_NON_ARCHIVE_LOAD_BALANCER_NETWORKS = [
Network.ETHEREUM,
Network.ETHEREUM_SEPOLIA,
Network.HAQQ,
Network.HAQQ_TESTNET,
]

export const SOLANA_NETWORKS = [Network.SOLANA, Network.SOLANA_DEVNET]
Expand Down
6 changes: 3 additions & 3 deletions src/service/address/address.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from 'bignumber.js'
import { Container, Service } from 'typedi'

Check warning on line 2 in src/service/address/address.ts

View workflow job for this annotation

GitHub Actions / test

'Service' is defined but never used
import { ApiBalanceRequest } from '../../api/api.dto'
import { TatumConnector } from '../../connector/tatum.connector'
import {
Expand All @@ -20,7 +20,7 @@
},
transient: true,
})
export class Address {

Check warning on line 23 in src/service/address/address.ts

View workflow job for this annotation

GitHub Actions / test

'Address' is defined but never used
private readonly connector: TatumConnector
private readonly config: TatumConfig

Expand Down Expand Up @@ -235,7 +235,7 @@
private async getNativeBalance(addresses: string[]): Promise<string[]> {
const network = this.config.network
if (isEvmBasedNetwork(network)) {
const rpc = Utils.getRpc<EvmRpc>(this.id, network)
const rpc = Utils.getRpc<EvmRpc>(this.id, this.config)
const result = await Promise.all(
addresses.map((a, i) => rpc.rawRpcCall(Utils.prepareRpcCall('eth_getBalance', [a, 'pending'], i))),
)
Expand All @@ -244,7 +244,7 @@
return result.map((e) => new BigNumber(e.result).dividedBy(10 ** Constant.DECIMALS[network]).toString())
}
if ([Network.SOLANA, Network.SOLANA_DEVNET].includes(network)) {
const rpc = Utils.getRpc<GenericRpc>(this.id, network)
const rpc = Utils.getRpc<GenericRpc>(this.id, this.config)
return rpc
.rawBatchRpcCall(
addresses.map((a, i) => Utils.prepareRpcCall('getBalance', [a, { commitment: 'processed' }], i)),
Expand All @@ -256,7 +256,7 @@
if (addresses.length !== 1) {
throw new Error(`UTXO based networks like ${network} support only one address per call.`)
}
const rpc = Utils.getRpc<GenericRpc>(this.id, network)
const rpc = Utils.getRpc<GenericRpc>(this.id, this.config)
return rpc
.rawRpcCall(
Utils.prepareRpcCall('account_info', [
Expand Down
2 changes: 2 additions & 0 deletions src/service/rpc/evm/EvmArchiveLoadBalancerRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class EvmArchiveLoadBalancerRpc extends AbstractEvmRpc implements EvmBase
}

private isArchiveMethod(rpc: JsonRpcCall): boolean {


const isArchiveMethod = ARCHIVE_METHODS.includes(rpc.method)
if (isArchiveMethod) {
return true
Expand Down
10 changes: 5 additions & 5 deletions src/service/tatum/tatum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export abstract class BaseUtxoClass extends BaseTatumSdk {

constructor(id: string) {
super(id)
this.rpc = Utils.getRpc<UtxoBasedRpcSuite>(id, Container.of(id).get(CONFIG).network)
this.rpc = Utils.getRpc<UtxoBasedRpcSuite>(id, Container.of(id).get(CONFIG))
this.fee = Container.of(id).get(FeeUtxo)
}
}
Expand All @@ -46,7 +46,7 @@ export abstract class BaseEvmClass extends BaseTatumSdk {

constructor(id: string) {
super(id)
this.rpc = Utils.getRpc<EvmBasedRpcSuite>(id, Container.of(id).get(CONFIG).network)
this.rpc = Utils.getRpc<EvmBasedRpcSuite>(id, Container.of(id).get(CONFIG))
}
}

Expand Down Expand Up @@ -91,21 +91,21 @@ export class Xrp extends BaseTatumSdk {
rpc: XrpRpcSuite
constructor(id: string) {
super(id)
this.rpc = Utils.getRpc<XrpRpcSuite>(id, Container.of(id).get(CONFIG).network)
this.rpc = Utils.getRpc<XrpRpcSuite>(id, Container.of(id).get(CONFIG))
}
}
export class Solana extends BaseTatumSdk {
rpc: SolanaRpcSuite
constructor(id: string) {
super(id)
this.rpc = Utils.getRpc<SolanaRpcSuite>(id, Container.of(id).get(CONFIG).network)
this.rpc = Utils.getRpc<SolanaRpcSuite>(id, Container.of(id).get(CONFIG))
}
}
export class Tron extends BaseTatumSdk {
rpc: TronRpcSuite
constructor(id: string) {
super(id)
this.rpc = Utils.getRpc<TronRpcSuite>(id, Container.of(id).get(CONFIG).network)
this.rpc = Utils.getRpc<TronRpcSuite>(id, Container.of(id).get(CONFIG))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/service/walletProvider/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class MetaMask<T extends EvmRpc> {

constructor(private readonly id: string) {
this.config = Container.of(this.id).get(CONFIG)
this.rpc = Utils.getRpc<T>(this.id, this.config.network)
this.rpc = Utils.getRpc<T>(this.id, this.config)
this.connector = Container.of(this.id).get(TatumConnector)
}

Expand Down
7 changes: 4 additions & 3 deletions src/util/util.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
Palm,
Polygon,
Solana,
SolanaRpc,
SolanaRpc, TatumConfig,
Tron,
TronRpc,
UtxoLoadBalancerRpc,
Expand All @@ -59,12 +59,13 @@ import { CONFIG } from './di.tokens'
import { EvmArchiveLoadBalancerRpc } from '../service/rpc/evm/EvmArchiveLoadBalancerRpc'

export const Utils = {
getRpc: <T>(id: string, network: Network): T => {
getRpc: <T>(id: string, config: TatumConfig): T => {
const { network, apiKey } = config
if (isUtxoLoadBalancerNetwork(network)) {
return Container.of(id).get(UtxoLoadBalancerRpc) as T
}

if (isEvmArchiveNonArchiveLoadBalancerNetwork(network)) {
if (isEvmArchiveNonArchiveLoadBalancerNetwork(network) && apiKey?.v2) {
return Container.of(id).get(EvmArchiveLoadBalancerRpc) as T
}

Expand Down
Loading