@meow-laika/ton-lite-client 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright
2
+
3
+ (c) 2022-2023 Whales Corp.
4
+ (c) 2023 TrueCarry <truecarry@gmail.com>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ ## ton-lite-client
2
+
3
+ ton-lite-client is a JS library that allows you to get information from TON Blockchain through it's native ADNL protocol.
4
+
5
+ To get servers list, use official urls:
6
+ - Mainnet: https://ton.org/global.config.json
7
+ - Testnet: https://ton.org/testnet-global.config.json
8
+
9
+ Example of getting account state:
10
+ ```typescript
11
+ import { LiteClient, LiteRoundRobinEngine, LiteSingleEngine, LiteEngine } from "ton-lite-client";
12
+ import { Address } from "@ton/core";
13
+
14
+ function intToIP(int: number) {
15
+ var part1 = int & 255;
16
+ var part2 = ((int >> 8) & 255);
17
+ var part3 = ((int >> 16) & 255);
18
+ var part4 = ((int >> 24) & 255);
19
+
20
+ return part4 + "." + part3 + "." + part2 + "." + part1;
21
+ }
22
+
23
+ let server = {
24
+ "ip": 1097649206,
25
+ "port": 29296,
26
+ "id": {
27
+ "@type": "pub.ed25519",
28
+ "key": "p2tSiaeSqX978BxE5zLxuTQM06WVDErf5/15QToxMYA="
29
+ }
30
+ }
31
+
32
+ async function main() {
33
+ const engines: LiteEngine[] = [];
34
+ engines.push(new LiteSingleEngine({
35
+ host: `tcp://${intToIP(server.ip)}:${server.port}`,
36
+ publicKey: Buffer.from(server.id.key, 'base64'),
37
+ }));
38
+ const engine: LiteEngine = new LiteRoundRobinEngine(engines);
39
+ const client = new LiteClient({ engine });
40
+ console.log('get master info')
41
+ const master = await client.getMasterchainInfo()
42
+ console.log('master', master)
43
+
44
+ const address = Address.parse('kQC2sf_Hy34aMM7n9f9_V-ThHDehjH71LWBETy_JrTirPIHa');
45
+ const accountState = await client.getAccountState(address, master.last)
46
+ console.log('Account state:', accountState)
47
+ }
48
+
49
+ main()
50
+ ```
51
+
52
+ By default, LiteClient uses cache for 4 things: blocks, blockHeaders, shards, account states at given block. All caches are LRU maps with capacity of 1000 elements. If your use case needs different caching strategy - you can bring your own map.
53
+
54
+
55
+ For example, you can cap every map at 100 000 elements:
56
+ ```typescript
57
+ const client = new LiteClient({
58
+ engine,
59
+ cacheMap: 100000,
60
+ });
61
+ ```
62
+
63
+ Or you can cache only account states (not recommended, just example):
64
+ ```typescript
65
+ const client = new LiteClient({
66
+ engine, cacheMap: (kind) => {
67
+ if (kind === 'accounts') {
68
+ return new Map()
69
+ }
70
+
71
+ return {
72
+ get(key) { },
73
+ set(key, value) { },
74
+ delete(key: any) { },
75
+ clear() { },
76
+ }
77
+ }
78
+ });
79
+ ```
80
+
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Copyright
3
+ * (c) 2022 Whales Corp.
4
+ * (c) 2023 TrueCarry <truecarry@gmail.com>
5
+ * All Rights Reserved.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ /// <reference types="node" />
11
+ import { Address, Contract, StateInit } from "@ton/core";
12
+ import { LiteEngine } from "./engines/engine";
13
+ import { liteServer_blockHeader, liteServer_transactionId3 } from "./schema";
14
+ import { AllShardsResponse, BlockID, CacheMap, ClientAccountState, QueryArgs } from "./types";
15
+ type MapKind = 'block' | 'header' | 'shard' | 'account';
16
+ export declare class LiteClient {
17
+ #private;
18
+ readonly engine: LiteEngine;
19
+ constructor(opts: {
20
+ engine: LiteEngine;
21
+ batchSize?: number | undefined | null;
22
+ cacheMap?: number | ((mapKind: MapKind) => CacheMap);
23
+ });
24
+ /**
25
+ * Open a contract
26
+ * @param contract
27
+ */
28
+ open<T extends Contract>(contract: T): import("@ton/core").OpenedContract<T>;
29
+ /**
30
+ * Create a new contract provider
31
+ * @param address
32
+ * @param init
33
+ */
34
+ provider(address: Address, init?: StateInit | null): import("@ton/core").ContractProvider;
35
+ sendMessage: (src: Buffer) => Promise<{
36
+ status: number;
37
+ }>;
38
+ getMasterchainInfo: (queryArgs?: QueryArgs) => Promise<import("./schema").liteServer_masterchainInfo>;
39
+ getMasterchainInfoExt: (queryArgs?: QueryArgs) => Promise<import("./schema").liteServer_masterchainInfoExt>;
40
+ getCurrentTime: (queryArgs?: QueryArgs) => Promise<number>;
41
+ getVersion: (queryArgs?: QueryArgs) => Promise<import("./schema").liteServer_version>;
42
+ getConfig: (block: BlockID, queryArgs?: QueryArgs) => Promise<import("@ton/core").MasterchainStateExtra>;
43
+ getAccountState: (src: Address, block: BlockID) => Promise<ClientAccountState>;
44
+ getAccountStateRaw: (src: Address, block: BlockID, queryArgs?: QueryArgs) => Promise<ClientAccountState>;
45
+ getAccountStatePrunned: (src: Address, block: BlockID, queryArgs?: QueryArgs) => Promise<{
46
+ stateHash: Buffer | null;
47
+ raw: Buffer;
48
+ proof: Buffer;
49
+ block: import("./schema").tonNode_blockIdExt;
50
+ shardBlock: import("./schema").tonNode_blockIdExt;
51
+ shardProof: Buffer;
52
+ }>;
53
+ getAccountTransaction: (src: Address, lt: string, block: BlockID, queryArgs?: QueryArgs) => Promise<import("./schema").liteServer_transactionInfo>;
54
+ getAccountTransactions: (src: Address, lt: string, hash: Buffer, count: number, queryArgs?: QueryArgs) => Promise<{
55
+ ids: import("./schema").tonNode_blockIdExt[];
56
+ transactions: Buffer;
57
+ }>;
58
+ runMethod: (src: Address, method: string, params: Buffer, block: BlockID, queryArgs?: QueryArgs) => Promise<{
59
+ exitCode: number;
60
+ result: string | null;
61
+ block: {
62
+ seqno: number;
63
+ shard: string;
64
+ workchain: number;
65
+ rootHash: Buffer;
66
+ fileHash: Buffer;
67
+ };
68
+ shardBlock: {
69
+ seqno: number;
70
+ shard: string;
71
+ workchain: number;
72
+ rootHash: Buffer;
73
+ fileHash: Buffer;
74
+ };
75
+ }>;
76
+ lookupBlockByID: (block: {
77
+ seqno: number;
78
+ shard: string;
79
+ workchain: number;
80
+ }) => Promise<liteServer_blockHeader>;
81
+ lookupBlockByUtime: (block: {
82
+ shard: string;
83
+ workchain: number;
84
+ utime: number;
85
+ }) => Promise<liteServer_blockHeader>;
86
+ lookupBlockByLt: (block: {
87
+ shard: string;
88
+ workchain: number;
89
+ lt: bigint;
90
+ }) => Promise<liteServer_blockHeader>;
91
+ getBlockHeader: (block: BlockID) => Promise<liteServer_blockHeader>;
92
+ getAllShardsInfo: (block: BlockID) => Promise<AllShardsResponse>;
93
+ listBlockTransactions: (block: BlockID, args?: {
94
+ mode: number;
95
+ count: number;
96
+ after?: liteServer_transactionId3 | null | undefined;
97
+ wantProof?: boolean;
98
+ }, queryArgs?: QueryArgs) => Promise<import("./schema").liteServer_blockTransactions>;
99
+ listBlockTransactionsExt: (block: BlockID, args?: {
100
+ mode: number;
101
+ count: number;
102
+ after?: liteServer_transactionId3 | null | undefined;
103
+ wantProof?: boolean;
104
+ }, queryArgs?: QueryArgs) => Promise<import("./schema").liteServer_blockTransactionsExt>;
105
+ getFullBlock: (seqno: number) => Promise<{
106
+ shards: {
107
+ rootHash: Buffer;
108
+ fileHash: Buffer;
109
+ transactions: {
110
+ hash: Buffer;
111
+ lt: string;
112
+ account: Buffer;
113
+ }[];
114
+ workchain: number;
115
+ seqno: number;
116
+ shard: string;
117
+ }[];
118
+ }>;
119
+ getLibraries: (hashes: Buffer[], queryArgs?: QueryArgs) => Promise<import("./schema").liteServer_libraryResult>;
120
+ }
121
+ export {};