diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ec17471d..c655a74b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [4.2.38] - 2024.7.23 + +### Added + +- Support for Ton basic api + ## [4.2.37] - 2024.7.23 ### Added diff --git a/package.json b/package.json index be9529c9b..e9b01fa99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tatumio/tatum", - "version": "4.2.37", + "version": "4.2.38", "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 a2bf5933a..2a530e611 100644 --- a/src/dto/Network.ts +++ b/src/dto/Network.ts @@ -57,7 +57,7 @@ export enum Network { BITCOIN_ELECTRS = 'bitcoin-mainnet-electrs', CASPER = 'casper-mainnet', TON = 'ton-mainnet', - ZK_SYNC = 'zks-mainnet', + ZK_SYNC = 'zksync-mainnet', // Testnets @@ -113,7 +113,7 @@ export enum Network { BITCOIN_ELECTRS_TESTNET = 'bitcoin-testnet-electrs', ROSTRUM_TESTNET = 'bch-testnet-rostrum', TON_TESTNET = 'ton-testnet', - ZK_SYNC_TESTNET = 'zks-testnet', + ZK_SYNC_TESTNET = 'zksync-testnet', } export const EVM_BASED_NETWORKS = [ @@ -299,7 +299,6 @@ export const LOAD_BALANCER_NETWORKS = [ ...IOTA_LOAD_BALANCER_NETWORKS, ...BITCOIN_ELECTRS_NETWORKS, ...CASPER_NETWORKS, - ...TON_NETWORKS, ] export const EVM_ARCHIVE_NON_ARCHIVE_LOAD_BALANCER_NETWORKS = [ diff --git a/src/dto/rpc/ton/TonRpcSuite.ts b/src/dto/rpc/ton/TonRpcSuite.ts index 956770cc5..c351cd263 100644 --- a/src/dto/rpc/ton/TonRpcSuite.ts +++ b/src/dto/rpc/ton/TonRpcSuite.ts @@ -54,6 +54,23 @@ import type { PoolInfo } from './models/PoolInfo'; import type { StorageProvider } from './models/StorageProvider'; import type { Seqno } from './models/Seqno'; import { NftItem } from './models/NftItem' +import { TonResponse } from './models/TonResponse' +import { GetTransactions } from './models/GetTransactions' +import { GetShardBlockProof } from './models/GetShardBlockProof' +import { LookupBlock } from './models/LookupBlock' +import { GetBlockTransactions } from './models/GetBlockTransactions' +import { GetBlockTransactionsExt } from './models/GetBlockTransactionsExt' +import { GetBlockHeader } from './models/GetBlockHeader' +import { TryLocateTx } from './models/TryLocateTx' +import { Body_run_get_method_runGetMethod_post } from './models/Body_run_get_method_runGetMethod_post' +import { Body_send_boc_sendBoc_post } from './models/Body_send_boc_sendBoc_post' +import { + Body_send_boc_return_hash_sendBocReturnHash_post +} from './models/Body_send_boc_return_hash_sendBocReturnHash_post' +import { Body_send_query_sendQuery_post } from './models/Body_send_query_sendQuery_post' +import { Body_estimate_fee_estimateFee_post } from './models/Body_estimate_fee_estimateFee_post' +import { TonRequestJsonRPC } from './models/TonRequestJsonRPC' +import { DeprecatedTonResponseJsonRPC } from './models/DeprecatedTonResponseJsonRPC' export interface TonRpcSuite { status(): Promise; @@ -539,4 +556,70 @@ export interface TonRpcSuite { getWalletsByPublicKey(publicKey: string): Promise; getAccountSeqno(accountId: string): Promise; + + // Ton Http API + + // Accounts + getAddressInformation(address: string): Promise; + + getExtendedAddressInformation(address: string): Promise; + + getWalletInformation(address: string): Promise; + + getTransactions(params: GetTransactions): Promise; + + getAddressBalance(address: string): Promise; + + getAddressState(address: string): Promise; + + packAddress(address: string): Promise; + + unpackAddress(address: string): Promise; + + getTokenMetadata(token: string): Promise; + + detectAddress(address: string): Promise; + + // Blocks + getMasterchainInfo(): Promise; + + getMasterchainBlockSignatures(seqno: number): Promise; + + getShardBlockProof(params: GetShardBlockProof): Promise; + + getConsensusBlock(): Promise + + lookupBlock(params: LookupBlock): Promise; + + shards(seqno: number): Promise; + + getBlockTransactions(params: GetBlockTransactions): Promise; + + getBlockTransactionsExt(params: GetBlockTransactionsExt): Promise; + + getBlockHeader(params: GetBlockHeader): Promise; + + getOutMsqQueueSizes(): Promise; + + // Transactions + tryLocateTx(params: TryLocateTx): Promise; + + tryLocateResultTx(params: TryLocateTx): Promise; + + tryLocateSourceTx(params: TryLocateTx): Promise; + + // Run method + runGetMethod(params: Body_run_get_method_runGetMethod_post): Promise; + + // Send + sendBoc(params: Body_send_boc_sendBoc_post): Promise; + + sendBocReturnHash(params: Body_send_boc_return_hash_sendBocReturnHash_post): Promise; + + sendQuery(params: Body_send_query_sendQuery_post): Promise; + + estimateFee(params: Body_estimate_fee_estimateFee_post): Promise; + + // Json Rpc + jsonRPC(params: TonRequestJsonRPC): Promise } diff --git a/src/dto/rpc/ton/models/Body_estimate_fee_estimateFee_post.ts b/src/dto/rpc/ton/models/Body_estimate_fee_estimateFee_post.ts new file mode 100644 index 000000000..7e1f108c3 --- /dev/null +++ b/src/dto/rpc/ton/models/Body_estimate_fee_estimateFee_post.ts @@ -0,0 +1,26 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Body_estimate_fee_estimateFee_post = { + /** + * Address in any format + */ + address: string; + /** + * b64-encoded cell with message body + */ + body: string; + /** + * b64-encoded cell with init-code + */ + init_code?: string; + /** + * b64-encoded cell with init-data + */ + init_data?: string; + /** + * If true during test query processing assume that all chksig operations return True + */ + ignore_chksig?: boolean; +}; diff --git a/src/dto/rpc/ton/models/Body_run_get_method_runGetMethod_post.ts b/src/dto/rpc/ton/models/Body_run_get_method_runGetMethod_post.ts new file mode 100644 index 000000000..3299d15e1 --- /dev/null +++ b/src/dto/rpc/ton/models/Body_run_get_method_runGetMethod_post.ts @@ -0,0 +1,22 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Body_run_get_method_runGetMethod_post = { + /** + * Contract address + */ + address: string; + /** + * Method name or method id + */ + method: (string | number); + /** + * Array of stack elements: `[['num',3], ['cell', cell_object], ['slice', slice_object]]` + */ + stack: Array>; + /** + * Seqno of masterchain block at which moment the Get Method is to be executed + */ + seqno?: number; +}; diff --git a/src/dto/rpc/ton/models/Body_send_boc_return_hash_sendBocReturnHash_post.ts b/src/dto/rpc/ton/models/Body_send_boc_return_hash_sendBocReturnHash_post.ts new file mode 100644 index 000000000..26d6c9472 --- /dev/null +++ b/src/dto/rpc/ton/models/Body_send_boc_return_hash_sendBocReturnHash_post.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Body_send_boc_return_hash_sendBocReturnHash_post = { + /** + * b64 encoded bag of cells + */ + boc: string; +}; diff --git a/src/dto/rpc/ton/models/Body_send_boc_sendBoc_post.ts b/src/dto/rpc/ton/models/Body_send_boc_sendBoc_post.ts new file mode 100644 index 000000000..f7de174cc --- /dev/null +++ b/src/dto/rpc/ton/models/Body_send_boc_sendBoc_post.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Body_send_boc_sendBoc_post = { + /** + * b64 encoded bag of cells + */ + boc: string; +}; diff --git a/src/dto/rpc/ton/models/Body_send_query_sendQuery_post.ts b/src/dto/rpc/ton/models/Body_send_query_sendQuery_post.ts new file mode 100644 index 000000000..c9b747f9e --- /dev/null +++ b/src/dto/rpc/ton/models/Body_send_query_sendQuery_post.ts @@ -0,0 +1,22 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type Body_send_query_sendQuery_post = { + /** + * Address in any format + */ + address: string; + /** + * b64-encoded boc-serialized cell with message body + */ + body: string; + /** + * b64-encoded boc-serialized cell with init-code + */ + init_code?: string; + /** + * b64-encoded boc-serialized cell with init-data + */ + init_data?: string; +}; diff --git a/src/dto/rpc/ton/models/DeprecatedTonResponseJsonRPC.ts b/src/dto/rpc/ton/models/DeprecatedTonResponseJsonRPC.ts new file mode 100644 index 000000000..3ba5fe1c1 --- /dev/null +++ b/src/dto/rpc/ton/models/DeprecatedTonResponseJsonRPC.ts @@ -0,0 +1,12 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type DeprecatedTonResponseJsonRPC = { + ok: boolean; + result?: any; + error?: string; + code?: number; + id: string; + jsonrpc?: string; +}; diff --git a/src/dto/rpc/ton/models/GetBlockHeader.ts b/src/dto/rpc/ton/models/GetBlockHeader.ts new file mode 100644 index 000000000..3ef368c64 --- /dev/null +++ b/src/dto/rpc/ton/models/GetBlockHeader.ts @@ -0,0 +1,7 @@ +export interface GetBlockHeader { + workchain: number; + shard: number; + seqno: number; + root_hash?: string; + file_hash?: string; +} diff --git a/src/dto/rpc/ton/models/GetBlockTransactions.ts b/src/dto/rpc/ton/models/GetBlockTransactions.ts new file mode 100644 index 000000000..eef8d7d7e --- /dev/null +++ b/src/dto/rpc/ton/models/GetBlockTransactions.ts @@ -0,0 +1,10 @@ +export interface GetBlockTransactions { + workchain: number; + shard: number; + seqno: number; + root_hash?: string; + file_hash?: string; + after_lt?: number; + after_hash?: string; + count?: number; +} diff --git a/src/dto/rpc/ton/models/GetBlockTransactionsExt.ts b/src/dto/rpc/ton/models/GetBlockTransactionsExt.ts new file mode 100644 index 000000000..7840ec235 --- /dev/null +++ b/src/dto/rpc/ton/models/GetBlockTransactionsExt.ts @@ -0,0 +1,10 @@ +export interface GetBlockTransactionsExt { + workchain: number; + shard: number; + seqno: number; + root_hash?: string; + file_hash?: string; + after_lt?: number; + after_hash?: string; + count?: number; +} diff --git a/src/dto/rpc/ton/models/GetShardBlockProof.ts b/src/dto/rpc/ton/models/GetShardBlockProof.ts new file mode 100644 index 000000000..05522636b --- /dev/null +++ b/src/dto/rpc/ton/models/GetShardBlockProof.ts @@ -0,0 +1,6 @@ +export interface GetShardBlockProof { + workchain: number + shard: number + seqno: number + from_seqno?: number +} diff --git a/src/dto/rpc/ton/models/GetTransactions.ts b/src/dto/rpc/ton/models/GetTransactions.ts new file mode 100644 index 000000000..10e3f45e4 --- /dev/null +++ b/src/dto/rpc/ton/models/GetTransactions.ts @@ -0,0 +1,8 @@ +export interface GetTransactions { + address: string + limit?: number + It?: number + hash?: string + to_It?: number + archival?: boolean +} diff --git a/src/dto/rpc/ton/models/LookupBlock.ts b/src/dto/rpc/ton/models/LookupBlock.ts new file mode 100644 index 000000000..e00059a71 --- /dev/null +++ b/src/dto/rpc/ton/models/LookupBlock.ts @@ -0,0 +1,7 @@ +export interface LookupBlock { + workchain: number + shard: number + seqno?: number + It?: number + unixtime?: number +} diff --git a/src/dto/rpc/ton/models/TonRequestJsonRPC.ts b/src/dto/rpc/ton/models/TonRequestJsonRPC.ts new file mode 100644 index 000000000..0d6c0542b --- /dev/null +++ b/src/dto/rpc/ton/models/TonRequestJsonRPC.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type TonRequestJsonRPC = { + method: string; + params?: any; + id?: string; + jsonrpc?: string; +}; diff --git a/src/dto/rpc/ton/models/TonResponse.ts b/src/dto/rpc/ton/models/TonResponse.ts new file mode 100644 index 000000000..803aed42b --- /dev/null +++ b/src/dto/rpc/ton/models/TonResponse.ts @@ -0,0 +1,10 @@ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ + +export type TonResponse = { + ok: boolean; + result?: string; + error?: string; + code?: number; +}; diff --git a/src/dto/rpc/ton/models/TryLocateTx.ts b/src/dto/rpc/ton/models/TryLocateTx.ts new file mode 100644 index 000000000..c88356bfc --- /dev/null +++ b/src/dto/rpc/ton/models/TryLocateTx.ts @@ -0,0 +1,5 @@ +export interface TryLocateTx { + source: string; + destination: string; + created_lt: number; +} diff --git a/src/e2e/rpc/other/tatum.rpc.ton.spec.ts b/src/e2e/rpc/other/tatum.rpc.ton.spec.ts index 6c57ea6ed..435ef5ffb 100644 --- a/src/e2e/rpc/other/tatum.rpc.ton.spec.ts +++ b/src/e2e/rpc/other/tatum.rpc.ton.spec.ts @@ -1,32 +1,22 @@ -import { Network, RpcNodeType, TatumSDK, Ton } from '../../../service' +import { Network, TatumSDK, Ton } from '../../../service' import { e2eUtil } from '../../e2e.util' -const getTonRpc = async (testnet: boolean) => { - return await TatumSDK.init({ - ...e2eUtil.initConfig(testnet ? Network.TON_TESTNET : Network.TON), rpc: { - nodes: [ - { - url: testnet ? 'https://testnet.tonapi.io' : 'https://tonapi.io', - type: RpcNodeType.NORMAL, - }, - ], - }, - }) +const getTonClient = async (testnet: boolean) => { + return await TatumSDK.init(e2eUtil.initConfig(testnet ? Network.TON_TESTNET : Network.TON)) } describe('Ton', () => { [true, false].forEach(testnet => { describe(testnet ? 'Testnet' : 'Mainnet', () => { it('status', async () => { - const ton = await getTonRpc(testnet) - const result = await ton.rpc.status() + const ton = await getTonClient(testnet) + const result = await ton.rpc.getBlockchainMasterchainHead() await ton.destroy() expect(result).toBeDefined() }) - - it('getBlockchainValidators', async () => { - const ton = await getTonRpc(testnet) - const result = await ton.rpc.getBlockchainValidators() + it('getMasterchainInfo', async () => { + const ton = await getTonClient(testnet) + const result = await ton.rpc.getMasterchainInfo() await ton.destroy() expect(result).toBeDefined() }) diff --git a/src/service/rpc/other/AbstractTonRpc.ts b/src/service/rpc/other/AbstractTonRpc.ts index 060d9ba1f..89d4b08b5 100644 --- a/src/service/rpc/other/AbstractTonRpc.ts +++ b/src/service/rpc/other/AbstractTonRpc.ts @@ -60,6 +60,25 @@ import { BlockchainAccountInspect } from '../../../dto/rpc/ton/models/Blockchain import { Account } from '../../../dto/rpc/ton/models/Account' import { DomainNames } from '../../../dto/rpc/ton/models/DomainNames' import { JettonsBalances } from '../../../dto/rpc/ton/models/JettonsBalances' +import { TonResponse } from '../../../dto/rpc/ton/models/TonResponse' +import { GetTransactions } from '../../../dto/rpc/ton/models/GetTransactions' +import { GetShardBlockProof } from '../../../dto/rpc/ton/models/GetShardBlockProof' +import { LookupBlock } from '../../../dto/rpc/ton/models/LookupBlock' +import { GetBlockTransactions } from '../../../dto/rpc/ton/models/GetBlockTransactions' +import { GetBlockTransactionsExt } from '../../../dto/rpc/ton/models/GetBlockTransactionsExt' +import { GetBlockHeader } from '../../../dto/rpc/ton/models/GetBlockHeader' +import { TryLocateTx } from '../../../dto/rpc/ton/models/TryLocateTx' +import { + Body_run_get_method_runGetMethod_post +} from '../../../dto/rpc/ton/models/Body_run_get_method_runGetMethod_post' +import { Body_send_boc_sendBoc_post } from '../../../dto/rpc/ton/models/Body_send_boc_sendBoc_post' +import { + Body_send_boc_return_hash_sendBocReturnHash_post +} from '../../../dto/rpc/ton/models/Body_send_boc_return_hash_sendBocReturnHash_post' +import { Body_send_query_sendQuery_post } from '../../../dto/rpc/ton/models/Body_send_query_sendQuery_post' +import { Body_estimate_fee_estimateFee_post } from '../../../dto/rpc/ton/models/Body_estimate_fee_estimateFee_post' +import { TonRequestJsonRPC } from '../../../dto/rpc/ton/models/TonRequestJsonRPC' +import { DeprecatedTonResponseJsonRPC } from '../../../dto/rpc/ton/models/DeprecatedTonResponseJsonRPC' interface RequestI { path: string @@ -1041,4 +1060,206 @@ export abstract class AbstractTonRpc implements TonRpcSuite { queryParams: { start_date: startDate, end_date: endDate }, }); } + + // Ton Http API + + getAddressInformation(address: string): Promise { + return this.sendGet({ + path: `/getAddressInformation`, + queryParams: { address }, + }) + } + + getExtendedAddressInformation(address: string): Promise { + return this.sendGet({ + path: `/getExtendedAddressInformation`, + queryParams: { address }, + }) + } + + getWalletInformation(address: string): Promise { + return this.sendGet({ + path: `/getWalletInformation`, + queryParams: { address }, + }) + } + + getTransactions(params: GetTransactions): Promise { + return this.sendGet({ + path: `/getTransactions`, + queryParams: params as unknown as QueryParams, + }) + } + + getAddressBalance(address: string): Promise { + return this.sendGet({ + path: `/getAddressBalance`, + queryParams: { address }, + }) + } + + getAddressState(address: string): Promise { + return this.sendGet({ + path: `/getAddressState`, + queryParams: { address }, + }) + } + + packAddress(address: string): Promise { + return this.sendGet({ + path: `/packAddress`, + queryParams: { address }, + }) + } + + unpackAddress(address: string): Promise { + return this.sendGet({ + path: `/unpackAddress`, + queryParams: { address }, + }) + } + + getTokenMetadata(address: string): Promise { + return this.sendGet({ + path: `/getTokenMetadata`, + queryParams: { address }, + }) + } + + detectAddress(address: string): Promise { + return this.sendGet({ + path: `/detectAddress`, + queryParams: { address }, + }) + } + + getMasterchainInfo(): Promise { + return this.sendGet({ + path: `/getMasterchainInfo`, + }) + } + + getMasterchainBlockSignatures(seqno: number): Promise { + return this.sendGet({ + path: `/getMasterchainBlockSignatures`, + queryParams: { seqno }, + }) + } + + getShardBlockProof(params: GetShardBlockProof): Promise { + return this.sendGet({ + path: `/getShardBlockProof`, + queryParams: params as unknown as QueryParams, + }) + } + + getConsensusBlock(): Promise { + return this.sendGet({ + path: `/getConsensusBlock`, + }) + } + + lookupBlock(params: LookupBlock): Promise { + return this.sendGet({ + path: `/lookupBlock`, + queryParams: params as unknown as QueryParams, + }) + } + + shards(seqno: number): Promise { + return this.sendGet({ + path: `/shards`, + queryParams: { seqno }, + }) + } + + getBlockTransactions(params: GetBlockTransactions): Promise { + return this.sendGet({ + path: `/getBlockTransactions`, + queryParams: params as unknown as QueryParams, + }) + } + + getBlockTransactionsExt(params: GetBlockTransactionsExt): Promise { + return this.sendGet({ + path: `/getBlockTransactionsExt`, + queryParams: params as unknown as QueryParams, + }) + } + + getBlockHeader(params: GetBlockHeader): Promise { + return this.sendGet({ + path: `/getBlockHeader`, + queryParams: params as unknown as QueryParams, + }) + } + + getOutMsqQueueSizes(): Promise { + return this.sendGet({ + path: `/getOutMsqQueueSizes`, + }) + } + + tryLocateTx(params: TryLocateTx): Promise { + return this.sendGet({ + path: `/tryLocateTx`, + queryParams: params as unknown as QueryParams, + }) + } + + tryLocateResultTx(params: TryLocateTx): Promise { + return this.sendGet({ + path: `/tryLocateResultTx`, + queryParams: params as unknown as QueryParams, + }) + } + + tryLocateSourceTx(params: TryLocateTx): Promise { + return this.sendGet({ + path: `/tryLocateSourceTx`, + queryParams: params as unknown as QueryParams, + }) + } + + runGetMethod(params: Body_run_get_method_runGetMethod_post): Promise { + return this.sendPost({ + path: `/runGetMethod`, + body: params, + }) + } + + sendBoc(params: Body_send_boc_sendBoc_post): Promise { + return this.sendPost({ + path: `/sendBoc`, + body: params, + }) + } + + sendBocReturnHash(params: Body_send_boc_return_hash_sendBocReturnHash_post): Promise { + return this.sendPost({ + path: `/sendBocReturnHash`, + body: params, + }) + } + + sendQuery(params: Body_send_query_sendQuery_post): Promise { + return this.sendPost({ + path: `/sendQuery`, + body: params, + }) + } + + estimateFee(params: Body_estimate_fee_estimateFee_post): Promise { + return this.sendPost({ + path: `/estimateFee`, + body: params, + }) + } + + jsonRPC(params: TonRequestJsonRPC): Promise { + return this.sendPost({ + path: `/jsonRPC`, + body: params, + }) + } }