From 6e976f2ce297f7bab7c3bcd49f2bf921f3b91d2a Mon Sep 17 00:00:00 2001 From: Lukas Kotol Date: Thu, 2 Nov 2023 16:07:05 +0100 Subject: [PATCH] ALL-3134 Update Tezos methods --- CHANGELOG.md | 4 ++ package.json | 2 +- src/dto/GetI.ts | 3 +- src/dto/PostI.ts | 2 +- src/dto/rpc/TezosRpcSuite.ts | 26 +++++++------ src/e2e/rpc/other/tatum.rpc.tezos.spec.ts | 8 ++-- src/service/rpc/generic/LoadBalancer.ts | 39 +++++++++++-------- src/service/rpc/other/AbstractTezosRpc.ts | 30 +++++++------- src/service/rpc/other/EosLoadBalancerRpc.ts | 2 +- src/service/rpc/other/TezosLoadBalancerRpc.ts | 4 +- 10 files changed, 68 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0be233699..267ea38a6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [4.1.22] - 2023.11.2 +### Updated +- Naming of the Tezos RPC methods + ## [4.1.21] - 2023.11.2 ### Added - Added RPC support for the TEZOS network. Users can now make RPC calls to these network using the `Network.TEZOS` network. diff --git a/package.json b/package.json index fdbd954d41..cc5bf48b24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tatumio/tatum", - "version": "4.1.21", + "version": "4.1.22", "description": "Tatum JS SDK", "author": "Tatum", "repository": "https://github.com/tatumio/tatum-js", diff --git a/src/dto/GetI.ts b/src/dto/GetI.ts index c4358b76a1..f13a9944e8 100644 --- a/src/dto/GetI.ts +++ b/src/dto/GetI.ts @@ -1,5 +1,4 @@ export interface GetI { path: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - basePath?: string + prefix?: string } diff --git a/src/dto/PostI.ts b/src/dto/PostI.ts index be52032ea4..d5e376ef8f 100644 --- a/src/dto/PostI.ts +++ b/src/dto/PostI.ts @@ -2,5 +2,5 @@ export interface PostI { path: string // eslint-disable-next-line @typescript-eslint/no-explicit-any body?: any - basePath?: string + prefix?: string } diff --git a/src/dto/rpc/TezosRpcSuite.ts b/src/dto/rpc/TezosRpcSuite.ts index 9d8f81d7b7..db44b2cef7 100644 --- a/src/dto/rpc/TezosRpcSuite.ts +++ b/src/dto/rpc/TezosRpcSuite.ts @@ -24,7 +24,7 @@ export interface GetContractBase extends GetBlock { contractId: string } -export interface GetContractsBigMapGet extends GetContractBase { +export interface GetContractBigMapValue extends GetContractBase { key: any type: any } @@ -78,29 +78,31 @@ export interface TezosRpcInterface { getBlockHashes(params: GetBlockHashes): Promise - getContracts(params: GetContract): Promise + getContract(params: GetContract): Promise - getContractsTickets(params: GetContractBase): Promise + getContractTickets(params: GetContractBase): Promise - getContractsBalance(params: GetContractBase): Promise + getContractBalance(params: GetContractBase): Promise - getContractsBalanceAndFrozenBonds(params: GetContractBase): Promise + getContractBalanceAndFrozenBonds(params: GetContractBase): Promise - getContractsBigMapGet(params: GetContractsBigMapGet): Promise + getContractBigMapValue(params: GetContractBigMapValue): Promise - getContractsCounter(params: GetContractBase): Promise + getContractCounter(params: GetContractBase): Promise getContractDelegate(params: GetContractBase): Promise - getContractsEntrypoints(params: GetContract): Promise + getContractEntrypoints(params: GetContract): Promise - getContractsEntrypoint(params: GetContractsEntrypoints): Promise + getContractEntrypoint(params: GetContractsEntrypoints): Promise - getContractsManagerKey(params: GetContractBase): Promise + getContractManagerKey(params: GetContractBase): Promise + + getContracts(params: GetBlock): Promise getBlock(params: GetBlock): Promise - getBlockHash(params: GetBlockHash): Promise + getBlockHash(params: GetBlock): Promise getOperationHashes(params: GetBlock): Promise @@ -124,7 +126,7 @@ export interface TezosRpcInterface { getLevelsCaboose(params: GetChainId): Promise - getLevelsSavePoint(params: GetChainId): Promise + getLevelsSavepoint(params: GetChainId): Promise getErrorsSchema(): Promise diff --git a/src/e2e/rpc/other/tatum.rpc.tezos.spec.ts b/src/e2e/rpc/other/tatum.rpc.tezos.spec.ts index 91616a95ab..54398062bb 100644 --- a/src/e2e/rpc/other/tatum.rpc.tezos.spec.ts +++ b/src/e2e/rpc/other/tatum.rpc.tezos.spec.ts @@ -11,7 +11,7 @@ const getTezosRpc = async (testnet?: boolean) => verbose: e2eUtil.isVerbose, }) - describe.each([true, false])(`Tezos`, (testnet: boolean) => { + describe.each([false, true])(`Tezos`, (testnet: boolean) => { describe(`${testnet ? 'Testnet' : 'Mainnet'}`, () => { it('getBlock', async () => { @@ -38,7 +38,7 @@ const getTezosRpc = async (testnet?: boolean) => if (!testnet) { it('getContract', async () => { const tatum = await getTezosRpc(testnet) - const result = await tatum.rpc.getContracts({ + const result = await tatum.rpc.getContract({ chainId: 'main', contractId: 'KT1Hkg5qeNhfwpKW4fXvq7HGZB9z2EnmCCA9', block: '3000000' @@ -49,7 +49,7 @@ const getTezosRpc = async (testnet?: boolean) => it('getContractBalanceAndFrozenBonds', async () => { const tatum = await getTezosRpc(testnet) - const result = await tatum.rpc.getContractsBalanceAndFrozenBonds({ + const result = await tatum.rpc.getContractBalanceAndFrozenBonds({ chainId: 'main', contractId: 'KT1Hkg5qeNhfwpKW4fXvq7HGZB9z2EnmCCA9', block: '3000000' @@ -60,7 +60,7 @@ const getTezosRpc = async (testnet?: boolean) => it('getContractsEntrypoints', async () => { const tatum = await getTezosRpc(testnet) - const result = await tatum.rpc.getContractsEntrypoints({ + const result = await tatum.rpc.getContractEntrypoints({ chainId: 'main', contractId: 'KT1Hkg5qeNhfwpKW4fXvq7HGZB9z2EnmCCA9', block: '3000000' diff --git a/src/service/rpc/generic/LoadBalancer.ts b/src/service/rpc/generic/LoadBalancer.ts index 66b761bbef..62764e4035 100644 --- a/src/service/rpc/generic/LoadBalancer.ts +++ b/src/service/rpc/generic/LoadBalancer.ts @@ -55,6 +55,7 @@ interface HandleFailedRpcCallParams { e: unknown nodeType: RpcNodeType requestType: RequestType + url: string } @Service({ @@ -394,9 +395,8 @@ export class LoadBalancer implements AbstractRpcInterface { } } - async handleFailedRpcCall({rpcCall, e, nodeType, requestType}: HandleFailedRpcCallParams) { + async handleFailedRpcCall({ rpcCall, e, nodeType, requestType, url }: HandleFailedRpcCallParams) { const { rpc: rpcConfig } = Container.of(this.id).get(CONFIG) - const { url } = this.getActiveUrl(nodeType) const activeIndex = this.getActiveIndex(nodeType) if (requestType === RequestType.RPC && 'method' in rpcCall) { Utils.log({ @@ -418,14 +418,14 @@ export class LoadBalancer implements AbstractRpcInterface { } else if (requestType === RequestType.POST && 'path' in rpcCall && 'body' in rpcCall) { Utils.log({ id: this.id, - message: `Failed to call request on url ${rpcCall.basePath}${rpcCall.path} with body ${JSON.stringify( + message: `Failed to call request on url ${url}${rpcCall.path} with body ${JSON.stringify( rpcCall.body, )}. Error: ${JSON.stringify(e, Object.getOwnPropertyNames(e))}`, }) } else if (requestType === RequestType.GET && 'path' in rpcCall) { Utils.log({ id: this.id, - message: `Failed to call request on url ${rpcCall.basePath}${rpcCall.path}. Error: ${JSON.stringify( + message: `Failed to call request on url ${url}${rpcCall.path}. Error: ${JSON.stringify( e, Object.getOwnPropertyNames(e), )}`, @@ -487,7 +487,7 @@ export class LoadBalancer implements AbstractRpcInterface { }) return await this.connector.rpcCall(url, rpcCall) } catch (e) { - await this.handleFailedRpcCall({ rpcCall, e, nodeType: type, requestType: RequestType.RPC }) + await this.handleFailedRpcCall({ rpcCall, e, nodeType: type, requestType: RequestType.RPC, url }) return await this.rawRpcCall(rpcCall) } } @@ -497,35 +497,42 @@ export class LoadBalancer implements AbstractRpcInterface { try { return await this.connector.rpcCall(url, rpcCall) } catch (e) { - await this.handleFailedRpcCall({ rpcCall, e, nodeType: type, requestType: RequestType.BATCH }) + await this.handleFailedRpcCall({ rpcCall, e, nodeType: type, requestType: RequestType.BATCH, url }) return await this.rawBatchRpcCall(rpcCall) } } - async post({ path, body, basePath }: PostI): Promise { + async post({ path, body, prefix }: PostI): Promise { const { url, type } = this.getActiveNormalUrlWithFallback() - const basePathUrl= basePath ?? url + const basePath = prefix ? `${url}${prefix}` : url try { - return await this.connector.post({ basePath: basePathUrl, path, body }) + return await this.connector.post({ basePath, path, body }) } catch (e) { await this.handleFailedRpcCall({ - rpcCall: { path, body, basePath: basePathUrl }, + rpcCall: { path, body }, e, nodeType: type, requestType: RequestType.POST, + url: basePath, }) - return await this.post({ path, body, basePath }) + return await this.post({ path, body, prefix }) } } - async get({ path, basePath }: GetI): Promise { + async get({ path, prefix }: GetI): Promise { const { url, type } = this.getActiveNormalUrlWithFallback() - const basePathUrl= basePath ?? url + const basePath = prefix ? `${url}${prefix}` : url try { - return await this.connector.get({ basePath: basePathUrl, path }) + return await this.connector.get({ basePath, path }) } catch (e) { - await this.handleFailedRpcCall({ rpcCall: { path, basePath: basePathUrl }, e, nodeType: type, requestType: RequestType.GET }) - return await this.get({ path, basePath }) + await this.handleFailedRpcCall({ + rpcCall: { path }, + e, + nodeType: type, + requestType: RequestType.GET, + url: basePath, + }) + return await this.get({ path, prefix }) } } diff --git a/src/service/rpc/other/AbstractTezosRpc.ts b/src/service/rpc/other/AbstractTezosRpc.ts index 3057b5298e..f0e31e0e62 100644 --- a/src/service/rpc/other/AbstractTezosRpc.ts +++ b/src/service/rpc/other/AbstractTezosRpc.ts @@ -3,12 +3,11 @@ import { Service } from 'typedi' import { GetBlock, - GetBlockHash, GetBlockHashes, GetChainId, GetContract, GetContractBase, - GetContractsBigMapGet, + GetContractBigMapValue, GetContractsEntrypoints, GetInvalidBlocks, GetProtocol, InjectBlock, @@ -72,7 +71,7 @@ export abstract class AbstractTezosRpc implements TezosRpcInterface { return this.sendGet({ path: `/chains/${chainId}/blocks/${block}`}) } - getBlockHash(params: GetBlockHash): Promise { + getBlockHash(params: GetBlock): Promise { const { chainId, block } = params return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/hash`}) } @@ -116,51 +115,56 @@ export abstract class AbstractTezosRpc implements TezosRpcInterface { return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/delegate`}) } - getContracts(params: GetContract): Promise { + getContract(params: GetContract): Promise { const { chainId, contractId, block, ...rest } = params return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}`, queryParams: rest }) } - getContractsBalance(params: GetContractBase): Promise { + getContractBalance(params: GetContractBase): Promise { const { chainId, block, contractId } = params return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/balance`}) } - getContractsBalanceAndFrozenBonds(params: GetContractBase): Promise { + getContractBalanceAndFrozenBonds(params: GetContractBase): Promise { const { chainId, block, contractId } = params return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/balance_and_frozen_bonds`}) } - getContractsBigMapGet(params: GetContractsBigMapGet): Promise { + getContractBigMapValue(params: GetContractBigMapValue): Promise { const { chainId, block, contractId, ...rest } = params return this.sendPost({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/big_map_get`, body: rest }) } - getContractsCounter(params: GetContractBase): Promise { + getContractCounter(params: GetContractBase): Promise { const { chainId, block, contractId} = params return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/counter`}) } - getContractsEntrypoint(params: GetContractsEntrypoints): Promise { + getContractEntrypoint(params: GetContractsEntrypoints): Promise { const { chainId, block, contractId, entrypoint, ...rest} = params return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/entrypoints/${entrypoint}`, queryParams: rest }) } - getContractsEntrypoints(params: GetContract): Promise { + getContractEntrypoints(params: GetContract): Promise { const { chainId, block, contractId, ...rest} = params return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/entrypoints`, queryParams: rest }) } - getContractsManagerKey(params: GetContractBase): Promise { + getContractManagerKey(params: GetContractBase): Promise { const { chainId, block, contractId} = params return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/manager_key`}) } - getContractsTickets(params: GetContractBase): Promise { + getContractTickets(params: GetContractBase): Promise { const { chainId, block, contractId} = params return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/all_ticket_balances` }) } + getContracts(params: GetBlock): Promise { + const { chainId, block } = params + return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts`}) + } + getErrorsSchema(): Promise { return this.sendGet({ path: `/errors/` }) } @@ -184,7 +188,7 @@ export abstract class AbstractTezosRpc implements TezosRpcInterface { return this.sendGet({ path: `/chains/${chainId}/levels/checkpoint` }) } - getLevelsSavePoint(params: GetChainId): Promise { + getLevelsSavepoint(params: GetChainId): Promise { const { chainId, } = params return this.sendGet({ path: `/chains/${chainId}/levels/savepoint` }) } diff --git a/src/service/rpc/other/EosLoadBalancerRpc.ts b/src/service/rpc/other/EosLoadBalancerRpc.ts index 53eed0bf49..083abc099f 100644 --- a/src/service/rpc/other/EosLoadBalancerRpc.ts +++ b/src/service/rpc/other/EosLoadBalancerRpc.ts @@ -26,7 +26,7 @@ export class EosLoadBalancerRpc extends AbstractEosRpc implements EosRpcSuite { } protected post(post: PostI): Promise { - return this.loadBalancer.post({ ...post, basePath: `${this.getRpcNodeUrl()}${Constant.EOS_PREFIX}` }) + return this.loadBalancer.post({ ...post, prefix: Constant.EOS_PREFIX }) } getRpcNodeUrl(): string { diff --git a/src/service/rpc/other/TezosLoadBalancerRpc.ts b/src/service/rpc/other/TezosLoadBalancerRpc.ts index 7fccea14ac..e25767adba 100644 --- a/src/service/rpc/other/TezosLoadBalancerRpc.ts +++ b/src/service/rpc/other/TezosLoadBalancerRpc.ts @@ -43,10 +43,10 @@ export class TezosLoadBalancerRpc extends AbstractTezosRpc { } protected get(get: GetI): Promise { - return this.loadBalancer.get({ ...get, basePath: this.getRpcNodeUrl() }) + return this.loadBalancer.get(get) } protected post(post: PostI): Promise { - return this.loadBalancer.post({ ...post, basePath: this.getRpcNodeUrl() }) + return this.loadBalancer.post(post) } }