Skip to content

Commit

Permalink
ALL-3134 Update Tezos methods (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel authored Nov 3, 2023
1 parent 18da3ab commit 02e10cd
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 65 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
}
36 changes: 17 additions & 19 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 All @@ -33,10 +33,6 @@ export interface GetContractsEntrypoints extends GetContract {
entrypoint: string
}

export interface GetBlockHash extends GetBlock {
hash: string
}

export interface SimulateOperation extends RPCSimulateOperationParam, GetBlock {
}

Expand All @@ -49,7 +45,7 @@ export interface GetProtocol {
}

export interface InjectBase {
async?: string
async?: boolean
chain?: string
}

Expand All @@ -58,7 +54,7 @@ export interface InjectOperation extends InjectBase {
}

export interface InjectBlock extends InjectBase {
force?: string
force?: boolean
data: string
operations: { branch: string, data: string }[][]
}
Expand All @@ -70,37 +66,39 @@ export interface InjectProtocol {
interface: string
implementation: string
}[]
async?: string
async?: boolean
}

export interface TezosRpcInterface {
getBlocksHead(params: GetChainId): Promise<any>

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>

getContractEntrypoint(params: GetContractsEntrypoints): Promise<any>

getContractsEntrypoint(params: GetContractsEntrypoints): Promise<any>
getContractManagerKey(params: GetContractBase): Promise<any>

getContractsManagerKey(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 +122,7 @@ export interface TezosRpcInterface {

getLevelsCaboose(params: GetChainId): Promise<any>

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

getErrorsSchema(): Promise<any>

Expand Down
3 changes: 3 additions & 0 deletions src/dto/shared.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ export interface TokenDetails {
*/
cap?: string
}

export type QueryValue = string | number | boolean | string[] | number[] | boolean[]
export type QueryParams = Record<string, QueryValue>
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
2 changes: 1 addition & 1 deletion src/e2e/tatum.faucet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Tatum faucet', () => {
})

describe('valid request', () => {
it('should only stop at balance being above limit', async () => {
it.skip('should only stop at balance being above limit', async () => {
const tatum = await TatumSDK.init<Ethereum>({
network: Network.POLYGON_MUMBAI,
})
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
33 changes: 19 additions & 14 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 All @@ -19,6 +18,7 @@ import {
import { Utils } from '../../../util'
import { GetI } from '../../../dto/GetI'
import { PostI } from '../../../dto/PostI'
import { QueryParams } from '../../../dto'

@Service()
export abstract class AbstractTezosRpc implements TezosRpcInterface {
Expand Down Expand Up @@ -46,7 +46,7 @@ export abstract class AbstractTezosRpc implements TezosRpcInterface {
}: {
path: string
body?: any
queryParams?: Record<string, string | string[] | number>
queryParams?: QueryParams
}): Promise<T> {
const post: PostI = {
path,
Expand All @@ -72,7 +72,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 +116,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 +189,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
Loading

0 comments on commit 02e10cd

Please sign in to comment.