Skip to content

Commit

Permalink
ALL-3134 Update Tezos methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel committed Nov 3, 2023
1 parent 18da3ab commit 6e976f2
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
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.1.21",
"version": "4.1.22",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
3 changes: 1 addition & 2 deletions src/dto/GetI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface GetI {
path: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
basePath?: string
prefix?: string
}
2 changes: 1 addition & 1 deletion src/dto/PostI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export interface PostI {
path: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body?: any
basePath?: string
prefix?: string
}
26 changes: 14 additions & 12 deletions src/dto/rpc/TezosRpcSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -78,29 +78,31 @@ export interface TezosRpcInterface {

getBlockHashes(params: GetBlockHashes): Promise<any>

getContracts(params: GetContract): Promise<any>
getContract(params: GetContract): Promise<any>

getContractsTickets(params: GetContractBase): Promise<any>
getContractTickets(params: GetContractBase): Promise<any>

getContractsBalance(params: GetContractBase): Promise<any>
getContractBalance(params: GetContractBase): Promise<any>

getContractsBalanceAndFrozenBonds(params: GetContractBase): Promise<any>
getContractBalanceAndFrozenBonds(params: GetContractBase): Promise<any>

getContractsBigMapGet(params: GetContractsBigMapGet): Promise<any>
getContractBigMapValue(params: GetContractBigMapValue): Promise<any>

getContractsCounter(params: GetContractBase): Promise<any>
getContractCounter(params: GetContractBase): Promise<any>

getContractDelegate(params: GetContractBase): Promise<any>

getContractsEntrypoints(params: GetContract): Promise<any>
getContractEntrypoints(params: GetContract): Promise<any>

getContractsEntrypoint(params: GetContractsEntrypoints): Promise<any>
getContractEntrypoint(params: GetContractsEntrypoints): Promise<any>

getContractsManagerKey(params: GetContractBase): Promise<any>
getContractManagerKey(params: GetContractBase): Promise<any>

getContracts(params: GetBlock): Promise<any>

getBlock(params: GetBlock): Promise<any>

getBlockHash(params: GetBlockHash): Promise<any>
getBlockHash(params: GetBlock): Promise<any>

getOperationHashes(params: GetBlock): Promise<any>

Expand All @@ -124,7 +126,7 @@ export interface TezosRpcInterface {

getLevelsCaboose(params: GetChainId): Promise<any>

getLevelsSavePoint(params: GetChainId): Promise<any>
getLevelsSavepoint(params: GetChainId): Promise<any>

getErrorsSchema(): Promise<any>

Expand Down
8 changes: 4 additions & 4 deletions src/e2e/rpc/other/tatum.rpc.tezos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down
39 changes: 23 additions & 16 deletions src/service/rpc/generic/LoadBalancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface HandleFailedRpcCallParams {
e: unknown
nodeType: RpcNodeType
requestType: RequestType
url: string
}

@Service({
Expand Down Expand Up @@ -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({
Expand All @@ -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),
)}`,
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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<T>({ path, body, basePath }: PostI): Promise<T> {
async post<T>({ path, body, prefix }: PostI): Promise<T> {
const { url, type } = this.getActiveNormalUrlWithFallback()
const basePathUrl= basePath ?? url
const basePath = prefix ? `${url}${prefix}` : url
try {
return await this.connector.post<T>({ basePath: basePathUrl, path, body })
return await this.connector.post<T>({ 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<T>({ path, basePath }: GetI): Promise<T> {
async get<T>({ path, prefix }: GetI): Promise<T> {
const { url, type } = this.getActiveNormalUrlWithFallback()
const basePathUrl= basePath ?? url
const basePath = prefix ? `${url}${prefix}` : url
try {
return await this.connector.get<T>({ basePath: basePathUrl, path })
return await this.connector.get<T>({ 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 })
}
}

Expand Down
30 changes: 17 additions & 13 deletions src/service/rpc/other/AbstractTezosRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import { Service } from 'typedi'
import {
GetBlock,
GetBlockHash,
GetBlockHashes,
GetChainId,
GetContract,
GetContractBase,
GetContractsBigMapGet,
GetContractBigMapValue,
GetContractsEntrypoints,
GetInvalidBlocks,
GetProtocol, InjectBlock,
Expand Down Expand Up @@ -72,7 +71,7 @@ export abstract class AbstractTezosRpc implements TezosRpcInterface {
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}`})
}

