From da0ddb824eea164f1364671207dfbdf34475f0e7 Mon Sep 17 00:00:00 2001 From: oliverjantar Date: Mon, 10 Jul 2023 15:47:40 +0200 Subject: [PATCH] Increase version, fix lint issues --- CHANGELOG.md | 4 +++ README.md | 2 +- package.json | 2 +- src/dto/Network.ts | 7 ++--- src/dto/rpc/AbstractJsonRpcInterface.ts | 4 +-- src/dto/walletProvider/index.ts | 2 +- src/e2e/e2e.constant.ts | 10 +++++-- src/e2e/rpc/tatum.rpc.bitcoin.spec.ts | 8 ++--- src/e2e/rpc/tatum.rpc.polygon.spec.ts | 2 +- src/service/address/address.ts | 4 ++- src/service/index.ts | 6 ++-- src/service/notification/subscribe.ts | 9 ++++-- src/service/rate/rates.ts | 30 +++++++++---------- .../rpc/evm/EvmBasedLoadBalancerRpc.ts | 4 +-- src/service/rpc/evm/index.ts | 2 +- src/service/rpc/generic/AbstractBatchRpc.ts | 4 +-- src/service/rpc/generic/GenericRpc.ts | 7 +++-- src/service/rpc/generic/LoadBalancerRpc.ts | 4 +-- src/service/rpc/generic/index.ts | 2 +- src/service/rpc/index.ts | 6 ++-- .../rpc/utxo/UtxoBasedLoadBalancerRpc.ts | 4 +-- src/service/rpc/utxo/UtxoBasedRpc.ts | 2 +- src/service/tatum/tatum.dto.ts | 2 +- src/service/tatum/tatum.ts | 13 ++------ src/service/walletProvider/wallet.provider.ts | 3 +- src/util/constant.ts | 3 +- src/util/util.shared.ts | 2 +- 27 files changed, 77 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d08cf39cde..f31d1f87b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 279b6747dd..c203222e84 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ import { TatumSDK, Network, Ethereum } from '@tatumcom/js' const tatum = await TatumSDK.init({ network: Network.ETHEREUM }) -const { data } = await tatum.rpc.getBalance('0x742d35Cc6634C0532925a3b844Bc454e4438f44e') +const { result } = await tatum.rpc.getBalance('0x742d35Cc6634C0532925a3b844Bc454e4438f44e') console.log(`Balance: ${data}`) ``` diff --git a/package.json b/package.json index caa7f25af9..00d4e11106 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/dto/Network.ts b/src/dto/Network.ts index aaf1b7dad0..dbf2c178e1 100644 --- a/src/dto/Network.ts +++ b/src/dto/Network.ts @@ -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 = [ @@ -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] diff --git a/src/dto/rpc/AbstractJsonRpcInterface.ts b/src/dto/rpc/AbstractJsonRpcInterface.ts index 7619fcf3e4..db06c77d2d 100644 --- a/src/dto/rpc/AbstractJsonRpcInterface.ts +++ b/src/dto/rpc/AbstractJsonRpcInterface.ts @@ -2,7 +2,7 @@ import { JsonRpcCall } from '../JsonRpcCall.dto' import { JsonRpcResponse } from '../JsonRpcResponse.dto' export interface AbstractRpcInterface { - rawRpcCall(body: JsonRpcCall): Promise> - rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> + rawRpcCall(body: JsonRpcCall): Promise> + rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> destroy(): void } diff --git a/src/dto/walletProvider/index.ts b/src/dto/walletProvider/index.ts index 8dec0766f1..80fda2a8a0 100644 --- a/src/dto/walletProvider/index.ts +++ b/src/dto/walletProvider/index.ts @@ -1,3 +1,3 @@ +export * from './CreateErc1155NftCollection' export * from './CreateFungibleToken' export * from './CreateNftCollection' -export * from './CreateErc1155NftCollection' diff --git a/src/e2e/e2e.constant.ts b/src/e2e/e2e.constant.ts index 265f471886..2e8721fc30 100644 --- a/src/e2e/e2e.constant.ts +++ b/src/e2e/e2e.constant.ts @@ -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, @@ -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, +] diff --git a/src/e2e/rpc/tatum.rpc.bitcoin.spec.ts b/src/e2e/rpc/tatum.rpc.bitcoin.spec.ts index a58c8bdebe..56eea9e1c2 100644 --- a/src/e2e/rpc/tatum.rpc.bitcoin.spec.ts +++ b/src/e2e/rpc/tatum.rpc.bitcoin.spec.ts @@ -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) }) diff --git a/src/e2e/rpc/tatum.rpc.polygon.spec.ts b/src/e2e/rpc/tatum.rpc.polygon.spec.ts index 8320411732..40a7a2cf34 100644 --- a/src/e2e/rpc/tatum.rpc.polygon.spec.ts +++ b/src/e2e/rpc/tatum.rpc.polygon.spec.ts @@ -1,5 +1,5 @@ -import { EvmE2eUtils } from './evm.e2e.utils' import { Network } from '../../dto' +import { EvmE2eUtils } from './evm.e2e.utils' describe('Polygon', () => { describe('mainnet', () => { diff --git a/src/service/address/address.ts b/src/service/address/address.ts index a38ef0be32..ef39e8b68d 100644 --- a/src/service/address/address.ts +++ b/src/service/address/address.ts @@ -236,7 +236,9 @@ export class Address { const network = this.config.network if (isEvmBasedNetwork(network)) { const rpc = Utils.getRpc(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()) diff --git a/src/service/index.ts b/src/service/index.ts index a8eedaf11e..17bfb22bb5 100644 --- a/src/service/index.ts +++ b/src/service/index.ts @@ -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' diff --git a/src/service/notification/subscribe.ts b/src/service/notification/subscribe.ts index 7d680c9154..7fb8654b85 100644 --- a/src/service/notification/subscribe.ts +++ b/src/service/notification/subscribe.ts @@ -7,7 +7,9 @@ import { AddressBasedNotification, AddressBasedNotificationDetail, BlockBasedNotification, - BlockBasedNotificationDetail, ContractBasedNotification, ContractBasedNotificationDetail, + BlockBasedNotificationDetail, + ContractBasedNotification, + ContractBasedNotificationDetail, NotificationType, } from './notification.dto' @@ -214,7 +216,10 @@ export class Subscribe { contractAddressLogEvent = async ( contractBasedNotificationDetail: ContractBasedNotificationDetail, ): Promise> => - this.contractBasedNotification(contractBasedNotificationDetail, NotificationType.CONTRACT_ADDRESS_LOG_EVENT) + this.contractBasedNotification( + contractBasedNotificationDetail, + NotificationType.CONTRACT_ADDRESS_LOG_EVENT, + ) /** * Subscribe to failed txs per block. diff --git a/src/service/rate/rates.ts b/src/service/rate/rates.ts index 85ad5ae237..86f053b030 100644 --- a/src/service/rate/rates.ts +++ b/src/service/rate/rates.ts @@ -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) @@ -20,22 +20,22 @@ export class Rates { return ErrorUtils.tryFail(async () => { return this.connector.get({ path: `rate/${currency}`, - params: {basePair} - }); - }); + params: { basePair }, + }) + }) } getCurrentRateBatch(pairs: RateBatchDto[]): Promise> { - 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({ path: `rate`, - body: pairs - }); - }); + body: pairs, + }) + }) } } diff --git a/src/service/rpc/evm/EvmBasedLoadBalancerRpc.ts b/src/service/rpc/evm/EvmBasedLoadBalancerRpc.ts index c13aaf4d44..eb1068d797 100644 --- a/src/service/rpc/evm/EvmBasedLoadBalancerRpc.ts +++ b/src/service/rpc/evm/EvmBasedLoadBalancerRpc.ts @@ -23,11 +23,11 @@ export class EvmBasedLoadBalancerRpc extends AbstractEvmBasedRpc implements EvmB return (await this.loadBalancerRpc.rawRpcCall(preparedCall)) as T } - async rawRpcCall(body: JsonRpcCall): Promise> { + async rawRpcCall(body: JsonRpcCall): Promise> { return this.loadBalancerRpc.rawRpcCall(body) } - rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> { + rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> { return this.loadBalancerRpc.rawBatchRpcCall(body) } diff --git a/src/service/rpc/evm/index.ts b/src/service/rpc/evm/index.ts index c89ca01f74..ebdb2caf2f 100644 --- a/src/service/rpc/evm/index.ts +++ b/src/service/rpc/evm/index.ts @@ -1,2 +1,2 @@ -export * from './EvmBasedRpc' export * from './EvmBasedLoadBalancerRpc' +export * from './EvmBasedRpc' diff --git a/src/service/rpc/generic/AbstractBatchRpc.ts b/src/service/rpc/generic/AbstractBatchRpc.ts index 89c6db7818..2a50ac2395 100644 --- a/src/service/rpc/generic/AbstractBatchRpc.ts +++ b/src/service/rpc/generic/AbstractBatchRpc.ts @@ -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> { + rawRpcCall(body: JsonRpcCall): Promise> { return this.connector.rpcCall(this.getRpcNodeUrl(), body) } - rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> { + rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> { return this.connector.rpcCall(this.getRpcNodeUrl(), body) } diff --git a/src/service/rpc/generic/GenericRpc.ts b/src/service/rpc/generic/GenericRpc.ts index 4923d3b80c..6f6dceba5b 100644 --- a/src/service/rpc/generic/GenericRpc.ts +++ b/src/service/rpc/generic/GenericRpc.ts @@ -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 }) => { @@ -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}` : '/'}` + ) } } diff --git a/src/service/rpc/generic/LoadBalancerRpc.ts b/src/service/rpc/generic/LoadBalancerRpc.ts index 328b70328b..1f243b45e6 100644 --- a/src/service/rpc/generic/LoadBalancerRpc.ts +++ b/src/service/rpc/generic/LoadBalancerRpc.ts @@ -329,7 +329,7 @@ export class LoadBalancerRpc implements AbstractRpcInterface { this.activeUrl[nodeType] = { url: fastestServer.node.url, index } } - async rawRpcCall(rpcCall: JsonRpcCall): Promise> { + async rawRpcCall(rpcCall: JsonRpcCall): Promise> { const { url, type } = this.getActiveArchiveUrlWithFallback() try { return await this.connector.rpcCall(url, rpcCall) @@ -339,7 +339,7 @@ export class LoadBalancerRpc implements AbstractRpcInterface { } } - async rawBatchRpcCall(rpcCall: JsonRpcCall[]): Promise[]> { + async rawBatchRpcCall(rpcCall: JsonRpcCall[]): Promise[]> { const { url, type } = this.getActiveArchiveUrlWithFallback() try { return await this.connector.rpcCall(url, rpcCall) diff --git a/src/service/rpc/generic/index.ts b/src/service/rpc/generic/index.ts index 12fc39f1b7..3c31e7d541 100644 --- a/src/service/rpc/generic/index.ts +++ b/src/service/rpc/generic/index.ts @@ -1,3 +1,3 @@ -export * from './GenericRpc' export * from './AbstractBatchRpc' +export * from './GenericRpc' export * from './LoadBalancerRpc' diff --git a/src/service/rpc/index.ts b/src/service/rpc/index.ts index d8c8e6986a..ea35a58246 100644 --- a/src/service/rpc/index.ts +++ b/src/service/rpc/index.ts @@ -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' diff --git a/src/service/rpc/utxo/UtxoBasedLoadBalancerRpc.ts b/src/service/rpc/utxo/UtxoBasedLoadBalancerRpc.ts index 38358111d4..55d1530846 100644 --- a/src/service/rpc/utxo/UtxoBasedLoadBalancerRpc.ts +++ b/src/service/rpc/utxo/UtxoBasedLoadBalancerRpc.ts @@ -23,11 +23,11 @@ export class UtxoBasedLoadBalancerRpc extends AbstractUtxoBasedRpc implements Ut return (await this.loadBalancerRpc.rawRpcCall(preparedCall)) as T } - async rawRpcCall(body: JsonRpcCall): Promise> { + async rawRpcCall(body: JsonRpcCall): Promise> { return this.loadBalancerRpc.rawRpcCall(body) } - rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> { + rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> { return this.loadBalancerRpc.rawBatchRpcCall(body) } diff --git a/src/service/rpc/utxo/UtxoBasedRpc.ts b/src/service/rpc/utxo/UtxoBasedRpc.ts index 7539a25b13..c140a6a935 100644 --- a/src/service/rpc/utxo/UtxoBasedRpc.ts +++ b/src/service/rpc/utxo/UtxoBasedRpc.ts @@ -23,7 +23,7 @@ export class UtxoBasedRpc extends AbstractUtxoBasedRpc implements UtxoBasedRpcSu return (await this.genericRpc.rawRpcCall(preparedCall)) as T } - async rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> { + async rawBatchRpcCall(body: JsonRpcCall[]): Promise[]> { return this.genericRpc.rawBatchRpcCall(body) } diff --git a/src/service/tatum/tatum.dto.ts b/src/service/tatum/tatum.dto.ts index 7582fdc6e3..60fd579c8d 100644 --- a/src/service/tatum/tatum.dto.ts +++ b/src/service/tatum/tatum.dto.ts @@ -94,5 +94,5 @@ export enum RpcNodeType { NORMAL, // Node with access to archive data, will be used for historical data - ARCHIVE + ARCHIVE, } diff --git a/src/service/tatum/tatum.ts b/src/service/tatum/tatum.ts index babb7edfcf..0092f15a3f 100644 --- a/src/service/tatum/tatum.ts +++ b/src/service/tatum/tatum.ts @@ -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 { @@ -145,7 +139,6 @@ export class TatumSDK { await loadBalancer.init() } - return Utils.getClient(id, mergedConfig.network) } diff --git a/src/service/walletProvider/wallet.provider.ts b/src/service/walletProvider/wallet.provider.ts index 948bfb8446..5b020c29b2 100644 --- a/src/service/walletProvider/wallet.provider.ts +++ b/src/service/walletProvider/wallet.provider.ts @@ -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 }) => { @@ -14,5 +14,4 @@ export class WalletProvider { constructor(private readonly id: string) { this.metaMask = Container.of(this.id).get(MetaMask) } - } diff --git a/src/util/constant.ts b/src/util/constant.ts index e9d74c0c79..dcfbae98c1 100644 --- a/src/util/constant.ts +++ b/src/util/constant.ts @@ -197,7 +197,6 @@ export const Constant = { [Network.ZILLIQA_TESTNET]: 'ZIL', [Network.HAQQ]: 'HAQQ', [Network.HAQQ_TESTNET]: 'HAQQ', - }, RPC: { MAINNETS: [ @@ -289,5 +288,5 @@ export const Constant = { OPEN_RPC: { LB_INTERVAL: 60_000, ALLOWED_BLOCKS_BEHIND: 10, - } + }, } diff --git a/src/util/util.shared.ts b/src/util/util.shared.ts index c2ee04d5e9..20fa131465 100644 --- a/src/util/util.shared.ts +++ b/src/util/util.shared.ts @@ -107,7 +107,7 @@ export const Utils = { } throw new Error(`Network ${network} is not supported.`) }, - parseStatusPayload: (network: Network, response: JsonRpcResponse) => { + parseStatusPayload: (network: Network, response: JsonRpcResponse) => { if (isUtxoBasedNetwork(network) || isEvmBasedNetwork(network)) { return new BigNumber((response.result as number) || -1).toNumber() }