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,13 @@
|
|
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.conf = void 0;
|
7
|
+
const fs_2 = __importDefault(require("fs"));
|
8
|
+
exports.conf = {
|
9
|
+
targets: [
|
10
|
+
'../../contracts/jetton/jetton-wallet.func'
|
11
|
+
],
|
12
|
+
sources: (path) => (0, fs_2.default.readFileSync)(path).toString(),
|
13
|
+
};
|
@@ -0,0 +1,13 @@
|
|
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.conf = void 0;
|
7
|
+
const fs_2 = __importDefault(require("fs"));
|
8
|
+
exports.conf = {
|
9
|
+
targets: [
|
10
|
+
'../../contracts/bridge.fc'
|
11
|
+
],
|
12
|
+
sources: (path) => (0, fs_2.default.readFileSync)(path).toString(),
|
13
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { Address, Transaction } from "@ton/core";
|
2
|
+
import { WanTonClient } from "../client/client-interface";
|
3
|
+
export declare function isTranSuccess(tran: Transaction): Promise<boolean>;
|
4
|
+
export declare function getUpperStepsFromDb(client: WanTonClient, scAddr: Address, tran: Transaction, path: TranPathInfo): Promise<void>;
|
5
|
+
export declare function getUpperSteps(client: WanTonClient, scAddr: Address, tran: Transaction, path: TranPathInfo): Promise<void>;
|
6
|
+
export declare function getLowerSteps(client: WanTonClient, scAddr: Address, tran: Transaction, path: TranPathInfo): Promise<void>;
|
7
|
+
export interface TranStepInfo {
|
8
|
+
addr: Address;
|
9
|
+
txHash: string;
|
10
|
+
gasUsed: bigint;
|
11
|
+
status: boolean;
|
12
|
+
lt: string;
|
13
|
+
}
|
14
|
+
export interface TranResult {
|
15
|
+
addr: Address;
|
16
|
+
msgInHash: string;
|
17
|
+
path: TranPathInfo;
|
18
|
+
success: boolean;
|
19
|
+
originAddr: Address;
|
20
|
+
gasUsed: bigint;
|
21
|
+
}
|
22
|
+
export type TranPathInfo = TranStepInfo[];
|
23
|
+
export declare function getTranResultByMsgHash(client: WanTonClient, scAddr: Address, msgBodyCellHash: string, msgInHash: string): Promise<TranResult>;
|
24
|
+
export declare function getTranResultByTxHash(client: WanTonClient, scAddr: Address, txHash: string, lt: string): Promise<TranResult>;
|
25
|
+
export declare function getTranResultByTran(client: WanTonClient, scAddr: Address, tran: Transaction): Promise<TranResult>;
|
26
|
+
export declare function findMsgCellHashInTran(tran: Transaction, msgCellHash: string, msgBodyHash: string, lt?: string): Promise<Boolean>;
|
27
|
+
export declare function findOnlyMsgCellHashInTran(tran: Transaction, msgCellHash: string): Promise<Boolean>;
|
28
|
+
export declare function getTranByMsgHash(client: WanTonClient, scAddr: Address, msgCellHash: string, msgBodyHash: string, lt?: string): Promise<Transaction>;
|
29
|
+
export declare function getTranByOnlyMsgHash(client: WanTonClient, scAddr: Address, msgCellHash: string): Promise<Transaction>;
|
@@ -0,0 +1,528 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isTranSuccess = isTranSuccess;
|
4
|
+
exports.getUpperStepsFromDb = getUpperStepsFromDb;
|
5
|
+
exports.getUpperSteps = getUpperSteps;
|
6
|
+
exports.getLowerSteps = getLowerSteps;
|
7
|
+
exports.getTranResultByMsgHash = getTranResultByMsgHash;
|
8
|
+
exports.getTranResultByTxHash = getTranResultByTxHash;
|
9
|
+
exports.getTranResultByTran = getTranResultByTran;
|
10
|
+
exports.findMsgCellHashInTran = findMsgCellHashInTran;
|
11
|
+
exports.findOnlyMsgCellHashInTran = findOnlyMsgCellHashInTran;
|
12
|
+
exports.getTranByMsgHash = getTranByMsgHash;
|
13
|
+
exports.getTranByOnlyMsgHash = getTranByOnlyMsgHash;
|
14
|
+
const core_1 = require("@ton/core");
|
15
|
+
const utils_1 = require("../utils/utils");
|
16
|
+
const DbAccess_1 = require("../db/DbAccess");
|
17
|
+
const common_1 = require("../db/common");
|
18
|
+
const const_value_1 = require("../const/const-value");
|
19
|
+
const logger_1 = require("../utils/logger");
|
20
|
+
const formatUtil = require('util');
|
21
|
+
function sleep(ms) {
|
22
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
23
|
+
}
|
24
|
+
/*
|
25
|
+
return
|
26
|
+
[
|
27
|
+
{
|
28
|
+
addr: Address,
|
29
|
+
txHash: string,
|
30
|
+
gasUsed: bigInt,
|
31
|
+
status: boolean,
|
32
|
+
},
|
33
|
+
...
|
34
|
+
]
|
35
|
+
*/
|
36
|
+
async function getTranPathInfoByMsgHash(client, scAddr, msgBodyCellHash, msgInHash) {
|
37
|
+
let pivotTran = await getTranByMsgHash(client, scAddr, msgBodyCellHash, msgInHash);
|
38
|
+
let path = await getTranPathInfoByPivotTran(client, scAddr, pivotTran);
|
39
|
+
return path;
|
40
|
+
}
|
41
|
+
async function isTranSuccess(tran) {
|
42
|
+
//https://testnet.tonviewer.com/transaction/3a80c94fa62a855ebb47c634f1b42ebd0fdc9ea35ab3f6389bf2c086aac887ef
|
43
|
+
let td = tran.description;
|
44
|
+
// if(td.aborted){
|
45
|
+
// return false
|
46
|
+
// }
|
47
|
+
let cp = td.computePhase;
|
48
|
+
if ((cp.type == "vm") && (!cp.success || cp.exitCode != 0)) {
|
49
|
+
return false;
|
50
|
+
}
|
51
|
+
if (td.aborted && cp.type == "vm") {
|
52
|
+
return false;
|
53
|
+
}
|
54
|
+
let ap = td.actionPhase;
|
55
|
+
let apSuccess = ap?.success ? ap.success : true;
|
56
|
+
if (!apSuccess) {
|
57
|
+
return false;
|
58
|
+
}
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
async function computePathGas(path) {
|
62
|
+
let ret = BigInt(0);
|
63
|
+
for (let step of path) {
|
64
|
+
ret += step.gasUsed;
|
65
|
+
}
|
66
|
+
return ret;
|
67
|
+
}
|
68
|
+
async function isTranPathSuccess(allTranPathInfo) {
|
69
|
+
let ret = true;
|
70
|
+
for (let step of allTranPathInfo) {
|
71
|
+
if (!step.status) {
|
72
|
+
return false;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
return true;
|
76
|
+
}
|
77
|
+
async function getUpperStepsFromDb(client, scAddr, tran, path) {
|
78
|
+
logger_1.logger.info("getUpperStepsFromDb", "tran hash", tran.hash().toString('hex'));
|
79
|
+
if (tran.inMessage.info.type == 'external-in') {
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
const inMessageCell = (0, core_1.beginCell)().store((0, core_1.storeMessage)(tran.inMessage)).endCell();
|
83
|
+
logger_1.logger.info("getUpperStepsFromDb inMessageCell==>", "hash", tran.hash().toString('hex'));
|
84
|
+
let upperAddress = tran.inMessage.info.src;
|
85
|
+
let maxRetry = 5;
|
86
|
+
//get from scanned db
|
87
|
+
let dbAccess = await DbAccess_1.DBAccess.getDBAccess();
|
88
|
+
if (!dbAccess) {
|
89
|
+
logger_1.logger.error("not using db cache");
|
90
|
+
throw new Error("not using db cache");
|
91
|
+
}
|
92
|
+
let transFromDb = null;
|
93
|
+
let foundInDb = false;
|
94
|
+
while (maxRetry-- > 0 && !transFromDb) {
|
95
|
+
try {
|
96
|
+
let inDb = await dbAccess?.has(upperAddress.toString());
|
97
|
+
if (!inDb) {
|
98
|
+
await dbAccess?.addDbByName(upperAddress.toString());
|
99
|
+
await sleep(const_value_1.RETRY_INTERNAL_TIME);
|
100
|
+
}
|
101
|
+
logger_1.logger.info("getUpperStepsFromDb before dbAccess.getParentTx", "tran hash", tran.hash().toString('hex'), "upperAddress", upperAddress.toString());
|
102
|
+
transFromDb = await dbAccess?.getParentTx(upperAddress.toString(), (0, common_1.convertTranToTonTrans)([tran])[0]);
|
103
|
+
if (transFromDb) { // found from db
|
104
|
+
foundInDb = true;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
catch (err) {
|
108
|
+
logger_1.logger.info("getUpperStepsFromDb from db err", (0, utils_1.formatError)(err), "retry ", maxRetry);
|
109
|
+
}
|
110
|
+
await sleep(const_value_1.RETRY_INTERNAL_TIME);
|
111
|
+
}
|
112
|
+
if (maxRetry == 0 && !foundInDb) {
|
113
|
+
throw new Error(`Fail to look for parent. upperAddress: ${upperAddress.toString()}`);
|
114
|
+
}
|
115
|
+
if (foundInDb && transFromDb) {
|
116
|
+
logger_1.logger.info("getUpperStepsFromDB success", "hash", tran.hash().toString('hex'), "parent hash", transFromDb.hash().toString('hex'));
|
117
|
+
let stepInfoTemp = {
|
118
|
+
addr: upperAddress,
|
119
|
+
txHash: transFromDb.hash().toString('hex'),
|
120
|
+
gasUsed: transFromDb.totalFees.coins,
|
121
|
+
status: await isTranSuccess(transFromDb),
|
122
|
+
lt: transFromDb.lt.toString(),
|
123
|
+
};
|
124
|
+
path.unshift(stepInfoTemp);
|
125
|
+
await getUpperStepsFromDb(client, upperAddress, transFromDb, path);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
async function getUpperSteps(client, scAddr, tran, path) {
|
129
|
+
if (tran.inMessage.info.type == 'external-in') {
|
130
|
+
return;
|
131
|
+
}
|
132
|
+
try {
|
133
|
+
await getUpperStepsFromDb(client, scAddr, tran, path);
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
catch (err) {
|
137
|
+
logger_1.logger.info("getUpperStepsFromDb error", (0, utils_1.formatError)(err));
|
138
|
+
}
|
139
|
+
logger_1.logger.info("getUpperSteps from rpc", "scAddr", scAddr, "tran hash", tran.hash().toString('hex'));
|
140
|
+
const inMessageCell = (0, core_1.beginCell)().store((0, core_1.storeMessage)(tran.inMessage)).endCell();
|
141
|
+
logger_1.logger.info("inMessageCell==>", inMessageCell.toBoc().toString('hex'));
|
142
|
+
let tranInMsgHash = inMessageCell.hash().toString('hex');
|
143
|
+
let tranInMsgBodyCellHash = tran.inMessage.body.hash().toString('hex');
|
144
|
+
let upperAddress = tran.inMessage.info.src;
|
145
|
+
let maxTrans = 1000;
|
146
|
+
let transChecked = 0;
|
147
|
+
let opts = {
|
148
|
+
limit: 10,
|
149
|
+
archival: true,
|
150
|
+
};
|
151
|
+
let foundUpper = false;
|
152
|
+
let transCount = 10;
|
153
|
+
while (transChecked < maxTrans && !foundUpper && transCount) {
|
154
|
+
let retry = 5;
|
155
|
+
let status = false;
|
156
|
+
let transactions = [];
|
157
|
+
while (--retry > 0 && !status) {
|
158
|
+
try {
|
159
|
+
logger_1.logger.info("getUpperSteps getTransactions ", "scAddress", upperAddress, "opts", opts);
|
160
|
+
transactions = await client.getTransactions(upperAddress, opts);
|
161
|
+
transCount = transactions.length;
|
162
|
+
status = true;
|
163
|
+
retry = 5;
|
164
|
+
}
|
165
|
+
catch (e) {
|
166
|
+
await sleep(1000);
|
167
|
+
logger_1.logger.error((0, utils_1.formatError)(e));
|
168
|
+
}
|
169
|
+
}
|
170
|
+
if (retry == 0) {
|
171
|
+
throw (new Error(formatUtil.format("error getUpperSteps getTransactions ", "scAddress", upperAddress, "opts", opts)));
|
172
|
+
}
|
173
|
+
for (let i = 0; i < transactions.length; i++) {
|
174
|
+
let tx = transactions[i];
|
175
|
+
if (i == transactions.length - 1) {
|
176
|
+
opts.lt = tx.lt.toString(10);
|
177
|
+
opts.hash = tx.hash().toString('base64');
|
178
|
+
}
|
179
|
+
const transactionHash = tx.hash().toString('base64');
|
180
|
+
logger_1.logger.info("tx hash is:", i, tx.lt, transactionHash, tx.hash().toString('hex'));
|
181
|
+
const outMessages = tx.outMessages;
|
182
|
+
let foundInOutMsgs = false;
|
183
|
+
for (let outMsgKey of outMessages.keys()) {
|
184
|
+
let outMsg = outMessages.get(outMsgKey);
|
185
|
+
let outMsgHash = (0, core_1.beginCell)().store((0, core_1.storeMessage)(outMsg)).endCell().hash().toString('hex');
|
186
|
+
let outMsgBodyHash = outMsg.body.hash().toString('hex');
|
187
|
+
logger_1.logger.info("outMsgHash", outMsgHash, "tranInMsgHash", tranInMsgHash, "outMsgBodyHash", outMsgBodyHash, "tranInMsgBodyCellHash", tranInMsgBodyCellHash);
|
188
|
+
if (outMsgHash == tranInMsgHash || outMsgBodyHash == tranInMsgBodyCellHash) {
|
189
|
+
if (outMsg.info.dest.equals(scAddr)) {
|
190
|
+
if (outMsg.info.createdLt == tran.inMessage.info.createdLt) {
|
191
|
+
let stepInfoTemp = {
|
192
|
+
addr: upperAddress,
|
193
|
+
txHash: tx.hash().toString('hex'),
|
194
|
+
gasUsed: tx.totalFees.coins,
|
195
|
+
status: await isTranSuccess(tx),
|
196
|
+
lt: tx.lt.toString(),
|
197
|
+
};
|
198
|
+
path.unshift(stepInfoTemp);
|
199
|
+
foundInOutMsgs = true;
|
200
|
+
break;
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
if (foundInOutMsgs) {
|
206
|
+
logger_1.logger.info("found upper tx", tx.hash().toString('base64'));
|
207
|
+
await getUpperSteps(client, upperAddress, tx, path);
|
208
|
+
foundUpper = true;
|
209
|
+
break; // found the upper tx
|
210
|
+
}
|
211
|
+
}
|
212
|
+
await sleep(const_value_1.RETRY_INTERNAL_TIME);
|
213
|
+
transChecked += transactions.length;
|
214
|
+
}
|
215
|
+
if (transChecked >= maxTrans) {
|
216
|
+
throw new Error("can not found the upper tx!");
|
217
|
+
}
|
218
|
+
}
|
219
|
+
async function getLowerSteps(client, scAddr, tran, path) {
|
220
|
+
logger_1.logger.info("Entering getLowerSteps", "scAddr", scAddr);
|
221
|
+
if (tran.outMessages.keys().length == 0) {
|
222
|
+
return;
|
223
|
+
}
|
224
|
+
const outMessages = tran.outMessages;
|
225
|
+
for (let outMsgKey of outMessages.keys()) {
|
226
|
+
let outMsg = outMessages.get(outMsgKey);
|
227
|
+
let lowerAddr = outMsg.info.dest;
|
228
|
+
let msgCellHash = (0, core_1.beginCell)().store((0, core_1.storeMessage)(outMsg)).endCell().hash().toString('hex');
|
229
|
+
let msgBodyHash = outMsg.body.hash().toString('hex');
|
230
|
+
logger_1.logger.info("===========================before getTranByMsgHash", "outMsg", outMsg);
|
231
|
+
let lowerTx = await getTranByMsgHash(client, lowerAddr, msgCellHash, msgBodyHash, outMsg.info.createdLt.toString(10));
|
232
|
+
let stepInfoTemp = {
|
233
|
+
addr: lowerAddr,
|
234
|
+
txHash: lowerTx.hash().toString('hex'),
|
235
|
+
gasUsed: lowerTx.totalFees.coins,
|
236
|
+
status: await isTranSuccess(lowerTx),
|
237
|
+
lt: lowerTx.lt.toString(),
|
238
|
+
};
|
239
|
+
path.push(stepInfoTemp);
|
240
|
+
await getLowerSteps(client, lowerAddr, lowerTx, path);
|
241
|
+
}
|
242
|
+
}
|
243
|
+
async function getTranPathInfoByPivotTran(client, scAddr, pivotTran) {
|
244
|
+
logger_1.logger.info("Entering getTranPathInfoByPivotTran");
|
245
|
+
let allTranPathInfo = [];
|
246
|
+
let beforePivotTranPathInfo = [];
|
247
|
+
let afterPivotTranPathInfo = [];
|
248
|
+
let pivoltTranStepInfo = {
|
249
|
+
addr: scAddr,
|
250
|
+
txHash: pivotTran.hash().toString('hex'),
|
251
|
+
gasUsed: pivotTran.totalFees.coins,
|
252
|
+
status: await isTranSuccess(pivotTran),
|
253
|
+
lt: pivotTran.lt.toString(),
|
254
|
+
};
|
255
|
+
logger_1.logger.info("Entering get children tx");
|
256
|
+
await getLowerSteps(client, scAddr, pivotTran, afterPivotTranPathInfo); // find children tx //todo check it carefully.
|
257
|
+
logger_1.logger.info("End get children tx");
|
258
|
+
logger_1.logger.info("Entering get parent tx");
|
259
|
+
await getUpperSteps(client, scAddr, pivotTran, beforePivotTranPathInfo); // find parent tx
|
260
|
+
logger_1.logger.info("End get parent tx");
|
261
|
+
logger_1.logger.info("[pivoltTranStepInfo]====>", [pivoltTranStepInfo]);
|
262
|
+
logger_1.logger.info("[beforePivotTranPathInfo]====>", beforePivotTranPathInfo);
|
263
|
+
logger_1.logger.info("[afterPivotTranPathInfo]====>", afterPivotTranPathInfo);
|
264
|
+
let ret = allTranPathInfo.concat(beforePivotTranPathInfo, [pivoltTranStepInfo], afterPivotTranPathInfo);
|
265
|
+
logger_1.logger.info("========================ret = >", ret);
|
266
|
+
return ret;
|
267
|
+
}
|
268
|
+
// example of result
|
269
|
+
/*
|
270
|
+
TranResult=> {
|
271
|
+
addr: EQCT7rMc77KcPciOlxV-dfhYWK7RisB7lEAdGze2f0-vUI30,
|
272
|
+
msgInHash: '8a2fdd9e5508f06c94ff55f0d367fdaaca82207c52ed03008680319b2424bfed',
|
273
|
+
path: [
|
274
|
+
{
|
275
|
+
addr: EQCT7rMc77KcPciOlxV-dfhYWK7RisB7lEAdGze2f0-vUI30,
|
276
|
+
txHash: '3bc0e57c110eab0a0ad1d282df89a99f3c2a3aa71fcd27d2ff897bc45febd3bb',
|
277
|
+
gasUsed: 2577471n,
|
278
|
+
status: true,
|
279
|
+
lt: '29498261000001'
|
280
|
+
},
|
281
|
+
{
|
282
|
+
addr: EQBsdoNazbwI9ybbsgufhRocWBPm7emo7cZQxojqzNuvNRcC,
|
283
|
+
txHash: '9e4f815609fa16591648b08d186cda0d81175e3a45ee17a91754f83fe013136d',
|
284
|
+
gasUsed: 4319392n,
|
285
|
+
status: true,
|
286
|
+
lt: '29498264000001'
|
287
|
+
},
|
288
|
+
{
|
289
|
+
addr: EQCT7rMc77KcPciOlxV-dfhYWK7RisB7lEAdGze2f0-vUI30,
|
290
|
+
txHash: '78b3031ffed07ec7b147f24db7a80e6fda5338d1d9fdbf5e9a845dbcf12de67f',
|
291
|
+
gasUsed: 396405n,
|
292
|
+
status: true,
|
293
|
+
lt: '29498268000001'
|
294
|
+
}
|
295
|
+
],
|
296
|
+
success: true,
|
297
|
+
originAddr: EQCT7rMc77KcPciOlxV-dfhYWK7RisB7lEAdGze2f0-vUI30,
|
298
|
+
gasUsed: 7293268n
|
299
|
+
}
|
300
|
+
*/
|
301
|
+
async function getTranResultByMsgHash(client, scAddr, msgBodyCellHash, msgInHash) {
|
302
|
+
let path = await getTranPathInfoByMsgHash(client, scAddr, msgBodyCellHash, msgInHash);
|
303
|
+
let success = await isTranPathSuccess(path);
|
304
|
+
return {
|
305
|
+
addr: scAddr,
|
306
|
+
msgInHash,
|
307
|
+
path,
|
308
|
+
success,
|
309
|
+
originAddr: path[0].addr,
|
310
|
+
gasUsed: await computePathGas(path)
|
311
|
+
};
|
312
|
+
}
|
313
|
+
async function getTranResultByTxHash(client, scAddr, txHash, lt) {
|
314
|
+
let tran = await client.getTransaction(scAddr, lt, txHash);
|
315
|
+
let path = await getTranPathInfoByPivotTran(client, scAddr, tran);
|
316
|
+
let success = await isTranPathSuccess(path);
|
317
|
+
return {
|
318
|
+
addr: scAddr,
|
319
|
+
msgInHash: tran.inMessage.body.hash().toString('base64'),
|
320
|
+
path,
|
321
|
+
success,
|
322
|
+
originAddr: path[0].addr,
|
323
|
+
gasUsed: await computePathGas(path)
|
324
|
+
};
|
325
|
+
}
|
326
|
+
async function getTranResultByTran(client, scAddr, tran) {
|
327
|
+
logger_1.logger.info("Entering getTranResultByTran");
|
328
|
+
let path = await getTranPathInfoByPivotTran(client, scAddr, tran);
|
329
|
+
let success = await isTranPathSuccess(path);
|
330
|
+
return {
|
331
|
+
addr: scAddr,
|
332
|
+
msgInHash: tran.inMessage.body.hash().toString('base64'),
|
333
|
+
path,
|
334
|
+
success,
|
335
|
+
originAddr: path[0].addr,
|
336
|
+
gasUsed: await computePathGas(path)
|
337
|
+
};
|
338
|
+
}
|
339
|
+
async function findMsgCellHashInTran(tran, msgCellHash, msgBodyHash, lt = '') {
|
340
|
+
let found = false;
|
341
|
+
const inMessageCell = (0, core_1.beginCell)().store((0, core_1.storeMessage)(tran.inMessage)).endCell();
|
342
|
+
let inMessageHash = inMessageCell.hash().toString('hex');
|
343
|
+
let inMessageBodyCellHash = tran.inMessage.body.hash().toString('hex');
|
344
|
+
let internalMsg = true;
|
345
|
+
if (tran.inMessage.info.type == 'external-in') {
|
346
|
+
internalMsg = false;
|
347
|
+
}
|
348
|
+
let inMessageLt = "";
|
349
|
+
if (internalMsg) {
|
350
|
+
inMessageLt = tran.inMessage.info.createdLt.toString(10);
|
351
|
+
}
|
352
|
+
if (!internalMsg) {
|
353
|
+
if ((inMessageHash == msgCellHash || inMessageBodyCellHash == msgBodyHash)) {
|
354
|
+
found = true;
|
355
|
+
}
|
356
|
+
}
|
357
|
+
else {
|
358
|
+
if ((inMessageHash == msgCellHash || inMessageBodyCellHash == msgBodyHash)) {
|
359
|
+
if (lt.length != 0 && (inMessageLt == lt)) {
|
360
|
+
found = true;
|
361
|
+
}
|
362
|
+
else {
|
363
|
+
if (lt.length == 0) {
|
364
|
+
found = true;
|
365
|
+
}
|
366
|
+
}
|
367
|
+
}
|
368
|
+
}
|
369
|
+
return found;
|
370
|
+
}
|
371
|
+
async function findOnlyMsgCellHashInTran(tran, msgCellHash) {
|
372
|
+
let found = false;
|
373
|
+
const inMessageCell = (0, core_1.beginCell)().store((0, core_1.storeMessage)(tran.inMessage)).endCell();
|
374
|
+
let inMessageHash = inMessageCell.hash().toString('hex');
|
375
|
+
let inMessageBodyCellHash = tran.inMessage.body.hash().toString('hex');
|
376
|
+
let internalMsg = true;
|
377
|
+
if (tran.inMessage.info.type == 'external-in') {
|
378
|
+
internalMsg = false;
|
379
|
+
}
|
380
|
+
let inMessageLt = "";
|
381
|
+
if (internalMsg) {
|
382
|
+
inMessageLt = tran.inMessage.info.createdLt.toString(10);
|
383
|
+
}
|
384
|
+
if (!internalMsg) {
|
385
|
+
if ((inMessageHash == msgCellHash)) {
|
386
|
+
found = true;
|
387
|
+
}
|
388
|
+
}
|
389
|
+
else {
|
390
|
+
if ((inMessageHash == msgCellHash)) {
|
391
|
+
found = true;
|
392
|
+
}
|
393
|
+
}
|
394
|
+
return found;
|
395
|
+
}
|
396
|
+
async function getTranByMsgHash(client, scAddr, msgCellHash, msgBodyHash, lt = '') {
|
397
|
+
let limit = const_value_1.MAX_LIMIT;
|
398
|
+
let retry = const_value_1.MAX_RETRY;
|
399
|
+
let maxRetry = retry;
|
400
|
+
//get from scanned db
|
401
|
+
let dbAccess = await DbAccess_1.DBAccess.getDBAccess();
|
402
|
+
let transFromDb = null;
|
403
|
+
while (maxRetry-- > 0 && !transFromDb) {
|
404
|
+
try {
|
405
|
+
let inDb = await dbAccess?.has(scAddr.toString());
|
406
|
+
if (!inDb) {
|
407
|
+
await dbAccess.addDbByName(scAddr.toString());
|
408
|
+
await sleep(const_value_1.RETRY_INTERNAL_TIME);
|
409
|
+
}
|
410
|
+
transFromDb = await dbAccess?.getTxByMsg(scAddr.toString(), msgCellHash, msgBodyHash, BigInt(lt));
|
411
|
+
if (transFromDb) { // found from db
|
412
|
+
logger_1.logger.info("getTranByMsgHash from db success", "scAddr", scAddr, "msgCellHash", msgCellHash, "msgBodyHash", msgBodyHash, "lt", lt);
|
413
|
+
return transFromDb;
|
414
|
+
}
|
415
|
+
}
|
416
|
+
catch (err) {
|
417
|
+
logger_1.logger.error(err);
|
418
|
+
logger_1.logger.error("getTranByMsgHash from db err", (0, utils_1.formatError)(err), "retry ", maxRetry, "scAddr", scAddr, "msgCellHash", msgCellHash, "msgBodyHash", msgBodyHash, "lt", lt);
|
419
|
+
}
|
420
|
+
await sleep(const_value_1.RETRY_INTERNAL_TIME);
|
421
|
+
}
|
422
|
+
logger_1.logger.info("begin getTranByMsgHash from rpc", "scAddr", scAddr, "msgCellHash", msgCellHash, "msgBodyHash", msgBodyHash, "lt", lt);
|
423
|
+
//get from rpc
|
424
|
+
maxRetry = retry;
|
425
|
+
let trans = [];
|
426
|
+
let transCount = limit;
|
427
|
+
let opts = {
|
428
|
+
limit,
|
429
|
+
archival: true,
|
430
|
+
};
|
431
|
+
while (transCount) {
|
432
|
+
let getSuccess = false;
|
433
|
+
while (maxRetry-- > 0 && (!getSuccess)) {
|
434
|
+
try {
|
435
|
+
logger_1.logger.info("maxRetry = %s, getSuccess = %s, transCount = %s, scAddress = %s opts = %s", maxRetry, getSuccess, transCount, scAddr, JSON.stringify(opts, utils_1.bigIntReplacer));
|
436
|
+
let ret = await client.getTransactions(scAddr, opts);
|
437
|
+
transCount = ret.length;
|
438
|
+
logger_1.logger.info("getTranByMsgHash getTransactions success from rpc", "opts", JSON.stringify(opts, utils_1.bigIntReplacer), "len of getTransactions", transCount, "scAddr", scAddr);
|
439
|
+
for (let tran of ret) {
|
440
|
+
logger_1.logger.info("=====> tranHash = %s lt = %s", tran.hash().toString('base64'), tran.lt.toString(10));
|
441
|
+
let found = await findMsgCellHashInTran(tran, msgCellHash, msgBodyHash, lt);
|
442
|
+
if (found) {
|
443
|
+
return tran;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
if (ret.length) {
|
447
|
+
opts.lt = ret[ret.length - 1].lt.toString(10);
|
448
|
+
opts.hash = ret[ret.length - 1].hash().toString('base64');
|
449
|
+
}
|
450
|
+
getSuccess = true;
|
451
|
+
maxRetry = retry;
|
452
|
+
}
|
453
|
+
catch (e) {
|
454
|
+
logger_1.logger.error("getTranByMsgHash from rpc err ", (0, utils_1.formatError)(e));
|
455
|
+
await sleep(const_value_1.RETRY_INTERNAL_TIME);
|
456
|
+
}
|
457
|
+
}
|
458
|
+
if (maxRetry == 0) {
|
459
|
+
throw (new Error(formatUtil("getTransactions failed after %d retry. opts is %s", retry, JSON.stringify(opts))));
|
460
|
+
}
|
461
|
+
await sleep(const_value_1.RETRY_INTERNAL_TIME);
|
462
|
+
}
|
463
|
+
}
|
464
|
+
async function getTranByOnlyMsgHash(client, scAddr, msgCellHash) {
|
465
|
+
let limit = const_value_1.MAX_LIMIT;
|
466
|
+
let retry = const_value_1.MAX_RETRY;
|
467
|
+
let maxRetry = retry;
|
468
|
+
//get from scanned db
|
469
|
+
let dbAccess = await DbAccess_1.DBAccess.getDBAccess();
|
470
|
+
let transFromDb = null;
|
471
|
+
while (maxRetry-- > 0 && !transFromDb) {
|
472
|
+
try {
|
473
|
+
let inDb = await dbAccess?.has(scAddr.toString());
|
474
|
+
if (!inDb) {
|
475
|
+
await dbAccess.addDbByName(scAddr.toString());
|
476
|
+
await sleep(10);
|
477
|
+
}
|
478
|
+
transFromDb = await dbAccess?.getTxByOnlyMsgHash(scAddr.toString(), msgCellHash);
|
479
|
+
if (transFromDb) { // found from db
|
480
|
+
return transFromDb;
|
481
|
+
}
|
482
|
+
}
|
483
|
+
catch (err) {
|
484
|
+
logger_1.logger.error("getTranByOnlyMsgHash from db err", (0, utils_1.formatError)(err), "retry ", maxRetry);
|
485
|
+
}
|
486
|
+
await sleep(10);
|
487
|
+
}
|
488
|
+
//get from rpc
|
489
|
+
maxRetry = retry;
|
490
|
+
let trans = [];
|
491
|
+
let transCount = limit;
|
492
|
+
let opts = {
|
493
|
+
limit,
|
494
|
+
archival: true,
|
495
|
+
};
|
496
|
+
while (transCount) {
|
497
|
+
let getSuccess = false;
|
498
|
+
while (maxRetry-- > 0 && (!getSuccess)) {
|
499
|
+
try {
|
500
|
+
logger_1.logger.info("maxRetry = %s, getSuccess = %s, transCount = %s, scAddress = %s opts = %s", maxRetry, getSuccess, transCount, scAddr, JSON.stringify(opts, utils_1.bigIntReplacer));
|
501
|
+
let ret = await client.getTransactions(scAddr, opts);
|
502
|
+
transCount = ret.length;
|
503
|
+
logger_1.logger.info("getTranByOnlyMsgHash getTransactions success from rpc", "opts", JSON.stringify(opts, utils_1.bigIntReplacer), "len of getTransactions", transCount, "scAddr", scAddr);
|
504
|
+
for (let tran of ret) {
|
505
|
+
logger_1.logger.info("=====> tranHash = %s lt = %s", tran.hash().toString('base64'), tran.lt.toString(10));
|
506
|
+
let found = await findOnlyMsgCellHashInTran(tran, msgCellHash);
|
507
|
+
if (found) {
|
508
|
+
return tran;
|
509
|
+
}
|
510
|
+
}
|
511
|
+
if (ret.length) {
|
512
|
+
opts.lt = ret[ret.length - 1].lt.toString(10);
|
513
|
+
opts.hash = ret[ret.length - 1].hash().toString('base64');
|
514
|
+
}
|
515
|
+
getSuccess = true;
|
516
|
+
maxRetry = retry;
|
517
|
+
}
|
518
|
+
catch (e) {
|
519
|
+
logger_1.logger.error("err ", (0, utils_1.formatError)(e));
|
520
|
+
await sleep(const_value_1.RETRY_INTERNAL_TIME);
|
521
|
+
}
|
522
|
+
}
|
523
|
+
if (maxRetry == 0) {
|
524
|
+
throw (new Error(formatUtil("getTransactions failed after %d retry. opts is %s", retry, JSON.stringify(opts))));
|
525
|
+
}
|
526
|
+
await sleep(const_value_1.RETRY_INTERNAL_TIME);
|
527
|
+
}
|
528
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { CompilerConfig, CompilerVersion } from '@ton-community/func-js';
|
2
|
+
import { Cell } from '@ton/core';
|
3
|
+
export interface CR {
|
4
|
+
version: CompilerVersion;
|
5
|
+
hashHex: string;
|
6
|
+
codeBase64: string;
|
7
|
+
}
|
8
|
+
export declare function compileContract(conf: CompilerConfig): Promise<CR>;
|
9
|
+
export declare function writeCR(filePath: string, cr: CR): void;
|
10
|
+
export declare function doCompile(conf: CompilerConfig, resultFilePath?: string): Promise<{
|
11
|
+
status: boolean;
|
12
|
+
codeCell: Cell;
|
13
|
+
}>;
|
@@ -0,0 +1,54 @@
|
|
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.compileContract = compileContract;
|
7
|
+
exports.writeCR = writeCR;
|
8
|
+
exports.doCompile = doCompile;
|
9
|
+
const func_js_1 = require("@ton-community/func-js");
|
10
|
+
const core_1 = require("@ton/core");
|
11
|
+
const fs_2 = __importDefault(require("fs"));
|
12
|
+
const logger_1 = require("../utils/logger");
|
13
|
+
const formatUtil = require('util');
|
14
|
+
async function compileContract(conf) {
|
15
|
+
// You can get compiler version
|
16
|
+
let version = await (0, func_js_1.compilerVersion)();
|
17
|
+
let result = await (0, func_js_1.compileFunc)(conf);
|
18
|
+
if (result.status === 'error') {
|
19
|
+
logger_1.logger.error(result.message);
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
let codeCell = core_1.Cell.fromBoc(Buffer.from(result.codeBoc, "base64"))[0];
|
23
|
+
logger_1.logger.info(formatUtil.format("hash=>", codeCell.hash().toString('hex')));
|
24
|
+
let cr = {
|
25
|
+
version,
|
26
|
+
hashHex: codeCell.hash().toString('hex'),
|
27
|
+
codeBase64: result.codeBoc,
|
28
|
+
};
|
29
|
+
return cr;
|
30
|
+
}
|
31
|
+
function writeCR(filePath, cr) {
|
32
|
+
return fs_2.default.writeFileSync(filePath, JSON.stringify(cr));
|
33
|
+
}
|
34
|
+
async function doCompile(conf, resultFilePath) {
|
35
|
+
let ret = await compileContract(conf);
|
36
|
+
//logger.info(formatUtil.format(ret?.toBoc().toString('base64'));
|
37
|
+
logger_1.logger.info(formatUtil.format("result file path: %s", resultFilePath));
|
38
|
+
if (resultFilePath) {
|
39
|
+
writeCR(resultFilePath, ret);
|
40
|
+
let cr = JSON.parse(fs_2.default.readFileSync(resultFilePath, 'utf-8'));
|
41
|
+
let codeCell = core_1.Cell.fromBoc(Buffer.from(cr.codeBase64, "base64"))[0];
|
42
|
+
return {
|
43
|
+
status: codeCell.hash().toString('hex') == cr.hashHex && cr.hashHex == ret?.hashHex,
|
44
|
+
codeCell: codeCell
|
45
|
+
};
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
let codeCell = core_1.Cell.fromBoc(Buffer.from(ret?.codeBase64, "base64"))[0];
|
49
|
+
return {
|
50
|
+
status: true,
|
51
|
+
codeCell: codeCell,
|
52
|
+
};
|
53
|
+
}
|
54
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
export declare class Logger {
|
2
|
+
private filePath;
|
3
|
+
private errorFilePath;
|
4
|
+
private level;
|
5
|
+
private errorFile;
|
6
|
+
private file;
|
7
|
+
private name;
|
8
|
+
private logger;
|
9
|
+
constructor(name: any, file: any, errorFile: any, level?: string);
|
10
|
+
init(name: any, file: any, errorFile: any, level: any): void;
|
11
|
+
debug(...params: any[]): void;
|
12
|
+
info(...params: any[]): void;
|
13
|
+
warn(...params: any[]): void;
|
14
|
+
error(...params: any[]): void;
|
15
|
+
}
|
16
|
+
export declare const logger: Logger;
|