Skip to content

Commit

Permalink
ALL-8276 - Add Ton API
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel committed Aug 6, 2024
1 parent 7df5678 commit d5a5974
Show file tree
Hide file tree
Showing 18 changed files with 501 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/dto/rpc/ton/TonRpcSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServiceStatus | { error: string }>;
Expand Down Expand Up @@ -539,4 +556,70 @@ export interface TonRpcSuite {
getWalletsByPublicKey(publicKey: string): Promise<Accounts | { error: string }>;

getAccountSeqno(accountId: string): Promise<Seqno | { error: string }>;

// Ton Http API

// Accounts
getAddressInformation(address: string): Promise<TonResponse>;

getExtendedAddressInformation(address: string): Promise<TonResponse>;

getWalletInformation(address: string): Promise<TonResponse>;

getTransactions(params: GetTransactions): Promise<TonResponse>;

getAddressBalance(address: string): Promise<TonResponse>;

getAddressState(address: string): Promise<TonResponse>;

packAddress(address: string): Promise<TonResponse>;

unpackAddress(address: string): Promise<TonResponse>;

getTokenMetadata(token: string): Promise<TonResponse>;

detectAddress(address: string): Promise<TonResponse>;

// Blocks
getMasterchainInfo(): Promise<TonResponse>;

getMasterchainBlockSignatures(seqno: number): Promise<TonResponse>;

getShardBlockProof(params: GetShardBlockProof): Promise<TonResponse>;

getConsensusBlock(): Promise<TonResponse>

lookupBlock(params: LookupBlock): Promise<TonResponse>;

shards(seqno: number): Promise<TonResponse>;

getBlockTransactions(params: GetBlockTransactions): Promise<TonResponse>;

getBlockTransactionsExt(params: GetBlockTransactionsExt): Promise<TonResponse>;

getBlockHeader(params: GetBlockHeader): Promise<TonResponse>;

getOutMsqQueueSizes(): Promise<TonResponse>;

// Transactions
tryLocateTx(params: TryLocateTx): Promise<TonResponse>;

tryLocateResultTx(params: TryLocateTx): Promise<TonResponse>;

tryLocateSourceTx(params: TryLocateTx): Promise<TonResponse>;

// Run method
runGetMethod(params: Body_run_get_method_runGetMethod_post): Promise<TonResponse>;

// Send
sendBoc(params: Body_send_boc_sendBoc_post): Promise<TonResponse>;

sendBocReturnHash(params: Body_send_boc_return_hash_sendBocReturnHash_post): Promise<TonResponse>;

sendQuery(params: Body_send_query_sendQuery_post): Promise<TonResponse>;

estimateFee(params: Body_estimate_fee_estimateFee_post): Promise<TonResponse>;

// Json Rpc
jsonRPC(params: TonRequestJsonRPC): Promise<DeprecatedTonResponseJsonRPC>
}
26 changes: 26 additions & 0 deletions src/dto/rpc/ton/models/Body_estimate_fee_estimateFee_post.ts
Original file line number Diff line number Diff line change
@@ -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;
};
22 changes: 22 additions & 0 deletions src/dto/rpc/ton/models/Body_run_get_method_runGetMethod_post.ts
Original file line number Diff line number Diff line change
@@ -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<Array<any>>;
/**
* Seqno of masterchain block at which moment the Get Method is to be executed
*/
seqno?: number;
};
Original file line number Diff line number Diff line change
@@ -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;
};
10 changes: 10 additions & 0 deletions src/dto/rpc/ton/models/Body_send_boc_sendBoc_post.ts
Original file line number Diff line number Diff line change
@@ -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;
};
22 changes: 22 additions & 0 deletions src/dto/rpc/ton/models/Body_send_query_sendQuery_post.ts
Original file line number Diff line number Diff line change
@@ -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;
};
12 changes: 12 additions & 0 deletions src/dto/rpc/ton/models/DeprecatedTonResponseJsonRPC.ts
Original file line number Diff line number Diff line change
@@ -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;
};
7 changes: 7 additions & 0 deletions src/dto/rpc/ton/models/GetBlockHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface GetBlockHeader {
workchain: number;
shard: number;
seqno: number;
root_hash?: string;
file_hash?: string;
}
10 changes: 10 additions & 0 deletions src/dto/rpc/ton/models/GetBlockTransactions.ts
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 10 additions & 0 deletions src/dto/rpc/ton/models/GetBlockTransactionsExt.ts
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 6 additions & 0 deletions src/dto/rpc/ton/models/GetShardBlockProof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface GetShardBlockProof {
workchain: number
shard: number
seqno: number
from_seqno?: number
}
8 changes: 8 additions & 0 deletions src/dto/rpc/ton/models/GetTransactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface GetTransactions {
address: string
limit?: number
It?: number
hash?: string
to_It?: number
archival?: boolean
}
7 changes: 7 additions & 0 deletions src/dto/rpc/ton/models/LookupBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface LookupBlock {
workchain: number
shard: number
seqno?: number
It?: number
unixtime?: number
}
10 changes: 10 additions & 0 deletions src/dto/rpc/ton/models/TonRequestJsonRPC.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type TonRequestJsonRPC = {
method: string;
params?: any;
id?: string;
jsonrpc?: string;
};
10 changes: 10 additions & 0 deletions src/dto/rpc/ton/models/TonResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type TonResponse = {
ok: boolean;
result?: string;
error?: string;
code?: number;
};
5 changes: 5 additions & 0 deletions src/dto/rpc/ton/models/TryLocateTx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface TryLocateTx {
source: string;
destination: string;
created_lt: number;
}
22 changes: 22 additions & 0 deletions src/e2e/rpc/other/tatum.rpc.ton.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ const getTonRpc = async (testnet: boolean) => {
})
}

