wan-ton-sdk 0.0.7 → 0.0.9
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/dist/Bridge.compile.d.ts +2 -0
- package/dist/Bridge.compile.js +9 -0
- package/dist/Bridge.d.ts +208 -0
- package/dist/Bridge.js +468 -0
- package/dist/Fake.compile.d.ts +2 -0
- package/dist/Fake.compile.js +9 -0
- package/dist/GroupApprove.compile.d.ts +2 -0
- package/dist/GroupApprove.compile.js +7 -0
- package/dist/GroupApprove.d.ts +124 -0
- package/dist/GroupApprove.js +181 -0
- package/dist/JettonMinter.compile.d.ts +2 -0
- package/dist/JettonMinter.compile.js +6 -0
- package/dist/JettonMinter.d.ts +45 -0
- package/dist/JettonMinter.js +124 -0
- package/dist/JettonWallet.compile.d.ts +2 -0
- package/dist/JettonWallet.compile.js +6 -0
- package/dist/JettonWallet.d.ts +26 -0
- package/dist/JettonWallet.js +103 -0
- package/dist/Signature.compile.d.ts +2 -0
- package/dist/Signature.compile.js +7 -0
- package/dist/Signature.d.ts +44 -0
- package/dist/Signature.js +106 -0
- package/dist/address.compile.d.ts +2 -0
- package/dist/address.compile.js +9 -0
- package/dist/client/client-interface.d.ts +35 -0
- package/dist/client/client-interface.js +9 -0
- package/dist/client/client.d.ts +22 -0
- package/dist/client/client.js +86 -0
- package/dist/client/tonapi-client.d.ts +4630 -0
- package/dist/client/tonapi-client.js +5376 -0
- package/dist/code/encode-decode.d.ts +132 -0
- package/dist/code/encode-decode.js +645 -0
- package/dist/code/userLock.d.ts +39 -0
- package/dist/code/userLock.js +284 -0
- package/dist/common.d.ts +9 -0
- package/dist/common.js +45 -0
- package/dist/config/config-ex.d.ts +7 -0
- package/dist/config/config-ex.js +73 -0
- package/dist/const/const-value.d.ts +21 -0
- package/dist/const/const-value.js +26 -0
- package/dist/contractAccess/bridgeAccess.d.ts +10 -0
- package/dist/contractAccess/bridgeAccess.js +55 -0
- package/dist/contractAccess/groupApproveAccess.d.ts +10 -0
- package/dist/contractAccess/groupApproveAccess.js +54 -0
- package/dist/db/Db.d.ts +24 -0
- package/dist/db/Db.js +739 -0
- package/dist/db/DbAccess.d.ts +24 -0
- package/dist/db/DbAccess.js +211 -0
- package/dist/db/common.d.ts +5 -0
- package/dist/db/common.js +114 -0
- package/dist/event/getEvents.d.ts +17 -0
- package/dist/event/getEvents.js +387 -0
- package/dist/example/db/createDb-ex.d.ts +1 -0
- package/{example/createDb-ex.ts → dist/example/db/createDb-ex.js} +3 -4
- package/dist/example/db/dbFeedTrans-ex.d.ts +1 -0
- package/{example/dbFeedTrans-ex.ts → dist/example/db/dbFeedTrans-ex.js} +9 -11
- package/dist/example/event/getAllEvents-ex.d.ts +1 -0
- package/dist/example/event/getAllEvents-ex.js +70 -0
- package/dist/example/event/getEventByHash-ex.d.ts +1 -0
- package/{example/getEventByHash-ex.ts → dist/example/event/getEventByHash-ex.js} +21 -25
- package/dist/example/event/getEventsByRange-ex.d.ts +1 -0
- package/dist/example/event/getEventsByRange-ex.js +58 -0
- package/dist/example/getAllTrans.d.ts +1 -0
- package/dist/example/getAllTrans.js +30 -0
- package/dist/example/jetton/getJettonInfo-ex.d.ts +1 -0
- package/dist/example/jetton/getJettonInfo-ex.js +32 -0
- package/dist/example/lock-release/smgRelease-ex.d.ts +1 -0
- package/dist/example/lock-release/smgRelease-ex.js +134 -0
- package/dist/example/lock-release/userLock-ex.d.ts +1 -0
- package/dist/example/lock-release/userLock-ex.js +69 -0
- package/dist/example/manage/addSmg-ex.d.ts +1 -0
- package/dist/example/manage/addSmg-ex.js +59 -0
- package/dist/example/manage/compileContract-ex.d.ts +1 -0
- package/dist/example/manage/compileContract-ex.js +11 -0
- package/dist/example/manage/deploy-ex.d.ts +1 -0
- package/dist/example/manage/deploy-ex.js +58 -0
- package/dist/example/manage/setFee-ex.d.ts +1 -0
- package/dist/example/manage/setFee-ex.js +61 -0
- package/dist/example/manage/setFeeProxy.d.ts +1 -0
- package/dist/example/manage/setFeeProxy.js +47 -0
- package/dist/example/manage/upgradeBridgeSc-ex.d.ts +1 -0
- package/dist/example/manage/upgradeBridgeSc-ex.js +44 -0
- package/dist/example/token/AddToken-ex.d.ts +1 -0
- package/dist/example/token/AddToken-ex.js +113 -0
- package/dist/example/token/addTokenPair-ex.d.ts +1 -0
- package/dist/example/token/addTokenPair-ex.js +59 -0
- package/dist/example/token/delTokenPair-ex.d.ts +1 -0
- package/dist/example/token/delTokenPair-ex.js +49 -0
- package/dist/example/token/getTokenPair-ex.d.ts +1 -0
- package/dist/example/token/getTokenPair-ex.js +39 -0
- package/dist/example/token/mintToken-ex.d.ts +1 -0
- package/dist/example/token/mintToken-ex.js +56 -0
- package/dist/example/tran/converTranToTonTran.d.ts +1 -0
- package/dist/example/tran/converTranToTonTran.js +32 -0
- package/dist/example/tran/getTransByRange-ex.d.ts +1 -0
- package/{example/getTransByRange-ex.ts → dist/example/tran/getTransByRange-ex.js} +26 -40
- package/dist/example/tran/getTransaction-ex.d.ts +1 -0
- package/dist/example/tran/getTransaction-ex.js +47 -0
- package/dist/example/tran/isTranSuccess-ex.d.ts +1 -0
- package/dist/example/tran/isTranSuccess-ex.js +27 -0
- package/dist/fee/fee.d.ts +12 -0
- package/dist/fee/fee.js +21 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +95 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +8 -0
- package/dist/opcodes.d.ts +55 -0
- package/dist/opcodes.js +59 -0
- package/dist/sign/buildHash.d.ts +6 -0
- package/dist/sign/buildHash.js +39 -0
- package/dist/sign/rawTrans.d.ts +36 -0
- package/dist/sign/rawTrans.js +89 -0
- package/dist/sign/tools-secp256k1.d.ts +21 -0
- package/{sign → dist/sign}/tools-secp256k1.js +18 -44
- package/dist/testData/JettonMinter.compile.func.d.ts +2 -0
- package/dist/testData/JettonMinter.compile.func.js +13 -0
- package/dist/testData/JettonWallet.compile.func.d.ts +2 -0
- package/dist/testData/JettonWallet.compile.func.js +13 -0
- package/dist/testData/bridge.compile.func.d.ts +2 -0
- package/dist/testData/bridge.compile.func.js +13 -0
- package/dist/transResult/transResult.d.ts +29 -0
- package/dist/transResult/transResult.js +528 -0
- package/dist/utils/compileContract.d.ts +13 -0
- package/dist/utils/compileContract.js +54 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.js +94 -0
- package/dist/utils/utils.d.ts +26 -0
- package/dist/utils/utils.js +330 -0
- package/dist/wallet/balance.d.ts +5 -0
- package/dist/wallet/balance.js +29 -0
- package/dist/wallet/jetton.d.ts +16 -0
- package/dist/wallet/jetton.js +171 -0
- package/dist/wallet/walletContract.d.ts +31 -0
- package/dist/wallet/walletContract.js +106 -0
- package/package.json +8 -6
- package/Bridge.compile.ts +0 -8
- package/Bridge.ts +0 -645
- package/Bridge.ts.org +0 -647
- package/Fake.compile.ts +0 -8
- package/GroupApprove.compile.ts +0 -6
- package/GroupApprove.ts +0 -274
- package/JettonMinter.compile.ts +0 -5
- package/JettonMinter.ts +0 -135
- package/JettonWallet.compile.ts +0 -5
- package/JettonWallet.ts +0 -127
- package/Signature.compile.ts +0 -6
- package/Signature.ts +0 -105
- package/address.compile.ts +0 -8
- package/client/1.json +0 -1730
- package/client/client.ts +0 -73
- package/client/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/code/decode.spec.ts +0 -81
- package/code/encode-decode.ts +0 -622
- package/code/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -20
- package/code/log/wan-ton-sdk.out.2025-01-20 +0 -0
- package/code/userLock.ts +0 -291
- package/common.ts +0 -62
- package/config/config-ex.ts +0 -25
- package/config/config.ts +0 -1
- package/const/const-value.ts +0 -33
- package/contractAccess/bridgeAccess.ts +0 -60
- package/contractAccess/groupApproveAccess.ts +0 -59
- package/data/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs.json +0 -7348
- package/db/Db.spec.ts +0 -193
- package/db/Db.ts +0 -736
- package/db/DbAccess.spec.ts +0 -23
- package/db/DbAccess.ts +0 -186
- package/db/common.ts +0 -94
- package/db/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/db/log/wan-ton-sdk.out.2025-04-21 +0 -0
- package/event/getEvents.ts +0 -441
- package/event/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/event/log/wan-ton-sdk.out.2024-12-19 +0 -0
- package/example/0:1.txt +0 -1
- package/example/AddToken-ex.ts +0 -148
- package/example/README.md +0 -21
- package/example/addSmg-ex.ts +0 -78
- package/example/addTokenPair-ex.ts +0 -73
- package/example/compileContract-ex.ts +0 -10
- package/example/converTranToTonTran.ts +0 -43
- package/example/delTokenPair-ex.ts +0 -63
- package/example/deploy-ex.ts +0 -68
- package/example/getAllEvents-ex.ts +0 -61
- package/example/getAllTrans.ts +0 -32
- package/example/getContractState-ex.ts +0 -33
- package/example/getEvents-ex.ts +0 -55
- package/example/getJettonInfo-ex.ts +0 -44
- package/example/getTokenPair-ex.ts +0 -47
- package/example/getTransaction-ex.ts +0 -62
- package/example/isTranSuccess-ex.ts +0 -33
- package/example/locateTx-ex.ts +0 -44
- package/example/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -55
- package/example/log/wan-ton-sdk.out.2025-04-21 +0 -447
- package/example/log/wan-ton-sdk.out.2025-04-22 +0 -1918
- package/example/log/wan-ton-sdk.out.2025-04-23 +0 -4216
- package/example/log/wan-ton-sdk.out.2025-04-24.gz +0 -0
- package/example/log/wan-ton-sdk.out.2025-04-25 +0 -46814
- package/example/log/wan-ton-sdk.out.2025-04-27.gz +0 -0
- package/example/log/wan-ton-sdk.out.2025-04-28 +0 -4966
- package/example/log/wan-ton-sdk.out.2025-04-29 +0 -1328
- package/example/log/wan-ton-sdk.out.2025-04-30 +0 -9
- package/example/mintToken-ex.ts +0 -82
- package/example/setFee-ex.ts +0 -82
- package/example/setFeeProxy.ts +0 -70
- package/example/smgRelease-ex.ts +0 -173
- package/example/upgradeBridgeSc-ex.ts +0 -49
- package/example/userLock-ex.ts +0 -78
- package/fee/fee.ts +0 -23
- package/index.ts +0 -76
- package/jest.config.ts +0 -9
- package/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -20
- package/log/wan-ton-sdk.out.2025-04-21 +0 -0
- package/log/wan-ton-sdk.out.2025-04-30 +0 -10
- package/opcodes.ts +0 -58
- package/publish.sh +0 -78
- package/sign/buildHash.ts +0 -47
- package/sign/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/sign/log/wan-ton-sdk.out.2025-04-14 +0 -3
- package/sign/rawTrans.spec.ts +0 -117
- package/sign/rawTrans.ts +0 -122
- package/testData/JettonMinter.compile.func.ts +0 -8
- package/testData/JettonWallet.compile.func.ts +0 -8
- package/testData/addressList.json +0 -6
- package/testData/bridge.compile.func.ts +0 -8
- package/testData/bridge.compiled.json +0 -1
- package/testData/contractAddress.json +0 -7
- package/testData/jettonTokenInfo.json +0 -14
- package/testData/prvlist.json +0 -6
- package/testData/smg.json +0 -5
- package/testData/tokenInfo.json +0 -23
- package/transResult/transResult.ts +0 -608
- package/tsconfig.json +0 -19
- package/utils/.compiled.json +0 -1
- package/utils/compileContract.ts +0 -60
- package/utils/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/utils/log/wan-ton-sdk.out.2025-01-08 +0 -0
- package/utils/logger.spec.ts +0 -14
- package/utils/logger.ts +0 -96
- package/utils/utils.spec.ts +0 -21
- package/utils/utils.ts +0 -295
- package/wallet/balance.ts +0 -29
- package/wallet/jetton.spec.ts +0 -27
- package/wallet/jetton.ts +0 -159
- package/wallet/walletContract.spec.ts +0 -111
- package/wallet/walletContract.ts +0 -105
- /package/{client/log/wan-ton-sdk.out.2024-12-19 → dist/config/config.d.ts} +0 -0
- /package/{code/log/wan-ton-sdk.out.2025-01-15 → dist/config/config.js} +0 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.logger = exports.Logger = void 0;
|
7
|
+
const winston_1 = __importDefault(require("winston"));
|
8
|
+
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
9
|
+
const moment = require('moment');
|
10
|
+
const path = require('path');
|
11
|
+
const customFormat = winston_1.default.format.printf(({ level, message, timestamp }) => {
|
12
|
+
return `${timestamp} [${level}]: ${message}`;
|
13
|
+
});
|
14
|
+
class Logger {
|
15
|
+
constructor(name, file, errorFile, level = 'info') {
|
16
|
+
this.name = name;
|
17
|
+
this.file = file;
|
18
|
+
this.errorFile = errorFile;
|
19
|
+
this.level = level ? level : 'info';
|
20
|
+
if (global.pkg) {
|
21
|
+
this.filePath = path.join(process.cwd(), file);
|
22
|
+
this.errorFilePath = path.join(process.cwd(), errorFile);
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
this.filePath = file;
|
26
|
+
this.errorFilePath = errorFile;
|
27
|
+
}
|
28
|
+
this.init(this.name, this.file, this.errorFile, this.level);
|
29
|
+
}
|
30
|
+
init(name, file, errorFile, level) {
|
31
|
+
this.logger = winston_1.default.createLogger({
|
32
|
+
levels: winston_1.default.config.syslog.levels,
|
33
|
+
level: level,
|
34
|
+
format: winston_1.default.format.combine(winston_1.default.format.timestamp(), customFormat),
|
35
|
+
transports: [
|
36
|
+
//
|
37
|
+
// - Write to all logs with level `level` and below to file
|
38
|
+
// - Write all logs error (and below) to errorFile.
|
39
|
+
//
|
40
|
+
// new winston.transports.Console({
|
41
|
+
// handleExceptions: true
|
42
|
+
// }),
|
43
|
+
new (winston_daily_rotate_file_1.default)({
|
44
|
+
filename: this.filePath,
|
45
|
+
level: level,
|
46
|
+
datePattern: 'YYYY-MM-DD',
|
47
|
+
zippedArchive: true,
|
48
|
+
maxSize: '50m',
|
49
|
+
maxFiles: (global.testnet || global.isLeader) ? '30d' : '10d'
|
50
|
+
})
|
51
|
+
],
|
52
|
+
exitOnError: false
|
53
|
+
});
|
54
|
+
}
|
55
|
+
debug(...params) {
|
56
|
+
let msgFull = params.join(" ");
|
57
|
+
try {
|
58
|
+
this.logger.debug(msgFull);
|
59
|
+
}
|
60
|
+
catch (err) {
|
61
|
+
this.error(err);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
info(...params) {
|
65
|
+
let msgFull = params.join(" ");
|
66
|
+
try {
|
67
|
+
this.logger.info(msgFull);
|
68
|
+
}
|
69
|
+
catch (err) {
|
70
|
+
this.error(err);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
warn(...params) {
|
74
|
+
let msgFull = params.join(" ");
|
75
|
+
try {
|
76
|
+
this.logger.warning(msgFull);
|
77
|
+
}
|
78
|
+
catch (err) {
|
79
|
+
this.error(err);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
error(...params) {
|
83
|
+
let msgFull = params.join(" ");
|
84
|
+
try {
|
85
|
+
this.logger.error(msgFull);
|
86
|
+
}
|
87
|
+
catch (err) {
|
88
|
+
exports.logger.info(err);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
exports.Logger = Logger;
|
93
|
+
const LOG_ROOT = path.join(__dirname, "../log/");
|
94
|
+
exports.logger = new Logger("wan-ton-sdk", path.join(LOG_ROOT, 'wan-ton-sdk.out'), path.join(LOG_ROOT, 'wan-ton-sdk.err'), global.SDK_LOG_LEVEL);
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { Address } from "@ton/core";
|
2
|
+
export declare const randomAddress: (wc?: number) => Address;
|
3
|
+
export declare const getRandomTon: (min: number, max: number) => bigint;
|
4
|
+
export declare const BufferrToHexString: (buff: Buffer) => string;
|
5
|
+
export declare const HexStringToBuffer: (str: String) => Buffer;
|
6
|
+
export declare function sleep(ms: number): Promise<unknown>;
|
7
|
+
export declare function getQueryID(): Promise<number>;
|
8
|
+
export declare function bigIntReviver(key: any, value: any): any;
|
9
|
+
export declare function bigIntReplacer(key: any, value: any): any;
|
10
|
+
export declare function isAddressEqual(src: Address | string, dst: Address | string): boolean;
|
11
|
+
export declare function bigIntToBytes32(value: bigint): Buffer;
|
12
|
+
export declare function int64ToByte32(int64Value: any): string;
|
13
|
+
export declare function remove0x(str: string): string;
|
14
|
+
export declare function add0x(str: string): string;
|
15
|
+
export declare function ensureFileAndPath(fullFilePath: string): Promise<boolean>;
|
16
|
+
export declare function ensurePath(fullFilePath: string): Promise<boolean>;
|
17
|
+
export declare function ensureDirectoryExists(directoryPath: any): Promise<void>;
|
18
|
+
export declare function removeFile(fullFilePath: string): Promise<boolean>;
|
19
|
+
export declare function formatError(err: any): string;
|
20
|
+
export declare function isValidHexString(str: string): boolean;
|
21
|
+
export declare function isNotBase64(str: any): boolean;
|
22
|
+
export declare function toBase64(str: any): any;
|
23
|
+
export declare function BigToAddress(big: bigint): Address;
|
24
|
+
export declare function bigIntToBuffer(big: bigint): Buffer;
|
25
|
+
export declare function bufferToBigInt(buffer: Buffer, isBigEndian?: boolean): bigint;
|
26
|
+
export declare function AddressToBig(addr: Address): bigint;
|
@@ -0,0 +1,330 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.HexStringToBuffer = exports.BufferrToHexString = exports.getRandomTon = exports.randomAddress = void 0;
|
4
|
+
exports.sleep = sleep;
|
5
|
+
exports.getQueryID = getQueryID;
|
6
|
+
exports.bigIntReviver = bigIntReviver;
|
7
|
+
exports.bigIntReplacer = bigIntReplacer;
|
8
|
+
exports.isAddressEqual = isAddressEqual;
|
9
|
+
exports.bigIntToBytes32 = bigIntToBytes32;
|
10
|
+
exports.int64ToByte32 = int64ToByte32;
|
11
|
+
exports.remove0x = remove0x;
|
12
|
+
exports.add0x = add0x;
|
13
|
+
exports.ensureFileAndPath = ensureFileAndPath;
|
14
|
+
exports.ensurePath = ensurePath;
|
15
|
+
exports.ensureDirectoryExists = ensureDirectoryExists;
|
16
|
+
exports.removeFile = removeFile;
|
17
|
+
exports.formatError = formatError;
|
18
|
+
exports.isValidHexString = isValidHexString;
|
19
|
+
exports.isNotBase64 = isNotBase64;
|
20
|
+
exports.toBase64 = toBase64;
|
21
|
+
exports.BigToAddress = BigToAddress;
|
22
|
+
exports.bigIntToBuffer = bigIntToBuffer;
|
23
|
+
exports.bufferToBigInt = bufferToBigInt;
|
24
|
+
exports.AddressToBig = AddressToBig;
|
25
|
+
const core_1 = require("@ton/core");
|
26
|
+
const crypto_1 = require("@ton/crypto");
|
27
|
+
const logger_1 = require("../utils/logger");
|
28
|
+
const randomAddress = (wc = 0) => {
|
29
|
+
const buf = Buffer.alloc(32);
|
30
|
+
for (let i = 0; i < buf.length; i++) {
|
31
|
+
buf[i] = Math.floor(Math.random() * 256);
|
32
|
+
}
|
33
|
+
return new core_1.Address(wc, buf);
|
34
|
+
};
|
35
|
+
exports.randomAddress = randomAddress;
|
36
|
+
const getRandom = (min, max) => {
|
37
|
+
return Math.random() * (max - min) + min;
|
38
|
+
};
|
39
|
+
const getRandomTon = (min, max) => {
|
40
|
+
return (0, core_1.toNano)(getRandom(min, max).toFixed(9));
|
41
|
+
};
|
42
|
+
exports.getRandomTon = getRandomTon;
|
43
|
+
const BufferrToHexString = (buff) => {
|
44
|
+
return "0x" + buff.toString('hex');
|
45
|
+
};
|
46
|
+
exports.BufferrToHexString = BufferrToHexString;
|
47
|
+
const HexStringToBuffer = (str) => {
|
48
|
+
return Buffer.from(str, 'hex');
|
49
|
+
};
|
50
|
+
exports.HexStringToBuffer = HexStringToBuffer;
|
51
|
+
async function sleep(ms) {
|
52
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
53
|
+
}
|
54
|
+
async function getQueryID() {
|
55
|
+
while (true) {
|
56
|
+
let queryID = await (0, crypto_1.getSecureRandomNumber)(1, Math.pow(2, 52) - 1);
|
57
|
+
if (queryID > 0) {
|
58
|
+
return queryID;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
function bigIntReviver(key, value) {
|
63
|
+
if (typeof value === "string" && value.endsWith("n")) {
|
64
|
+
return BigInt(value.slice(0, -1));
|
65
|
+
}
|
66
|
+
if (typeof value === "string") {
|
67
|
+
return BigInt(value);
|
68
|
+
}
|
69
|
+
return value;
|
70
|
+
}
|
71
|
+
function bigIntReplacer(key, value) {
|
72
|
+
if (typeof value === "bigint") {
|
73
|
+
return value.toString(10);
|
74
|
+
}
|
75
|
+
return value;
|
76
|
+
}
|
77
|
+
function isAddressEqual(src, dst) {
|
78
|
+
let srcAddr;
|
79
|
+
let dstAddr;
|
80
|
+
if (!(src instanceof core_1.Address)) {
|
81
|
+
srcAddr = core_1.Address.parse(src);
|
82
|
+
}
|
83
|
+
else {
|
84
|
+
srcAddr = src;
|
85
|
+
}
|
86
|
+
if (!(dst instanceof core_1.Address)) {
|
87
|
+
dstAddr = core_1.Address.parse(dst);
|
88
|
+
}
|
89
|
+
else {
|
90
|
+
dstAddr = dst;
|
91
|
+
}
|
92
|
+
return srcAddr.equals(dstAddr);
|
93
|
+
}
|
94
|
+
function bigIntToBytes32(value) {
|
95
|
+
if (value < 0n || value >= 2n ** 256n) {
|
96
|
+
throw new Error("Value must be a 256-bit unsigned integer");
|
97
|
+
}
|
98
|
+
const hex = value.toString(16).padStart(64, '0');
|
99
|
+
return Buffer.from(hex, 'hex');
|
100
|
+
}
|
101
|
+
function int64ToByte32(int64Value) {
|
102
|
+
// 确保输入是 BigInt
|
103
|
+
if (typeof int64Value !== 'bigint') {
|
104
|
+
throw new Error('Input must be a BigInt');
|
105
|
+
}
|
106
|
+
// 创建一个 8 字节的缓冲区(64 位)
|
107
|
+
const buffer = new ArrayBuffer(8);
|
108
|
+
const view = new DataView(buffer);
|
109
|
+
// 将 BigInt 写入缓冲区(小端序)
|
110
|
+
view.setBigUint64(0, int64Value, true);
|
111
|
+
// 将缓冲区转换为字节数组
|
112
|
+
const byteArray = new Uint8Array(buffer);
|
113
|
+
// 创建一个 32 字节的缓冲区
|
114
|
+
const byte32Buffer = new ArrayBuffer(32);
|
115
|
+
const byte32Array = new Uint8Array(byte32Buffer);
|
116
|
+
// 将 8 字节的 int64 复制到 32 字节缓冲区的末尾(右对齐)
|
117
|
+
byte32Array.set(byteArray, 24); // 24 = 32 - 8
|
118
|
+
// 将字节数组转换为十六进制字符串
|
119
|
+
let hexString = '0x';
|
120
|
+
byte32Array.forEach(byte => {
|
121
|
+
hexString += byte.toString(16).padStart(2, '0');
|
122
|
+
});
|
123
|
+
return hexString;
|
124
|
+
}
|
125
|
+
function remove0x(str) {
|
126
|
+
return (str.slice(0, 2).toLowerCase() == '0x') ? str.slice(2) : str;
|
127
|
+
}
|
128
|
+
function add0x(str) {
|
129
|
+
return (str.slice(0, 2).toLowerCase() == '0x') ? str : '0x' + str;
|
130
|
+
}
|
131
|
+
const fs = require('node:fs/promises');
|
132
|
+
const path = require('node:path');
|
133
|
+
async function ensureFileAndPath(fullFilePath) {
|
134
|
+
try {
|
135
|
+
await fs.access(fullFilePath);
|
136
|
+
logger_1.logger.info(`file exist: ${fullFilePath}`);
|
137
|
+
}
|
138
|
+
catch (error) {
|
139
|
+
if (error.code === 'ENOENT') {
|
140
|
+
const directoryPath = path.dirname(fullFilePath);
|
141
|
+
try {
|
142
|
+
await fs.access(directoryPath);
|
143
|
+
}
|
144
|
+
catch (dirError) {
|
145
|
+
if (dirError.code === 'ENOENT') {
|
146
|
+
logger_1.logger.info(`mkdir: ${directoryPath}`);
|
147
|
+
await fs.mkdir(directoryPath, { recursive: true });
|
148
|
+
}
|
149
|
+
else {
|
150
|
+
logger_1.logger.error(`mkdir (${directoryPath}):`, dirError);
|
151
|
+
return false;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
try {
|
155
|
+
await fs.writeFile(fullFilePath, '');
|
156
|
+
logger_1.logger.info(`file created: ${fullFilePath}`);
|
157
|
+
}
|
158
|
+
catch (fileError) {
|
159
|
+
logger_1.logger.error(`create file fail (${fullFilePath}):`, fileError);
|
160
|
+
return false;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
else {
|
164
|
+
logger_1.logger.error(`access file fail (${fullFilePath}):`, error);
|
165
|
+
return false;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
return true;
|
169
|
+
}
|
170
|
+
async function ensurePath(fullFilePath) {
|
171
|
+
try {
|
172
|
+
await fs.access(fullFilePath);
|
173
|
+
logger_1.logger.info(`file exist: ${fullFilePath}`);
|
174
|
+
}
|
175
|
+
catch (error) {
|
176
|
+
if (error.code === 'ENOENT') {
|
177
|
+
const directoryPath = path.dirname(fullFilePath);
|
178
|
+
try {
|
179
|
+
await fs.access(directoryPath);
|
180
|
+
}
|
181
|
+
catch (dirError) {
|
182
|
+
if (dirError.code === 'ENOENT') {
|
183
|
+
logger_1.logger.info(`mkdir: ${directoryPath}`);
|
184
|
+
await fs.mkdir(directoryPath, { recursive: true });
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
logger_1.logger.error(`mkdir (${directoryPath}):`, dirError);
|
188
|
+
return false;
|
189
|
+
}
|
190
|
+
}
|
191
|
+
}
|
192
|
+
else {
|
193
|
+
logger_1.logger.error(`access file fail (${fullFilePath}):`, error);
|
194
|
+
return false;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
return true;
|
198
|
+
}
|
199
|
+
async function ensureDirectoryExists(directoryPath) {
|
200
|
+
try {
|
201
|
+
await fs.access(directoryPath);
|
202
|
+
logger_1.logger.info(`目录 "${directoryPath}" 已存在。`);
|
203
|
+
}
|
204
|
+
catch (error) {
|
205
|
+
if (error.code === 'ENOENT') {
|
206
|
+
try {
|
207
|
+
await fs.mkdir(directoryPath, { recursive: true });
|
208
|
+
logger_1.logger.info(`目录 "${directoryPath}" 创建成功。`);
|
209
|
+
}
|
210
|
+
catch (mkdirError) {
|
211
|
+
logger_1.logger.error(`创建目录 "${directoryPath}" 失败:`, mkdirError);
|
212
|
+
throw mkdirError; // Re-throw the error if directory creation fails
|
213
|
+
}
|
214
|
+
}
|
215
|
+
else {
|
216
|
+
logger_1.logger.error(`检查目录 "${directoryPath}" 失败:`, error);
|
217
|
+
throw error; // Re-throw other errors during access check
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
async function removeFile(fullFilePath) {
|
222
|
+
try {
|
223
|
+
await fs.access(fullFilePath);
|
224
|
+
logger_1.logger.info(`file exist: ${fullFilePath}`);
|
225
|
+
await fs.unlink(fullFilePath);
|
226
|
+
}
|
227
|
+
catch (error) {
|
228
|
+
if (error.code === 'ENOENT') {
|
229
|
+
return true;
|
230
|
+
}
|
231
|
+
else {
|
232
|
+
logger_1.logger.error(`access file fail (${fullFilePath}):`, formatError(error));
|
233
|
+
return false;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
237
|
+
const util = require('util');
|
238
|
+
const ERROR_WHITELIST = new Set(['message', 'code', 'cause', 'name', 'status']);
|
239
|
+
function formatErrorStack(error) {
|
240
|
+
if (!error.stack)
|
241
|
+
return [];
|
242
|
+
const stackLines = error.stack.split('\n');
|
243
|
+
return stackLines.slice(1).map(line => line.trim());
|
244
|
+
}
|
245
|
+
function extractErrorDetails(err, depth = 0, maxDepth = 3) {
|
246
|
+
if (depth > maxDepth)
|
247
|
+
return '[Max Depth Exceeded]';
|
248
|
+
if (!err || typeof err !== 'object')
|
249
|
+
return err;
|
250
|
+
const details = {};
|
251
|
+
ERROR_WHITELIST.forEach((key) => {
|
252
|
+
const value = err[key];
|
253
|
+
if (value !== undefined) {
|
254
|
+
details[key] = key === 'cause'
|
255
|
+
? extractErrorDetails(value, depth + 1, maxDepth)
|
256
|
+
: value;
|
257
|
+
}
|
258
|
+
});
|
259
|
+
if (err.response?.config?.data) {
|
260
|
+
details['response.config.data'] = err.response?.config?.data;
|
261
|
+
}
|
262
|
+
if (err.response?.data) {
|
263
|
+
details['response.data.error'] = err.response?.data;
|
264
|
+
}
|
265
|
+
if (err instanceof Error) {
|
266
|
+
details['stack'] = formatErrorStack(err);
|
267
|
+
}
|
268
|
+
return details;
|
269
|
+
}
|
270
|
+
function formatError(err) {
|
271
|
+
return JSON.stringify(extractErrorDetails(err), null, 2);
|
272
|
+
}
|
273
|
+
function isHexStringWithPrefix(str) {
|
274
|
+
return /^(0x)?[0-9a-fA-F]+$/.test(str);
|
275
|
+
}
|
276
|
+
function isEvenLengthHex(str) {
|
277
|
+
return (/^[0-9a-fA-F]+$/.test(str)) && (str.length % 2 === 0);
|
278
|
+
}
|
279
|
+
function isValidHexString(str) {
|
280
|
+
return isEvenLengthHex(remove0x(str));
|
281
|
+
}
|
282
|
+
function isNotBase64(str) {
|
283
|
+
// 同时匹配标准Base64和URL安全Base64的正则表达式
|
284
|
+
const BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$|^(?:[A-Za-z0-9\-_]{4})*(?:[A-Za-z0-9\-_]{2}==|[A-Za-z0-9\-_]{3}=)?$/;
|
285
|
+
// 类型检查
|
286
|
+
if (typeof str !== 'string')
|
287
|
+
return true;
|
288
|
+
// 基础校验
|
289
|
+
const len = str.length;
|
290
|
+
if (len === 0)
|
291
|
+
return false; // 空字符串视为有效
|
292
|
+
if (len % 4 !== 0)
|
293
|
+
return true; // 长度必须是4的倍数
|
294
|
+
// 检查编码格式
|
295
|
+
return !BASE64_REGEX.test(str);
|
296
|
+
}
|
297
|
+
function toBase64(str) {
|
298
|
+
if (isValidHexString(str)) {
|
299
|
+
return Buffer.from(remove0x(str), 'hex').toString('base64');
|
300
|
+
}
|
301
|
+
else {
|
302
|
+
if (!isNotBase64(str)) {
|
303
|
+
return str;
|
304
|
+
}
|
305
|
+
else {
|
306
|
+
throw new Error(`invalid string ${str}`);
|
307
|
+
}
|
308
|
+
}
|
309
|
+
}
|
310
|
+
function BigToAddress(big) {
|
311
|
+
let bufHash = bigIntToBuffer(big);
|
312
|
+
return new core_1.Address(0, bufHash);
|
313
|
+
}
|
314
|
+
function bigIntToBuffer(big) {
|
315
|
+
let buffer = Buffer.from(big.toString(16), 'hex');
|
316
|
+
let bufferLeft = Buffer.alloc(32 - buffer.length);
|
317
|
+
return Buffer.concat([bufferLeft, buffer]);
|
318
|
+
}
|
319
|
+
function bufferToBigInt(buffer, isBigEndian = true) {
|
320
|
+
let result = 0n;
|
321
|
+
const bytes = isBigEndian ? buffer : [...buffer].reverse();
|
322
|
+
for (const byte of bytes) {
|
323
|
+
result = (result << 8n) | BigInt(byte);
|
324
|
+
}
|
325
|
+
return result;
|
326
|
+
}
|
327
|
+
function AddressToBig(addr) {
|
328
|
+
let hash = addr.hash;
|
329
|
+
return bufferToBigInt(hash);
|
330
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { Blockchain } from "@ton/sandbox";
|
2
|
+
import { Address } from "@ton/core";
|
3
|
+
import { WanTonClient } from "../client/client-interface";
|
4
|
+
export declare function CoinBalance(client: WanTonClient | Blockchain, addr: Address): Promise<bigint>;
|
5
|
+
export declare function TokenBalance(client: WanTonClient | Blockchain, tokenAddr: Address, addr: Address): Promise<bigint>;
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.CoinBalance = CoinBalance;
|
4
|
+
exports.TokenBalance = TokenBalance;
|
5
|
+
const jetton_1 = require("./jetton");
|
6
|
+
const JettonMinter_1 = require("../JettonMinter");
|
7
|
+
const JettonWallet_1 = require("../JettonWallet");
|
8
|
+
const client_interface_1 = require("../client/client-interface");
|
9
|
+
async function CoinBalance(client, addr) {
|
10
|
+
if ((0, client_interface_1.IsWanTonClient)(client)) {
|
11
|
+
return await client.getBalance(addr);
|
12
|
+
}
|
13
|
+
else {
|
14
|
+
return (await client.getContract(addr)).balance;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
async function TokenBalance(client, tokenAddr, addr) {
|
18
|
+
if ((0, client_interface_1.IsWanTonClient)(client)) {
|
19
|
+
return await (0, jetton_1.getJettonBalance)(client, tokenAddr, addr);
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
let jetttonMaster = JettonMinter_1.JettonMinter.createFromAddress(tokenAddr);
|
23
|
+
let jetttonMasterOpened = await client.openContract(jetttonMaster);
|
24
|
+
let jettonAddr = await jetttonMasterOpened.getWalletAddress(addr);
|
25
|
+
let jettonWallet = JettonWallet_1.JettonWallet.createFromAddress(jettonAddr);
|
26
|
+
let jettonWalletOpened = await client.openContract(jettonWallet);
|
27
|
+
return await jettonWalletOpened.getJettonBalance();
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { Address, Cell } from "@ton/core";
|
2
|
+
import { WanTonClient } from "../client/client-interface";
|
3
|
+
import { Blockchain } from "@ton/sandbox";
|
4
|
+
export declare function getJettonBalance(client: WanTonClient | Blockchain, jettonMasterAddr: Address, userAddress: Address): Promise<bigint>;
|
5
|
+
export declare function getJettonAddress(client: WanTonClient | Blockchain, jettonMasterAddr: Address, userAddress: Address): Promise<Address>;
|
6
|
+
export declare function getJettonData(client: WanTonClient | Blockchain, jettonMasterAddr: Address): Promise<{
|
7
|
+
totalSupply: bigint;
|
8
|
+
mintable: boolean;
|
9
|
+
adminAddress: Address;
|
10
|
+
content: import("@ton/core").Cell;
|
11
|
+
walletCode: import("@ton/core").Cell;
|
12
|
+
}>;
|
13
|
+
export declare function getJettonWalletCode(client: WanTonClient | Blockchain, jettonMasterAddr: Address): Promise<Cell>;
|
14
|
+
export declare function getJettonDataContent(client: WanTonClient | Blockchain, jettonMasterAddr: Address): Promise<Cell>;
|
15
|
+
export declare function buildWrappedJettonContent(opts: any): Promise<Cell>;
|
16
|
+
export declare function parseWrappedJettonContent(cell: Cell): Promise<{}>;
|
@@ -0,0 +1,171 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getJettonBalance = getJettonBalance;
|
4
|
+
exports.getJettonAddress = getJettonAddress;
|
5
|
+
exports.getJettonData = getJettonData;
|
6
|
+
exports.getJettonWalletCode = getJettonWalletCode;
|
7
|
+
exports.getJettonDataContent = getJettonDataContent;
|
8
|
+
exports.buildWrappedJettonContent = buildWrappedJettonContent;
|
9
|
+
exports.parseWrappedJettonContent = parseWrappedJettonContent;
|
10
|
+
const core_1 = require("@ton/core");
|
11
|
+
const ton_1 = require("@ton/ton");
|
12
|
+
const crypto_1 = require("@ton/crypto");
|
13
|
+
const client_interface_1 = require("../client/client-interface");
|
14
|
+
const logger_1 = require("../utils/logger");
|
15
|
+
async function getJettonBalance(client, jettonMasterAddr, userAddress) {
|
16
|
+
if ((0, client_interface_1.IsWanTonClient)(client)) {
|
17
|
+
let jettonWalletAddress = await getJettonAddress(client, jettonMasterAddr, userAddress);
|
18
|
+
let jettonWalletContract = ton_1.JettonWallet.create(jettonWalletAddress);
|
19
|
+
return await (client.open(jettonWalletContract)).getBalance();
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
let jettonWalletAddress = await getJettonAddress(client, jettonMasterAddr, userAddress);
|
23
|
+
let jettonWalletContract = ton_1.JettonWallet.create(jettonWalletAddress);
|
24
|
+
return await (client.openContract(jettonWalletContract)).getBalance();
|
25
|
+
}
|
26
|
+
}
|
27
|
+
async function getJettonAddress(client, jettonMasterAddr, userAddress) {
|
28
|
+
if ((0, client_interface_1.IsWanTonClient)(client)) {
|
29
|
+
let jettonMasterContract = ton_1.JettonMaster.create(jettonMasterAddr);
|
30
|
+
return await (client.open(jettonMasterContract).getWalletAddress(userAddress));
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
let jettonMasterContract = ton_1.JettonMaster.create(jettonMasterAddr);
|
34
|
+
return await (client.openContract(jettonMasterContract).getWalletAddress(userAddress));
|
35
|
+
}
|
36
|
+
}
|
37
|
+
async function getJettonData(client, jettonMasterAddr) {
|
38
|
+
if ((0, client_interface_1.IsWanTonClient)(client)) {
|
39
|
+
let jettonMasterContract = ton_1.JettonMaster.create(jettonMasterAddr);
|
40
|
+
let openedContract = await client.open(jettonMasterContract);
|
41
|
+
return await openedContract.getJettonData();
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
let jettonMasterContract = ton_1.JettonMaster.create(jettonMasterAddr);
|
45
|
+
let openedContract = await client.openContract(jettonMasterContract);
|
46
|
+
return await openedContract.getJettonData();
|
47
|
+
}
|
48
|
+
}
|
49
|
+
async function getJettonWalletCode(client, jettonMasterAddr) {
|
50
|
+
return (await getJettonData(client, jettonMasterAddr)).walletCode;
|
51
|
+
}
|
52
|
+
async function getJettonDataContent(client, jettonMasterAddr) {
|
53
|
+
return (await getJettonData(client, jettonMasterAddr)).content;
|
54
|
+
}
|
55
|
+
/*
|
56
|
+
opts= {
|
57
|
+
name:'dog', // string
|
58
|
+
symbol:'dog', // string
|
59
|
+
decimal:'5', // string
|
60
|
+
}
|
61
|
+
*/
|
62
|
+
function leftpad(str, len, ch = ' ') {
|
63
|
+
str = String(str);
|
64
|
+
const pad = new Array(len - str.length + 1).join(ch);
|
65
|
+
return pad + str;
|
66
|
+
}
|
67
|
+
const SNAKE_PREFIX = 0x00;
|
68
|
+
const ONCHAIN_CONTENT_PREFIX = 0x00;
|
69
|
+
const KEYLEN = 256;
|
70
|
+
const jettonOnChainMetadataSpec = {
|
71
|
+
name: "utf8",
|
72
|
+
description: "utf8",
|
73
|
+
image: "ascii",
|
74
|
+
symbol: "utf8",
|
75
|
+
decimals: 'utf8'
|
76
|
+
};
|
77
|
+
async function getRidofProp(originalObj, propertiesToRemove) {
|
78
|
+
const newObj = Object.keys(originalObj)
|
79
|
+
.filter(key => !propertiesToRemove.includes(key))
|
80
|
+
.reduce((acc, key) => {
|
81
|
+
acc[key] = originalObj[key];
|
82
|
+
return acc;
|
83
|
+
}, {});
|
84
|
+
return newObj;
|
85
|
+
}
|
86
|
+
async function buildWrappedJettonContent(opts) {
|
87
|
+
const dict = core_1.Dictionary.empty(core_1.Dictionary.Keys.BigUint(KEYLEN), core_1.Dictionary.Values.Cell());
|
88
|
+
let newOpts = await getRidofProp(opts, ['tokenAddress', 'walletCodeBase64']);
|
89
|
+
Object.entries(newOpts).forEach(([k, v]) => {
|
90
|
+
if (!jettonOnChainMetadataSpec[k]) {
|
91
|
+
//throw new Error(`Unsupported token key: ${k}`);
|
92
|
+
logger_1.logger.error(`Unsupported token key: ${k}`);
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
if (v === undefined || v === "")
|
96
|
+
return;
|
97
|
+
let bufferToStore = Buffer.from(v, jettonOnChainMetadataSpec[k]);
|
98
|
+
const rootCell = (0, core_1.beginCell)();
|
99
|
+
rootCell.storeUint(SNAKE_PREFIX, 8);
|
100
|
+
let currentCell = rootCell;
|
101
|
+
const CELL_MAX_SIZE_BYTES = Math.floor((1023 - 8) / 8);
|
102
|
+
while (bufferToStore.length > 0) {
|
103
|
+
currentCell.storeBuffer(bufferToStore.slice(0, CELL_MAX_SIZE_BYTES));
|
104
|
+
bufferToStore = bufferToStore.slice(CELL_MAX_SIZE_BYTES);
|
105
|
+
if (bufferToStore.length > 0) {
|
106
|
+
const newCell = (0, core_1.beginCell)();
|
107
|
+
currentCell.storeRef(newCell);
|
108
|
+
currentCell = newCell;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
const keyHash = BigInt("0x" + (0, crypto_1.sha256_sync)(k).toString('hex'));
|
112
|
+
dict.set(keyHash, rootCell.endCell());
|
113
|
+
});
|
114
|
+
return (0, core_1.beginCell)()
|
115
|
+
.storeUint(ONCHAIN_CONTENT_PREFIX, 8)
|
116
|
+
.storeDict(dict)
|
117
|
+
.endCell();
|
118
|
+
}
|
119
|
+
async function parseWrappedJettonContent(cell) {
|
120
|
+
// const keys = Dictionary.Keys.BitString(256);
|
121
|
+
// const values = Dictionary.Values.Buffer(16);
|
122
|
+
// const keyName = new BitString(sha256_sync("name"),0,256);
|
123
|
+
// const keySymbol = new BitString(sha256_sync("symbol"),0,256);
|
124
|
+
// const keyDecimals = new BitString(sha256_sync("decimals"),0,256);
|
125
|
+
// let cs = cell.beginParse();
|
126
|
+
// cs.skip(8);
|
127
|
+
// let dictDs = Dictionary.loadDirect(keys, values, cs)
|
128
|
+
// return {
|
129
|
+
// name:dictDs.get(keyName).toString('utf-8').trim(),
|
130
|
+
// symbol:dictDs.get(keySymbol).toString('utf-8').trim(),
|
131
|
+
// decimals:dictDs.get(keyDecimals).toString('utf-8').trim(),
|
132
|
+
// }
|
133
|
+
const defaultJettonKeys = ["uri", "name", "description", "image", "image_data", "symbol", "decimals", "amount_style"];
|
134
|
+
const defaultNftKeys = ["uri", "name", "description", "image", "image_data"];
|
135
|
+
const contentValue = {
|
136
|
+
serialize: (src, builder) => {
|
137
|
+
builder.storeRef((0, core_1.beginCell)().storeUint(0, 8).storeStringTail(src).endCell());
|
138
|
+
},
|
139
|
+
parse: (src) => {
|
140
|
+
const sc = src.loadRef().beginParse();
|
141
|
+
const prefix = sc.loadUint(8);
|
142
|
+
if (prefix == 0) {
|
143
|
+
return sc.loadStringTail();
|
144
|
+
}
|
145
|
+
else if (prefix == 1) {
|
146
|
+
// Not really tested, but feels like it should work
|
147
|
+
const chunkDict = core_1.Dictionary.loadDirect(core_1.Dictionary.Keys.Uint(32), core_1.Dictionary.Values.Cell(), sc);
|
148
|
+
return chunkDict.values().map(x => x.beginParse().loadStringTail()).join('');
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
throw (Error(`Prefix ${prefix} is not supported yet`));
|
152
|
+
}
|
153
|
+
}
|
154
|
+
};
|
155
|
+
const content = cell.beginParse();
|
156
|
+
const type = content.loadUint(8);
|
157
|
+
logger_1.logger.info(`type is ${JSON.stringify(type)}`);
|
158
|
+
const contentDict = core_1.Dictionary.load(core_1.Dictionary.Keys.BigUint(256), contentValue, content);
|
159
|
+
const contentMap = {};
|
160
|
+
const contentKeys = defaultJettonKeys;
|
161
|
+
for (const name of contentKeys) {
|
162
|
+
// I know we should pre-compute hashed keys for known values... just not today.
|
163
|
+
const dictKey = BigInt("0x" + ((0, crypto_1.sha256_sync)(name)).toString('hex'));
|
164
|
+
const dictValue = contentDict.get(dictKey);
|
165
|
+
if (dictValue !== undefined) {
|
166
|
+
contentMap[name] = dictValue;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
logger_1.logger.info(`jetton has content ${JSON.stringify(contentMap, null, 2)}`);
|
170
|
+
return contentMap;
|
171
|
+
}
|