Skip to content

Commit

Permalink
Increase version, fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverjantar committed Jul 11, 2023
1 parent 7a7c0d4 commit da0ddb8
Show file tree
Hide file tree
Showing 27 changed files with 77 additions and 71 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.5.8] - 2023.07.10
### Changed
- Update all RPC calls to return unmodified data

## [1.5.7] - 2023.07.10
### Changed
- Extended JSON stringify to see error message in case of error to Loadbalancer
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ import { TatumSDK, Network, Ethereum } from '@tatumcom/js'

const tatum = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM })

const { data } = await tatum.rpc.getBalance('0x742d35Cc6634C0532925a3b844Bc454e4438f44e')
const { result } = await tatum.rpc.getBalance('0x742d35Cc6634C0532925a3b844Bc454e4438f44e')
console.log(`Balance: ${data}`)
```

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.7",
"version": "1.5.8",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
7 changes: 2 additions & 5 deletions src/dto/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const UTXO_LOAD_BALANCER_NETWORKS = [
Network.LITECOIN,
Network.LITECOIN_TESTNET,
Network.DOGECOIN,
Network.DOGECOIN_TESTNET
Network.DOGECOIN_TESTNET,
]

export const EVM_LOAD_BALANCER_NETWORKS = [
Expand All @@ -192,10 +192,7 @@ export const EVM_LOAD_BALANCER_NETWORKS = [
Network.ETHEREUM_SEPOLIA,
]

export const LOAD_BALANCER_NETWORKS = [
...UTXO_LOAD_BALANCER_NETWORKS,
...EVM_LOAD_BALANCER_NETWORKS,
]
export const LOAD_BALANCER_NETWORKS = [...UTXO_LOAD_BALANCER_NETWORKS, ...EVM_LOAD_BALANCER_NETWORKS]

export const SOLANA_NETWORKS = [Network.SOLANA, Network.SOLANA_DEVNET]
export const TRON_NETWORKS = [Network.TRON, Network.TRON_SHASTA]
Expand Down
4 changes: 2 additions & 2 deletions src/dto/rpc/AbstractJsonRpcInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { JsonRpcCall } from '../JsonRpcCall.dto'
import { JsonRpcResponse } from '../JsonRpcResponse.dto'

export interface AbstractRpcInterface {
rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<any>>
rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[]>
rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<unknown>>
rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<unknown>[]>
destroy(): void
}
2 changes: 1 addition & 1 deletion src/dto/walletProvider/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './CreateErc1155NftCollection'
export * from './CreateFungibleToken'
export * from './CreateNftCollection'
export * from './CreateErc1155NftCollection'
10 changes: 7 additions & 3 deletions src/e2e/e2e.constant.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Network } from "../dto";
import { Network } from '../dto'

export const TestConst = {
EXISTING_SUBSCRIPTION_ETH_ADDRESS: '0xbaf6dc2e647aeb6f510f9e318856a1bcd66c5e19',
INVALID_ETH_ADDRESS: 'TLduuX5NWFucPPafLbj9eab6Znwrdm72Qv',
}


export const AddressEventNetworks = [
Network.BITCOIN,
Network.BITCOIN_TESTNET,
Expand Down Expand Up @@ -192,4 +191,9 @@ export const ContractAddressLogEventNetworks = [
Network.KLAYTN_BAOBAB,
]

export const InternalTxNetworks = [Network.ETHEREUM, Network.ETHEREUM_SEPOLIA, Network.CELO, Network.CELO_ALFAJORES]
export const InternalTxNetworks = [
Network.ETHEREUM,
Network.ETHEREUM_SEPOLIA,
Network.CELO,
Network.CELO_ALFAJORES,
]
8 changes: 4 additions & 4 deletions src/e2e/rpc/tatum.rpc.bitcoin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ describe('Bitcoin', () => {
version: ApiVersion.V2,
verbose: true,
apiKey: {
v2: 't-646b50dc56974f10418581e1-646b50dc56974f10418581e7'
}
});
v2: 't-646b50dc56974f10418581e1-646b50dc56974f10418581e7',
},
})

for (let i = 0; i < 1000000; i++) {
await tatum.rpc.getBlockChainInfo()
// Wait for 1 second before starting the next iteration
await new Promise(resolve => setTimeout(resolve, 1000));
await new Promise((resolve) => setTimeout(resolve, 1000))
}
}, 1000000)
})
2 changes: 1 addition & 1 deletion src/e2e/rpc/tatum.rpc.polygon.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EvmE2eUtils } from './evm.e2e.utils'
import { Network } from '../../dto'
import { EvmE2eUtils } from './evm.e2e.utils'

describe('Polygon', () => {
describe('mainnet', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/service/address/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ export class Address {
const network = this.config.network
if (isEvmBasedNetwork(network)) {
const rpc = Utils.getRpc<EvmBasedRpc>(this.id, network)
const result = await Promise.all(addresses.map((a, i) => rpc.rawRpcCall(Utils.prepareRpcCall('eth_getBalance', [a, 'pending'], i))))
const result = await Promise.all(
addresses.map((a, i) => rpc.rawRpcCall(Utils.prepareRpcCall('eth_getBalance', [a, 'pending'], i))),
)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return result.map((e) => new BigNumber(e.result).dividedBy(10 ** Constant.DECIMALS[network]).toString())
Expand Down
6 changes: 3 additions & 3 deletions src/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './address'
export * from './fee'
export * from './nft'
export * from './notification'
export * from './rpc'
export * from './tatum'
export * from './nft'
export * from './address'
export * from './fee'
export * from './walletProvider'
9 changes: 7 additions & 2 deletions src/service/notification/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
AddressBasedNotification,
AddressBasedNotificationDetail,
BlockBasedNotification,
BlockBasedNotificationDetail, ContractBasedNotification, ContractBasedNotificationDetail,
BlockBasedNotificationDetail,
ContractBasedNotification,
ContractBasedNotificationDetail,
NotificationType,
} from './notification.dto'

Expand Down Expand Up @@ -214,7 +216,10 @@ export class Subscribe {
contractAddressLogEvent = async (
contractBasedNotificationDetail: ContractBasedNotificationDetail,
): Promise<ResponseDto<ContractBasedNotification>> =>
this.contractBasedNotification(contractBasedNotificationDetail, NotificationType.CONTRACT_ADDRESS_LOG_EVENT)
this.contractBasedNotification(
contractBasedNotificationDetail,
NotificationType.CONTRACT_ADDRESS_LOG_EVENT,
)

/**
* Subscribe to failed txs per block.
Expand Down
30 changes: 15 additions & 15 deletions src/service/rate/rates.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Container, Service } from "typedi";
import { TatumConnector } from "../../connector/tatum.connector";
import { ErrorUtils, ResponseDto } from "../../util";
import { Rate, RateBatchDto } from "./rates.dto";
import { Container, Service } from 'typedi'
import { TatumConnector } from '../../connector/tatum.connector'
import { ErrorUtils, ResponseDto } from '../../util'
import { Rate, RateBatchDto } from './rates.dto'

@Service({
factory: (data: { id: string }) => {
return new Rates(data.id);
return new Rates(data.id)
},
transient: true
transient: true,
})
export class Rates {
private connector: TatumConnector;
private connector: TatumConnector

constructor(private readonly id: string) {
this.connector = Container.of(this.id).get(TatumConnector)
Expand All @@ -20,22 +20,22 @@ export class Rates {
return ErrorUtils.tryFail(async () => {
return this.connector.get<Rate>({
path: `rate/${currency}`,
params: {basePair}
});
});
params: { basePair },
})
})
}

getCurrentRateBatch(pairs: RateBatchDto[]): Promise<ResponseDto<Rate[]>> {
pairs.forEach(pair => {
pairs.forEach((pair) => {
if (!pair.batchId) {
pair.batchId = `${pair.currency}/${pair.basePair}`;
pair.batchId = `${pair.currency}/${pair.basePair}`
}
})
return ErrorUtils.tryFail(async () => {
return this.connector.post<Rate[]>({
path: `rate`,
body: pairs
});
});
body: pairs,
})
})
}
}
4 changes: 2 additions & 2 deletions src/service/rpc/evm/EvmBasedLoadBalancerRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class EvmBasedLoadBalancerRpc extends AbstractEvmBasedRpc implements EvmB
return (await this.loadBalancerRpc.rawRpcCall(preparedCall)) as T
}

async rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<any>> {
async rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<unknown>> {
return this.loadBalancerRpc.rawRpcCall(body)
}

rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[]> {
rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<unknown>[]> {
return this.loadBalancerRpc.rawBatchRpcCall(body)
}

Expand Down
2 changes: 1 addition & 1 deletion src/service/rpc/evm/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './EvmBasedRpc'
export * from './EvmBasedLoadBalancerRpc'
export * from './EvmBasedRpc'
4 changes: 2 additions & 2 deletions src/service/rpc/generic/AbstractBatchRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export abstract class AbstractBatchRpc implements AbstractRpcInterface {
return rpc?.nodes?.[0].url || `https://api.tatum.io/v3/blockchain/node/${network}/`.concat(subPath || '')
}

rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<any>> {
rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<unknown>> {
return this.connector.rpcCall(this.getRpcNodeUrl(), body)
}

rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[]> {
rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<unknown>[]> {
return this.connector.rpcCall(this.getRpcNodeUrl(), body)
}

Expand Down
7 changes: 5 additions & 2 deletions src/service/rpc/generic/GenericRpc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Container, Service } from 'typedi'
import { AbstractBatchRpc } from './AbstractBatchRpc'
import { CONFIG } from '../../../util'
import { TatumConfig } from '../../tatum'
import { AbstractBatchRpc } from './AbstractBatchRpc'

@Service({
factory: (data: { id: string }) => {
Expand All @@ -19,6 +19,9 @@ export class GenericRpc extends AbstractBatchRpc {

protected getRpcNodeUrl() {
const { apiKey, rpc, network } = this.config
return rpc?.nodes?.[0].url || `https://api.tatum.io/v3/blockchain/node/${network}${apiKey?.v1 ? `/${apiKey.v1}` : '/'}`
return (
rpc?.nodes?.[0].url ||
`https://api.tatum.io/v3/blockchain/node/${network}${apiKey?.v1 ? `/${apiKey.v1}` : '/'}`
)
}
}
4 changes: 2 additions & 2 deletions src/service/rpc/generic/LoadBalancerRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class LoadBalancerRpc implements AbstractRpcInterface {
this.activeUrl[nodeType] = { url: fastestServer.node.url, index }
}

async rawRpcCall(rpcCall: JsonRpcCall): Promise<JsonRpcResponse<any>> {
async rawRpcCall(rpcCall: JsonRpcCall): Promise<JsonRpcResponse<unknown>> {
const { url, type } = this.getActiveArchiveUrlWithFallback()
try {
return await this.connector.rpcCall(url, rpcCall)
Expand All @@ -339,7 +339,7 @@ export class LoadBalancerRpc implements AbstractRpcInterface {
}
}

async rawBatchRpcCall(rpcCall: JsonRpcCall[]): Promise<JsonRpcResponse<any>[]> {
async rawBatchRpcCall(rpcCall: JsonRpcCall[]): Promise<JsonRpcResponse<unknown>[]> {
const { url, type } = this.getActiveArchiveUrlWithFallback()
try {
return await this.connector.rpcCall(url, rpcCall)
Expand Down
2 changes: 1 addition & 1 deletion src/service/rpc/generic/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './GenericRpc'
export * from './AbstractBatchRpc'
export * from './GenericRpc'
export * from './LoadBalancerRpc'
6 changes: 3 additions & 3 deletions src/service/rpc/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './utxo'
export * from './evm'
export * from './generic'
export * from './SolanaRpc'
export * from './TronRpc'
export * from './XrpRpc'
export * from './evm'
export * from './generic'
export * from './utxo'
4 changes: 2 additions & 2 deletions src/service/rpc/utxo/UtxoBasedLoadBalancerRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class UtxoBasedLoadBalancerRpc extends AbstractUtxoBasedRpc implements Ut
return (await this.loadBalancerRpc.rawRpcCall(preparedCall)) as T
}

async rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<any>> {
async rawRpcCall(body: JsonRpcCall): Promise<JsonRpcResponse<unknown>> {
return this.loadBalancerRpc.rawRpcCall(body)
}

rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[]> {
rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<unknown>[]> {
return this.loadBalancerRpc.rawBatchRpcCall(body)
}

Expand Down
2 changes: 1 addition & 1 deletion src/service/rpc/utxo/UtxoBasedRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class UtxoBasedRpc extends AbstractUtxoBasedRpc implements UtxoBasedRpcSu
return (await this.genericRpc.rawRpcCall(preparedCall)) as T
}

async rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<any>[]> {
async rawBatchRpcCall(body: JsonRpcCall[]): Promise<JsonRpcResponse<unknown>[]> {
return this.genericRpc.rawBatchRpcCall(body)
}

Expand Down
2 changes: 1 addition & 1 deletion src/service/tatum/tatum.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ export enum RpcNodeType {
NORMAL,

// Node with access to archive data, will be used for historical data
ARCHIVE
ARCHIVE,
}
13 changes: 3 additions & 10 deletions src/service/tatum/tatum.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { Container, Service } from 'typedi'
import {
SolanaRpcSuite,
TronRpcSuite,
UtxoBasedRpcSuite,
XrpRpcSuite,
EvmBasedRpcSuite,
} from '../../dto/rpc'
import { LOAD_BALANCER_NETWORKS } from '../../dto'
import { EvmBasedRpcSuite, SolanaRpcSuite, TronRpcSuite, UtxoBasedRpcSuite, XrpRpcSuite } from '../../dto/rpc'
import { CONFIG, Constant, Utils } from '../../util'
import { Address } from '../address'
import { FeeEvm, FeeUtxo } from '../fee'
import { Nft } from '../nft'
import { Notification } from '../notification'
import { Rates } from '../rate'
import { LoadBalancerRpc } from '../rpc/generic/LoadBalancerRpc'
import { Token } from '../token'
import { WalletProvider } from '../walletProvider'
import { LoadBalancerRpc } from '../rpc/generic/LoadBalancerRpc'
import { LOAD_BALANCER_NETWORKS } from '../../dto'
import { ApiVersion, TatumConfig } from './tatum.dto'

export class BaseTatumSdk {
Expand Down Expand Up @@ -145,7 +139,6 @@ export class TatumSDK {
await loadBalancer.init()
}


return Utils.getClient<T>(id, mergedConfig.network)
}

Expand Down
3 changes: 1 addition & 2 deletions src/service/walletProvider/wallet.provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container, Service } from 'typedi'
import { MetaMask } from './metaMask'
import { EvmBasedRpc } from '../rpc'
import { MetaMask } from './metaMask'

@Service({
factory: (data: { id: string }) => {
Expand All @@ -14,5 +14,4 @@ export class WalletProvider {
constructor(private readonly id: string) {
this.metaMask = Container.of(this.id).get(MetaMask)
}

}
3 changes: 1 addition & 2 deletions src/util/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export const Constant = {
[Network.ZILLIQA_TESTNET]: 'ZIL',
[Network.HAQQ]: 'HAQQ',
[Network.HAQQ_TESTNET]: 'HAQQ',

},
RPC: {
MAINNETS: [
Expand Down Expand Up @@ -289,5 +288,5 @@ export const Constant = {
OPEN_RPC: {
LB_INTERVAL: 60_000,
ALLOWED_BLOCKS_BEHIND: 10,
}
},
}
2 changes: 1 addition & 1 deletion src/util/util.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const Utils = {
}
throw new Error(`Network ${network} is not supported.`)
},
parseStatusPayload: (network: Network, response: JsonRpcResponse<any>) => {
parseStatusPayload: (network: Network, response: JsonRpcResponse<unknown>) => {
if (isUtxoBasedNetwork(network) || isEvmBasedNetwork(network)) {
return new BigNumber((response.result as number) || -1).toNumber()
}
Expand Down

0 comments on commit da0ddb8

Please sign in to comment.