const getTonHttpApi = async (testnet: boolean) => {
return await TatumSDK.init<Ton>({
...e2eUtil.initConfig(testnet ? Network.TON_TESTNET : Network.TON), rpc: {
nodes: [
{
url: testnet ? 'https://toncenter.com' : 'https://toncenter.com',
type: RpcNodeType.NORMAL,
},
],
},
})

}

describe('Ton', () => {
[true, false].forEach(testnet => {

Check failure on line 32 in src/e2e/rpc/other/tatum.rpc.ton.spec.ts

View workflow job for this annotation

GitHub Actions / TEST REPORT

src/e2e/rpc/other/tatum.rpc.ton.spec.ts ► Ton › Testnet ► getMasterchainInfo

Failed test found in: reports/jest-junit.xml Error: Error: thrown: "{\"ok\": false, \"error\": \"API key does not exist\",\"code\":401}"
Raw output
Error: thrown: "{\"ok\": false, \"error\": \"API key does not exist\",\"code\":401}"
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/other/tatum.rpc.ton.spec.ts:49:7
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/other/tatum.rpc.ton.spec.ts:34:5
    at Array.forEach (<anonymous>)
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/other/tatum.rpc.ton.spec.ts:33:18
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at Object.<anonymous> (/home/runner/work/tatum-js/tatum-js/src/e2e/rpc/other/tatum.rpc.ton.spec.ts:32:1)
    at Runtime._execModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:1439:24)
    at Runtime._loadModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:1022:12)
    at Runtime.requireModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:882:12)
    at jestAdapter (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:77:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runTestInternal (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/testWorker.js:106:12)

Check failure on line 32 in src/e2e/rpc/other/tatum.rpc.ton.spec.ts

View workflow job for this annotation

GitHub Actions / TEST REPORT

src/e2e/rpc/other/tatum.rpc.ton.spec.ts ► Ton › Mainnet ► getMasterchainInfo

Failed test found in: reports/jest-junit.xml Error: Error: thrown: "{\"ok\": false, \"error\": \"API key does not exist\",\"code\":401}"
Raw output
Error: thrown: "{\"ok\": false, \"error\": \"API key does not exist\",\"code\":401}"
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/other/tatum.rpc.ton.spec.ts:49:7
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/other/tatum.rpc.ton.spec.ts:34:5
    at Array.forEach (<anonymous>)
    at /home/runner/work/tatum-js/tatum-js/src/e2e/rpc/other/tatum.rpc.ton.spec.ts:33:18
    at _dispatchDescribe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:91:26)
    at describe (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/index.js:55:5)
    at Object.<anonymous> (/home/runner/work/tatum-js/tatum-js/src/e2e/rpc/other/tatum.rpc.ton.spec.ts:32:1)
    at Runtime._execModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:1439:24)
    at Runtime._loadModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:1022:12)
    at Runtime.requireModule (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runtime/build/index.js:882:12)
    at jestAdapter (/home/runner/work/tatum-js/tatum-js/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:77:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runTestInternal (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/tatum-js/tatum-js/node_modules/jest-runner/build/testWorker.js:106:12)
describe(testnet ? 'Testnet' : 'Mainnet', () => {
Expand All @@ -30,6 +44,14 @@ describe('Ton', () => {
await ton.destroy()
expect(result).toBeDefined()
})

it('getMasterchainInfo', async () => {
const ton = await getTonHttpApi(testnet)
const result = await ton.rpc.getMasterchainInfo()
console.log(result)
await ton.destroy()
expect(result).toBeDefined()
})
})
})
})
Loading

0 comments on commit d5a5974

Please sign in to comment.