getBlockHash(params: GetBlockHash): Promise<any> {
getBlockHash(params: GetBlock): Promise<any> {
const { chainId, block } = params
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/hash`})
}
Expand Down Expand Up @@ -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<any> {
getContract(params: GetContract): Promise<any> {
const { chainId, contractId, block, ...rest } = params
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}`, queryParams: rest })
}

getContractsBalance(params: GetContractBase): Promise<any> {
getContractBalance(params: GetContractBase): Promise<any> {
const { chainId, block, contractId } = params
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/balance`})
}

getContractsBalanceAndFrozenBonds(params: GetContractBase): Promise<any> {
getContractBalanceAndFrozenBonds(params: GetContractBase): Promise<any> {
const { chainId, block, contractId } = params
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/balance_and_frozen_bonds`})
}

getContractsBigMapGet(params: GetContractsBigMapGet): Promise<any> {
getContractBigMapValue(params: GetContractBigMapValue): Promise<any> {
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<any> {
getContractCounter(params: GetContractBase): Promise<any> {
const { chainId, block, contractId} = params
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/counter`})
}

getContractsEntrypoint(params: GetContractsEntrypoints): Promise<any> {
getContractEntrypoint(params: GetContractsEntrypoints): Promise<any> {
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<any> {
getContractEntrypoints(params: GetContract): Promise<any> {
const { chainId, block, contractId, ...rest} = params
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/entrypoints`, queryParams: rest })
}

getContractsManagerKey(params: GetContractBase): Promise<any> {
getContractManagerKey(params: GetContractBase): Promise<any> {
const { chainId, block, contractId} = params
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/manager_key`})
}

getContractsTickets(params: GetContractBase): Promise<any> {
getContractTickets(params: GetContractBase): Promise<any> {
const { chainId, block, contractId} = params
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts/${contractId}/all_ticket_balances` })
}

getContracts(params: GetBlock): Promise<any> {
const { chainId, block } = params
return this.sendGet({ path: `/chains/${chainId}/blocks/${block}/context/contracts`})
}

getErrorsSchema(): Promise<any> {
return this.sendGet({ path: `/errors/` })
}
Expand All @@ -184,7 +188,7 @@ export abstract class AbstractTezosRpc implements TezosRpcInterface {
return this.sendGet({ path: `/chains/${chainId}/levels/checkpoint` })
}

getLevelsSavePoint(params: GetChainId): Promise<any> {
getLevelsSavepoint(params: GetChainId): Promise<any> {
const { chainId, } = params
return this.sendGet({ path: `/chains/${chainId}/levels/savepoint` })
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/rpc/other/EosLoadBalancerRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class EosLoadBalancerRpc extends AbstractEosRpc implements EosRpcSuite {
}

protected post<T>(post: PostI): Promise<T> {
return this.loadBalancer.post({ ...post, basePath: `${this.getRpcNodeUrl()}${Constant.EOS_PREFIX}` })
return this.loadBalancer.post({ ...post, prefix: Constant.EOS_PREFIX })
}

getRpcNodeUrl(): string {
Expand Down
4 changes: 2 additions & 2 deletions src/service/rpc/other/TezosLoadBalancerRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export class TezosLoadBalancerRpc extends AbstractTezosRpc {
}

protected get<T>(get: GetI): Promise<T> {
return this.loadBalancer.get({ ...get, basePath: this.getRpcNodeUrl() })
return this.loadBalancer.get(get)
}

protected post<T>(post: PostI): Promise<T> {
return this.loadBalancer.post({ ...post, basePath: this.getRpcNodeUrl() })
return this.loadBalancer.post(post)
}
}

0 comments on commit 6e976f2

Please sign in to comment.