wan-ton-sdk 0.0.15 → 0.0.16
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/code/encode-decode.js +3 -1
- package/dist/code/exports.d.ts +2 -0
- package/dist/code/exports.js +18 -0
- package/dist/code/userLock.d.ts +49 -0
- package/dist/code/userLock.js +6 -2
- package/dist/config/config-ex.d.ts +1 -0
- package/dist/config/config-ex.js +13 -1
- package/dist/const/const-value.d.ts +1 -1
- package/dist/const/const-value.js +4 -3
- package/dist/contractAccess/bridgeAccess.js +3 -3
- package/dist/db/Db.js +10 -2
- package/dist/db/DbAccess.d.ts +1 -0
- package/dist/db/DbAccess.js +6 -0
- package/dist/event/getEvents.d.ts +3 -1
- package/dist/event/getEvents.js +37 -13
- package/dist/example/event/getAllEvents-ex.js +2 -2
- package/dist/example/event/getAllSlimEvents-ex.d.ts +1 -0
- package/dist/example/event/getAllSlimEvents-ex.js +73 -0
- package/dist/example/getAllTrans.js +1 -1
- package/dist/example/jetton/getJettonInfo-ex.js +1 -1
- package/dist/example/lock-release/smgRelease-ex.js +34 -28
- package/dist/example/lock-release/userLock-ex.js +9 -6
- package/dist/example/manage/addSmg-ex.js +1 -1
- package/dist/example/manage/deploy-ex.js +0 -1
- package/dist/example/manage/setFee-ex.js +0 -1
- package/dist/example/manage/setFeeProxy.js +1 -1
- package/dist/example/send/sendCoin.d.ts +1 -0
- package/dist/example/send/sendCoin.js +37 -0
- package/dist/example/send/sendToken.d.ts +1 -0
- package/dist/example/send/sendToken.js +38 -0
- package/dist/example/token/AddToken-ex.js +36 -27
- package/dist/example/token/addTokenPair-ex.js +10 -10
- package/dist/example/token/changeAdmin-ex.d.ts +1 -0
- package/dist/example/token/changeAdmin-ex.js +39 -0
- package/dist/example/token/delTokenPair-ex.js +5 -5
- package/dist/example/token/getAdmin-ex.d.ts +1 -0
- package/dist/example/token/getAdmin-ex.js +33 -0
- package/dist/example/token/getTokenPair-ex.js +5 -5
- package/dist/example/token/mintToken-ex.js +30 -34
- package/dist/index.d.ts +10 -15
- package/dist/index.js +44 -93
- package/dist/sign/exports.d.ts +3 -0
- package/dist/sign/exports.js +20 -0
- package/dist/testData/JettonMinter.compile.func.js +1 -1
- package/dist/testData/JettonWallet.compile.func.js +1 -1
- package/dist/testData/bridge.compile.func.js +1 -1
- package/dist/transResult/transResult.d.ts +1 -1
- package/dist/transResult/transResult.js +9 -7
- package/dist/utils/exports.d.ts +2 -0
- package/dist/utils/exports.js +18 -0
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.js +4 -0
- package/dist/wallet/exports.d.ts +4 -0
- package/dist/wallet/exports.js +20 -0
- package/dist/wallet/jetton.js +10 -3
- package/dist/wallet/send.d.ts +5 -0
- package/dist/wallet/send.js +35 -0
- package/package.json +1 -1
@@ -58,6 +58,8 @@ exports.codeTable = {
|
|
58
58
|
let crossValue = slice.loadUintBig(256);
|
59
59
|
let dstUserAccountLen = slice.loadUint(8);
|
60
60
|
let dstUserAccountBuff = slice.loadBuffer(dstUserAccountLen);
|
61
|
+
console.log("dstUserAccountBuff", dstUserAccountBuff.toString('hex'));
|
62
|
+
console.log("dstUserAccountBuffLen", dstUserAccountLen);
|
61
63
|
logger_1.logger.info("before load extraCell");
|
62
64
|
let extraCell = slice.loadRef().beginParse();
|
63
65
|
let addrTokenAccount = extraCell.loadAddress();
|
@@ -96,7 +98,7 @@ exports.codeTable = {
|
|
96
98
|
txHashBase64: opts.txHashBase64,
|
97
99
|
txHash: opts.txHash,
|
98
100
|
lt: opts?.lt,
|
99
|
-
from: opts?.origin,
|
101
|
+
from: (opts?.senderAccount).equals(core_1.Address.parse(const_value_1.TON_COIN_ACCOUNT_STR)) ? opts?.origin : opts?.senderAccount,
|
100
102
|
prevTransactionHash: opts?.prevTransactionHash,
|
101
103
|
prevTransactionLt: opts?.prevTransactionLt,
|
102
104
|
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./encode-decode"), exports);
|
18
|
+
__exportStar(require("./userLock"), exports);
|
package/dist/code/userLock.d.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import { Address } from "@ton/core";
|
2
|
+
import { Maybe } from "@ton/core/src/utils/maybe";
|
3
|
+
import { StateInit } from "@ton/core";
|
2
4
|
import { Cell } from "@ton/core";
|
3
5
|
import { Blockchain } from "@ton/sandbox";
|
4
6
|
import { WanTonClient } from "../client/client-interface";
|
@@ -29,6 +31,53 @@ export declare function buildUserLockMessages(opts: {
|
|
29
31
|
lockType: number;
|
30
32
|
value: bigint;
|
31
33
|
}>;
|
34
|
+
export declare function buildInternalMessage(src: {
|
35
|
+
to: Address | string;
|
36
|
+
value: bigint | string;
|
37
|
+
bounce?: Maybe<boolean>;
|
38
|
+
init?: Maybe<StateInit>;
|
39
|
+
body?: Maybe<Cell | string>;
|
40
|
+
}): Promise<import("@ton/ton").MessageRelaxed>;
|
41
|
+
export declare function buildLockCoinMessages(opts: {
|
42
|
+
value: bigint;
|
43
|
+
smgID: string;
|
44
|
+
tokenPairID: number;
|
45
|
+
crossValue: bigint;
|
46
|
+
dstUserAccount: string;
|
47
|
+
bridgeScAddr: string;
|
48
|
+
client: WanTonClient | Blockchain;
|
49
|
+
senderAccount: string;
|
50
|
+
}, jwAddrBridgeSc: Address, jwAddrSrc: Address, addrTokenAccount: Address, lockFee: bigint): Promise<{
|
51
|
+
internalMsg: import("@ton/ton").MessageRelaxed;
|
52
|
+
body: Cell;
|
53
|
+
to: string;
|
54
|
+
lockType: number;
|
55
|
+
value: bigint;
|
56
|
+
}>;
|
57
|
+
export declare function buildLockOriginalTokenMessages(opts: {
|
58
|
+
value: bigint;
|
59
|
+
smgID: string;
|
60
|
+
tokenPairID: number;
|
61
|
+
crossValue: bigint;
|
62
|
+
dstUserAccount: string;
|
63
|
+
bridgeScAddr: string;
|
64
|
+
client: WanTonClient | Blockchain;
|
65
|
+
senderAccount: string;
|
66
|
+
differentQueryID?: bigint;
|
67
|
+
}, jwAddrBridgeSc: Address, jwAddrSrc: Address, addrTokenAccount: Address, lockFee: bigint, differentQueryID?: bigint): Promise<{
|
68
|
+
internalMsg: import("@ton/ton").MessageRelaxed;
|
69
|
+
body: Cell;
|
70
|
+
to: Address;
|
71
|
+
lockType: number;
|
72
|
+
value: bigint;
|
73
|
+
}>;
|
74
|
+
export declare function buildLockWrappedTokenMessages(opts: any, jwAddrBridgeSc: Address, jwAddrSrc: Address, addrTokenAccount: Address, lockFee: bigint, differentQueryID?: bigint): Promise<{
|
75
|
+
internalMsg: import("@ton/ton").MessageRelaxed;
|
76
|
+
body: Cell;
|
77
|
+
to: Address;
|
78
|
+
lockType: number;
|
79
|
+
value: bigint;
|
80
|
+
}>;
|
32
81
|
export declare function getFee(client: WanTonClient | Blockchain, bridgeScAddr: Address, tokenPairID: number, srcChainId: any, dstChainId: any): Promise<number>;
|
33
82
|
export declare function getJettonWalletAddr(client: WanTonClient | Blockchain, jettonMasterAddr: Address, ownerAddr: Address): Promise<Address>;
|
34
83
|
export declare function getJettonAdminAddr(client: WanTonClient | Blockchain, jettonMasterAddr: Address): Promise<Address>;
|
package/dist/code/userLock.js
CHANGED
@@ -35,6 +35,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
36
36
|
exports.LOCK_TYPE = void 0;
|
37
37
|
exports.buildUserLockMessages = buildUserLockMessages;
|
38
|
+
exports.buildInternalMessage = buildInternalMessage;
|
39
|
+
exports.buildLockCoinMessages = buildLockCoinMessages;
|
40
|
+
exports.buildLockOriginalTokenMessages = buildLockOriginalTokenMessages;
|
41
|
+
exports.buildLockWrappedTokenMessages = buildLockWrappedTokenMessages;
|
38
42
|
exports.getFee = getFee;
|
39
43
|
exports.getJettonWalletAddr = getJettonWalletAddr;
|
40
44
|
exports.getJettonAdminAddr = getJettonAdminAddr;
|
@@ -106,10 +110,10 @@ async function buildInternalMessage(src) {
|
|
106
110
|
async function buildLockCoinMessages(opts, jwAddrBridgeSc, jwAddrSrc, addrTokenAccount, lockFee) {
|
107
111
|
logger_1.logger.info("buildLockCoinMessages", "jwAddrBridgeSc", jwAddrBridgeSc.toString(), "jwAddrSrc", jwAddrSrc.toString(), "addrTokenAccount", addrTokenAccount.toString(), "lockFee", lockFee);
|
108
112
|
let totalValue;
|
109
|
-
totalValue = opts.value + opts.crossValue;
|
113
|
+
totalValue = opts.value + opts.crossValue + lockFee;
|
110
114
|
logger_1.logger.info("totalValue=>", totalValue);
|
111
115
|
let queryId = await (0, utils_1.getQueryID)();
|
112
|
-
let dstUserAccountBuffer = Buffer.from(opts.dstUserAccount, 'hex');
|
116
|
+
let dstUserAccountBuffer = Buffer.from((0, utils_1.remove0x)(opts.dstUserAccount), 'hex');
|
113
117
|
let dstUserAccountBufferLen = dstUserAccountBuffer.length;
|
114
118
|
let extraCell = (0, core_1.beginCell)()
|
115
119
|
.storeAddress(addrTokenAccount)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { TonConfig } from "../client/client";
|
2
2
|
export declare const configTestnet: TonConfig;
|
3
3
|
export declare const configTestnetObs: TonConfig;
|
4
|
+
export declare const configTestnetNoDb: TonConfig;
|
4
5
|
export declare const configMainnet: TonConfig;
|
5
6
|
export declare const configTestTonApi: TonConfig;
|
6
7
|
export declare const configTestTonApiNoDb: TonConfig;
|
package/dist/config/config-ex.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.configMainTonApi = exports.configTestTonApiNoDb = exports.configTestTonApi = exports.configMainnet = exports.configTestnetObs = exports.configTestnet = void 0;
|
3
|
+
exports.configMainTonApi = exports.configTestTonApiNoDb = exports.configTestTonApi = exports.configMainnet = exports.configTestnetNoDb = exports.configTestnetObs = exports.configTestnet = void 0;
|
4
4
|
exports.configTestnet = {
|
5
5
|
network: {
|
6
6
|
network: "testnet", // testnet|mainnet
|
@@ -19,6 +19,18 @@ exports.configTestnetObs = {
|
|
19
19
|
},
|
20
20
|
usingDbCache: true,
|
21
21
|
};
|
22
|
+
exports.configTestnetNoDb = {
|
23
|
+
network: {
|
24
|
+
network: "testnet", // testnet|mainnet
|
25
|
+
},
|
26
|
+
usingDbCache: false,
|
27
|
+
urls: [
|
28
|
+
{
|
29
|
+
//url:'',
|
30
|
+
//apiKey:''
|
31
|
+
}
|
32
|
+
]
|
33
|
+
};
|
22
34
|
exports.configMainnet = {
|
23
35
|
network: {
|
24
36
|
network: "mainnet", // testnet|mainnet
|
@@ -14,7 +14,7 @@ export declare const CARRY_REMAINING_GAS = 64;
|
|
14
14
|
export declare const CARRY_REMAINING_BALANCE = 128;
|
15
15
|
export declare const MAX_LIMIT = 90;
|
16
16
|
export declare const MAX_RETRY = 3;
|
17
|
-
export declare const MAX_BACKTRACE_SECONDS
|
17
|
+
export declare const MAX_BACKTRACE_SECONDS = 86400;
|
18
18
|
export declare const RETRY_INTERNAL_TIME = 20;
|
19
19
|
export declare const TONCLINET_TIMEOUT: number;
|
20
20
|
export declare const MIN_SCAN_INTER: number;
|
@@ -19,8 +19,9 @@ exports.CARRY_REMAINING_GAS = 64;
|
|
19
19
|
exports.CARRY_REMAINING_BALANCE = 128;
|
20
20
|
exports.MAX_LIMIT = 90;
|
21
21
|
exports.MAX_RETRY = 3;
|
22
|
-
|
22
|
+
//export const MAX_BACKTRACE_SECONDS = 30*86400;
|
23
|
+
exports.MAX_BACKTRACE_SECONDS = 86400;
|
23
24
|
exports.RETRY_INTERNAL_TIME = 20;
|
24
25
|
exports.TONCLINET_TIMEOUT = 60 * 1000 * 1000;
|
25
|
-
exports.MIN_SCAN_INTER =
|
26
|
-
exports.MAX_SCAN_INTER =
|
26
|
+
exports.MIN_SCAN_INTER = 20 * 1000;
|
27
|
+
exports.MAX_SCAN_INTER = 40 * 1000;
|
@@ -26,8 +26,8 @@ class BridgeAccess {
|
|
26
26
|
return await cOpened[methodName](via, opts);
|
27
27
|
}
|
28
28
|
catch (err) {
|
29
|
-
logger_1.logger.
|
30
|
-
throw new Error(
|
29
|
+
logger_1.logger.error(formatUtil.format("writeContract err=>", "methodName", methodName, "opts", JSON.stringify(opts, utils_1.bigIntReplacer), "err", (0, utils_1.formatError)(err)));
|
30
|
+
throw new Error(`writeContract ${methodName} error ${(0, utils_1.formatError)(err)}`);
|
31
31
|
}
|
32
32
|
}
|
33
33
|
async readContract(methodName, parameters) {
|
@@ -42,7 +42,7 @@ class BridgeAccess {
|
|
42
42
|
}
|
43
43
|
catch (err) {
|
44
44
|
logger_1.logger.error(formatUtil.format((0, utils_1.formatError)(err)), "methodName", methodName, "parameters", parameters);
|
45
|
-
throw new Error(
|
45
|
+
throw new Error(`readContract ${methodName} error ${(0, utils_1.formatError)(err)}`);
|
46
46
|
}
|
47
47
|
}
|
48
48
|
}
|
package/dist/db/Db.js
CHANGED
@@ -310,13 +310,18 @@ class DB {
|
|
310
310
|
try {
|
311
311
|
let getSuccess = false;
|
312
312
|
let maxRetry = const_value_1.MAX_RETRY;
|
313
|
-
|
313
|
+
let insertSuccess = false;
|
314
|
+
while ((maxRetry-- > 0) && (!getSuccess || !insertSuccess)) {
|
314
315
|
try {
|
315
316
|
//let trans = await client.getTransactions(scAddress, optsOne)
|
316
317
|
let trans = await client.getTransactions(rawAddr, optsOne);
|
317
318
|
getSuccess = true;
|
318
319
|
this.logger.info("scanTonTxByTask get transcations one success", "optsOne", optsOne, "pivolt tran hash", trans[0].hash().toString('hex'));
|
319
320
|
tranPovit = trans[0];
|
321
|
+
let tonTrans = (0, common_1.convertTranToTonTrans)(trans);
|
322
|
+
this.logger.info("before insert povit tran", "db", this.dbName, "tranPovit.hash", tranPovit.hash().toString('base64'));
|
323
|
+
await this.insertTrans(tonTrans);
|
324
|
+
insertSuccess = true;
|
320
325
|
}
|
321
326
|
catch (e) {
|
322
327
|
this.logger.error("get transcations one err ", (0, utils_1.formatError)(e), "optsOne", optsOne);
|
@@ -391,7 +396,10 @@ class DB {
|
|
391
396
|
this.logger.info("scanTonTxByTask getTransactions success from rpc", "opts", JSON.stringify(opts, utils_1.bigIntReplacer), "len of getTransactions", transCount, "dbName", this.dbName);
|
392
397
|
for (let tran of ret) {
|
393
398
|
this.logger.info("(scanTonTxByTask) =====> tranHash = %s lt = %s", tran.hash().toString('base64'), tran.lt.toString(10), "dbName", this.dbName);
|
394
|
-
|
399
|
+
let cci = tran.inMessage.info;
|
400
|
+
if (cci?.createdAt && (BigInt(cci?.createdAt) + BigInt(const_value_1.MAX_BACKTRACE_SECONDS) >= BigInt(nowTimeStamp))) {
|
401
|
+
trans.push(tran); // oldest tran should not be inserted into db.
|
402
|
+
}
|
395
403
|
}
|
396
404
|
if (ret.length) {
|
397
405
|
opts.lt = ret[ret.length - 1].lt.toString(10);
|
package/dist/db/DbAccess.d.ts
CHANGED
@@ -18,6 +18,7 @@ export declare class DBAccess {
|
|
18
18
|
getChildTxs(dbName: string, tran: TonTransaction): Promise<import("@ton/core").Transaction[]>;
|
19
19
|
getAllTransNotHandled(dbName: string): Promise<import("@ton/core").Transaction[]>;
|
20
20
|
getAllTrans(dbName: string): Promise<import("@ton/core").Transaction[]>;
|
21
|
+
insertTrans(dbName: string, trans: TonTransaction[]): Promise<void>;
|
21
22
|
getAllTransNotHandledByRange(dbName: string, lt: bigint, to_lt: bigint): Promise<import("@ton/core").Transaction[]>;
|
22
23
|
getTxByOnlyMsgHash(dbName: string, msgCellHash: string): Promise<import("@ton/core").Transaction[]>;
|
23
24
|
getDbNameFinal(dbName: string): string;
|
package/dist/db/DbAccess.js
CHANGED
@@ -189,6 +189,12 @@ class DBAccess {
|
|
189
189
|
return finalRet;
|
190
190
|
}
|
191
191
|
}
|
192
|
+
async insertTrans(dbName, trans) {
|
193
|
+
if (!this.has(dbName)) {
|
194
|
+
throw new Error(`db ${dbName} not exists`);
|
195
|
+
}
|
196
|
+
await this.dbs.get(this.getDbNameFinal(dbName)).inserTrans(trans);
|
197
|
+
}
|
192
198
|
async getAllTransNotHandledByRange(dbName, lt, to_lt) {
|
193
199
|
if (!this.has(dbName)) {
|
194
200
|
throw new Error(`db ${dbName} not exists`);
|
@@ -10,8 +10,10 @@ export declare function getTransactions(client: WanTonClient, scAddress: string,
|
|
10
10
|
archival?: boolean;
|
11
11
|
}): Promise<any>;
|
12
12
|
export declare function getAllTransactions(client: WanTonClient, scAddress: string, limit: number, retry: number): Promise<any[]>;
|
13
|
-
export declare function getEventFromTran(client: WanTonClient, tran: Transaction, scAddress: string): Promise<any>;
|
13
|
+
export declare function getEventFromTran(client: WanTonClient, tran: Transaction, scAddress: string, slim?: boolean): Promise<any>;
|
14
|
+
export declare function getSlimEventFromTran(client: WanTonClient, tran: Transaction, scAddress: string): Promise<any>;
|
14
15
|
export declare function getTransaction(client: WanTonClient, scAddress: string, lt: string, tranHash: string): Promise<any>;
|
15
16
|
export declare function getTransactionFromDb(client: WanTonClient, scAddress: string, lt: string, tranHash: string): Promise<any>;
|
16
17
|
export declare function getEventByTranHash(client: WanTonClient, scAddress: string, lt: string, tranHash: string): Promise<any>;
|
18
|
+
export declare function getSlimEventByTranHash(client: WanTonClient, scAddress: string, lt: string, tranHash: string): Promise<any>;
|
17
19
|
export declare function getOpCodeFromCell(cell: Cell): Promise<number>;
|
package/dist/event/getEvents.js
CHANGED
@@ -37,9 +37,11 @@ exports.getEvents = getEvents;
|
|
37
37
|
exports.getTransactions = getTransactions;
|
38
38
|
exports.getAllTransactions = getAllTransactions;
|
39
39
|
exports.getEventFromTran = getEventFromTran;
|
40
|
+
exports.getSlimEventFromTran = getSlimEventFromTran;
|
40
41
|
exports.getTransaction = getTransaction;
|
41
42
|
exports.getTransactionFromDb = getTransactionFromDb;
|
42
43
|
exports.getEventByTranHash = getEventByTranHash;
|
44
|
+
exports.getSlimEventByTranHash = getSlimEventByTranHash;
|
43
45
|
exports.getOpCodeFromCell = getOpCodeFromCell;
|
44
46
|
const core_1 = require("@ton/core");
|
45
47
|
const encode_decode_1 = require("../code/encode-decode");
|
@@ -51,6 +53,7 @@ const utils_1 = require("../utils/utils");
|
|
51
53
|
const const_value_1 = require("../const/const-value");
|
52
54
|
const DbAccess_1 = require("../db/DbAccess");
|
53
55
|
const client_interface_1 = require("../client/client-interface");
|
56
|
+
const common_1 = require("../db/common");
|
54
57
|
async function getEvents(client, scAddress, limit, lt, to_lt, eventName, hash) {
|
55
58
|
logger_1.logger.info("scAddress:%s,limit:%s,lt:%s,to_lt:%s,eventName:%s", scAddress, limit, lt, to_lt, eventName);
|
56
59
|
if (!client) {
|
@@ -89,12 +92,23 @@ async function getTransactions(client, scAddress, opts) {
|
|
89
92
|
logger_1.logger.info(formatUtil.format("contractAddr=>", scAddress));
|
90
93
|
try {
|
91
94
|
ret = await client.getTransactions(scAddr, opts);
|
95
|
+
await insertTransByRpc(scAddr, ret);
|
92
96
|
}
|
93
97
|
catch (err) {
|
94
98
|
logger_1.logger.error((0, utils_1.formatError)(err), "getTransactions from RPC server opts = %s", opts);
|
95
99
|
}
|
96
100
|
return ret;
|
97
101
|
}
|
102
|
+
async function insertTransByRpc(scAddress, trans) {
|
103
|
+
let dbAccess = await DbAccess_1.DBAccess.getDBAccess();
|
104
|
+
if (!dbAccess) {
|
105
|
+
logger_1.logger.error("insertTransByRpc dbAccess null", "scAddress", scAddress.toString(), "trans.lenth", trans.length);
|
106
|
+
return null;
|
107
|
+
}
|
108
|
+
let tonTrans = (0, common_1.convertTranToTonTrans)(trans);
|
109
|
+
await dbAccess.insertTrans(scAddress.toString(), tonTrans);
|
110
|
+
logger_1.logger.error("insertTransByRpc successfully", "scAddress", scAddress.toString(), "trans.lenth", trans.length);
|
111
|
+
}
|
98
112
|
async function getTransactionsFromDb(client, scAddress, opts) {
|
99
113
|
logger_1.logger.info("getTransactionsFromDb opts = %s", opts);
|
100
114
|
let scAddr = core_1.Address.parse(scAddress);
|
@@ -161,7 +175,7 @@ async function getAllTransactions(client, scAddress, limit, retry) {
|
|
161
175
|
logger_1.logger.info("getAllTransactions success");
|
162
176
|
return trans;
|
163
177
|
}
|
164
|
-
async function getEventFromTran(client, tran, scAddress) {
|
178
|
+
async function getEventFromTran(client, tran, scAddress, slim = false) {
|
165
179
|
logger_1.logger.info("getEventFromTran entering", "client is WanTonClient", (0, client_interface_1.IsWanTonClient)(client));
|
166
180
|
let bodyCell = tran.inMessage?.body;
|
167
181
|
if (!bodyCell) {
|
@@ -188,28 +202,31 @@ async function getEventFromTran(client, tran, scAddress) {
|
|
188
202
|
if (opCode == opcodes.OP_CROSS_UserLock) {
|
189
203
|
logger_1.logger.info(formatUtil.format("getEventFromTran OP_CROSS_UserLock"));
|
190
204
|
logger_1.logger.info("getEventFromTran before handleUserLockEvent", "client is WanTonClient", (0, client_interface_1.IsWanTonClient)(client));
|
191
|
-
let handleResult = await handleUserLockEvent(client, core_1.Address.parse(scAddress), tran);
|
205
|
+
let handleResult = await handleUserLockEvent(client, core_1.Address.parse(scAddress), tran, slim);
|
192
206
|
if (!handleResult.valid) {
|
193
207
|
logger_1.logger.error(formatUtil.format("handleResult OP_CROSS_UserLock is not valid", "tran.hash", tran.hash().toString("base64")));
|
194
208
|
return null;
|
195
209
|
}
|
196
|
-
decoded.origin = handleResult.origin;
|
210
|
+
decoded.origin = decoded.sendAccount ? decoded.sendAccount : handleResult.origin;
|
197
211
|
}
|
198
212
|
else {
|
199
|
-
let handleResult = await handleCommonEvent(client, core_1.Address.parse(scAddress), tran);
|
213
|
+
let handleResult = await handleCommonEvent(client, core_1.Address.parse(scAddress), tran, slim);
|
200
214
|
if (!handleResult.valid) {
|
201
|
-
logger_1.logger.error(formatUtil.format("handleResult handleCommonEvent is not valid", "tran.hash", tran.hash().toString("base64")));
|
215
|
+
logger_1.logger.error(formatUtil.format("handleResult handleCommonEvent is not valid", "tran.hash", tran.hash().toString("base64"), "slim", slim));
|
202
216
|
return null;
|
203
217
|
}
|
204
|
-
decoded.origin = handleResult.origin;
|
218
|
+
decoded.origin = decoded.sendAccount ? decoded.sendAccount : handleResult.origin;
|
205
219
|
}
|
206
220
|
return await encode_decode_1.codeTable[opCode]["emitEvent"](decoded);
|
207
221
|
}
|
208
222
|
catch (err) {
|
209
223
|
logger_1.logger.error(formatUtil.format("getEventFromTran err", (0, utils_1.formatError)(err)), "tran.hash", tran.hash().toString("base64"));
|
210
|
-
|
224
|
+
throw new Error(formatUtil.format("getEventFromTran err", (0, utils_1.formatError)(err)));
|
211
225
|
}
|
212
226
|
}
|
227
|
+
async function getSlimEventFromTran(client, tran, scAddress) {
|
228
|
+
return await getEventFromTran(client, tran, scAddress, true);
|
229
|
+
}
|
213
230
|
async function getTransaction(client, scAddress, lt, tranHash) {
|
214
231
|
logger_1.logger.info("Entering getTransaction", "scAddress", scAddress, "lt", lt, "hash", tranHash, "hash(base64)", (0, utils_1.toBase64)(tranHash));
|
215
232
|
let retTranFromDb = await getTransactionFromDb(client, scAddress, lt, (0, utils_1.toBase64)(tranHash));
|
@@ -315,6 +332,13 @@ async function getEventByTranHash(client, scAddress, lt, tranHash) {
|
|
315
332
|
logger_1.logger.info("getEventByTranHash before getEventFromTran", "client is WanTonClient", (0, client_interface_1.IsWanTonClient)(client));
|
316
333
|
return await getEventFromTran(client, tran, scAddress);
|
317
334
|
}
|
335
|
+
async function getSlimEventByTranHash(client, scAddress, lt, tranHash) {
|
336
|
+
logger_1.logger.info("entering getSlimEventByTranHash getTransaction success", "tranHash ", tranHash, "lt", lt, "dbName", scAddress);
|
337
|
+
let tran = await getTransaction(client, scAddress, lt, tranHash);
|
338
|
+
logger_1.logger.info("getSlimEventByTranHash getTransaction success", "tranHash ", tran.hash().toString('hex'));
|
339
|
+
logger_1.logger.info("getSlimEventByTranHash before getEventFromTran", "client is WanTonClient", (0, client_interface_1.IsWanTonClient)(client));
|
340
|
+
return await getSlimEventFromTran(client, tran, scAddress);
|
341
|
+
}
|
318
342
|
async function getOpCodeFromCell(cell) {
|
319
343
|
if (cell.equals(core_1.Cell.EMPTY)) {
|
320
344
|
throw new Error("empty cell");
|
@@ -334,12 +358,12 @@ async function getOpCodeFromCell(cell) {
|
|
334
358
|
origin: Address, // from address, who trigger the lock event.
|
335
359
|
}
|
336
360
|
*/
|
337
|
-
async function handleUserLockEvent(client, scAddr, tran) {
|
338
|
-
return handleCommonEvent(client, scAddr, tran);
|
361
|
+
async function handleUserLockEvent(client, scAddr, tran, slim = false) {
|
362
|
+
return handleCommonEvent(client, scAddr, tran, slim);
|
339
363
|
}
|
340
|
-
async function handleCommonEvent(client, scAddr, tran) {
|
364
|
+
async function handleCommonEvent(client, scAddr, tran, slim = false) {
|
341
365
|
logger_1.logger.info(formatUtil.format("Entering handleCommonEvent"));
|
342
|
-
let transResult = await getTransResult(client, scAddr, tran);
|
366
|
+
let transResult = await getTransResult(client, scAddr, tran, slim);
|
343
367
|
if (!transResult.success) {
|
344
368
|
logger_1.logger.error("the trans tree is not success", "tran.hash", tran.hash().toString('base64'));
|
345
369
|
return {
|
@@ -381,6 +405,6 @@ async function decodeUserLock(bodyCell) {
|
|
381
405
|
jwAddrBridgeSc
|
382
406
|
};
|
383
407
|
}
|
384
|
-
async function getTransResult(client, scAddr, tran) {
|
385
|
-
return await (0, transResult_1.getTranResultByTran)(client, scAddr, tran);
|
408
|
+
async function getTransResult(client, scAddr, tran, slim = false) {
|
409
|
+
return await (0, transResult_1.getTranResultByTran)(client, scAddr, tran, slim);
|
386
410
|
}
|
@@ -31,8 +31,8 @@ async function main() {
|
|
31
31
|
await (0, utils_1.sleep)(2000);
|
32
32
|
}
|
33
33
|
try {
|
34
|
-
|
35
|
-
tonTrans = await dbAcces.getAllTrans(args[0])
|
34
|
+
tonTrans = await dbAcces.getAllTransNotHandled(args[0]);
|
35
|
+
//tonTrans = await dbAcces.getAllTrans(args[0])
|
36
36
|
console.log("getAllTransNotHandled tonTrans.length", tonTrans.length);
|
37
37
|
}
|
38
38
|
catch (err) {
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const utils_1 = require("../../utils/utils");
|
4
|
+
const config_ex_1 = require("../../config/config-ex");
|
5
|
+
const client_1 = require("../../client/client");
|
6
|
+
const getEvents_1 = require("../../event/getEvents");
|
7
|
+
const DbAccess_1 = require("../../db/DbAccess");
|
8
|
+
const core_1 = require("@ton/core");
|
9
|
+
const common_1 = require("../../db/common");
|
10
|
+
const args = process.argv.slice(2);
|
11
|
+
async function main() {
|
12
|
+
//await wanTonSdkInit(configMainnet);
|
13
|
+
//await wanTonSdkInit(configTestnet);
|
14
|
+
await (0, client_1.wanTonSdkInit)(config_ex_1.configTestTonApi);
|
15
|
+
//await wanTonSdkInit(configTestTonApiNoDb);
|
16
|
+
let scBridgeAddr = args[0];
|
17
|
+
let dbAcces = await DbAccess_1.DBAccess.getDBAccess();
|
18
|
+
if (!dbAcces) {
|
19
|
+
console.error("not using db cache");
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
console.log("scBridgeAddr", scBridgeAddr);
|
23
|
+
console.log("scBridgeAddr final address", core_1.Address.parse(scBridgeAddr).toString());
|
24
|
+
let client = await (0, client_1.getClient)();
|
25
|
+
let scanSlimEvent = async () => {
|
26
|
+
console.log("\n\n\n===================================getAllEvents===================================\n");
|
27
|
+
console.log("\n===================================getAllEvents===================================\n\n\n");
|
28
|
+
let tonTrans = [];
|
29
|
+
if (!dbAcces?.has(scBridgeAddr)) {
|
30
|
+
await dbAcces.addDbByName(scBridgeAddr);
|
31
|
+
await (0, utils_1.sleep)(2000);
|
32
|
+
}
|
33
|
+
try {
|
34
|
+
tonTrans = await dbAcces.getAllTransNotHandled(args[0]);
|
35
|
+
//tonTrans = await dbAcces.getAllTrans(args[0])
|
36
|
+
console.log("getAllTransNotHandled tonTrans.length", tonTrans.length);
|
37
|
+
}
|
38
|
+
catch (err) {
|
39
|
+
console.error(err.code, err.response?.data?.error);
|
40
|
+
}
|
41
|
+
if (!tonTrans) {
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
for (let tonTran of tonTrans) {
|
45
|
+
try {
|
46
|
+
console.log("begin getSlimEventByTranHash", "scBridgeAddr", scBridgeAddr, "lt", tonTran.lt.toString(10), "tranHash", tonTran.hash().toString('hex'));
|
47
|
+
let ret = await (0, getEvents_1.getSlimEventByTranHash)(client, scBridgeAddr, tonTran.lt.toString(10), tonTran.hash().toString('hex'));
|
48
|
+
console.log("end getSlimEventByTranHash JacobEvent ret = ", ret);
|
49
|
+
}
|
50
|
+
catch (err) {
|
51
|
+
console.error(err.code, err.response?.data?.error);
|
52
|
+
await (0, utils_1.sleep)(1000);
|
53
|
+
continue;
|
54
|
+
}
|
55
|
+
let tranTonTemp = (0, common_1.convertTranToTonTrans)([tonTran]);
|
56
|
+
console.log("begin setTranHandleFlag", "scBridgeAddr", scBridgeAddr, "lt", tonTran.lt.toString(10), "tranHash", tonTran.hash().toString('hex'));
|
57
|
+
await dbAcces.setTranHandleFlag(scBridgeAddr, tranTonTemp[0], true);
|
58
|
+
await (0, utils_1.sleep)(1000);
|
59
|
+
}
|
60
|
+
};
|
61
|
+
let round = 1;
|
62
|
+
let busy = false;
|
63
|
+
setInterval(async () => {
|
64
|
+
if (!busy) {
|
65
|
+
busy = true;
|
66
|
+
console.log("round = ", round++);
|
67
|
+
await scanSlimEvent();
|
68
|
+
busy = false;
|
69
|
+
}
|
70
|
+
}, 10000);
|
71
|
+
}
|
72
|
+
main();
|
73
|
+
// ts-node getAllSlimEvents-ex.ts kQDlYDH0PmST2okwTluXJ2mUDMDCzPzXF1gGz24U6H2tE9Wr
|
@@ -4,7 +4,7 @@ const utils_1 = require("../utils/utils");
|
|
4
4
|
const config_ex_1 = require("../config/config-ex");
|
5
5
|
const client_1 = require("../client/client");
|
6
6
|
const getEvents_1 = require("../event/getEvents");
|
7
|
-
const scAddress = require('
|
7
|
+
const scAddress = require('../../testData/contractAddress.json');
|
8
8
|
const LIMIT = 10;
|
9
9
|
let MAX_TRY_TIMES = 5;
|
10
10
|
async function main() {
|
@@ -10,7 +10,7 @@ const prvList = require('../../testData/prvlist');
|
|
10
10
|
let client = null;
|
11
11
|
async function init() {
|
12
12
|
//await wanTonSdkInit(configMainnet);
|
13
|
-
await (0, client_1.wanTonSdkInit)(config_ex_1.
|
13
|
+
await (0, client_1.wanTonSdkInit)(config_ex_1.configTestTonApiNoDb);
|
14
14
|
client = await (0, client_1.getClient)();
|
15
15
|
}
|
16
16
|
async function DisplayJettonInfo(client, addr) {
|
@@ -29,7 +29,7 @@ let client = null;
|
|
29
29
|
let aliceWallet, aliceAddressStr, aliceAddress;
|
30
30
|
let bobWallet, bobAddress, bobAddressStr;
|
31
31
|
async function init() {
|
32
|
-
await
|
32
|
+
//await wanTonSdkInit(configMainnet);
|
33
33
|
await (0, client_1.wanTonSdkInit)(config_ex_1.configTestnet);
|
34
34
|
client = await (0, client_1.getClient)();
|
35
35
|
aliceWallet = await (0, walletContract_1.getWalletByPrvKey)(prvAlice);
|
@@ -92,35 +92,41 @@ async function smgRelease() {
|
|
92
92
|
let transValueSmg = transValueSmgRelease;
|
93
93
|
let ba = bridgeAccess_1.BridgeAccess.create(client, bridgeScAddr);
|
94
94
|
for (let key of Object.keys(tokenInfo)) {
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
95
|
+
try {
|
96
|
+
console.log("key:", key);
|
97
|
+
// if(key.toString().toLowerCase() !== "tokenwrapped"){
|
98
|
+
// continue;
|
99
|
+
// }
|
100
|
+
// if(key.toString().toLowerCase() !== "coin"){
|
101
|
+
// continue;
|
102
|
+
// }
|
103
|
+
// if(key.toString().toLowerCase() !== "tokenOrg".toLowerCase()){
|
104
|
+
// continue;
|
105
|
+
// }
|
106
|
+
if (key.toString().toLowerCase() !== "ton".toLowerCase()) {
|
107
|
+
transValueSmg = fee_1.TON_FEE.TRANS_FEE_USER_LOCK_TOKEN;
|
108
|
+
}
|
109
|
+
let smgReleasePara = await buildSmgReleaseParameters(client, {
|
110
|
+
smgID: smgConfig.smgId,
|
111
|
+
tokenPairID: tokenInfo[key].tokenPairId,
|
112
|
+
releaseValue: smgReleaseValue,
|
113
|
+
value: transValueSmg,
|
114
|
+
queryID: BigInt(await (0, utils_1.getQueryID)()),
|
115
|
+
uniqueID: BigInt(await (0, utils_1.getQueryID)()), // should be txHas->bigInt, here is the example.
|
116
|
+
tokenCoinAccount: core_1.Address.parse(tokenInfo[key].dstTokenAcc),
|
117
|
+
//tokenCoinAccount:Address.parseFriendly(tokenInfo.tokenOrg.dstTokenAcc).address,
|
118
|
+
destAccount: bobAddress,
|
119
|
+
fwTonAmount: fee_1.TON_FEE.FWD_TON_AMOUNT_TRANSFER_JETTON,
|
120
|
+
totalTonAmount: fee_1.TON_FEE.TOTAL_TON_AMOUNT_TRANSFER_JETTON
|
121
|
+
}, tokenInfo[key].srcChainId, tokenInfo[key].dstChainId, core_1.Address.parse(bridgeScAddr));
|
122
|
+
let ret = await ba.writeContract('sendSmgRelease', aliceSender, smgReleasePara);
|
123
|
+
await (0, utils_1.sleep)(3000);
|
124
|
+
console.log("key = %s, ret of smRelease is %s", key, ret);
|
125
|
+
}
|
126
|
+
catch (err) {
|
127
|
+
console.error("key = %s, error: %s", key, err);
|
107
128
|
}
|
108
|
-
let smgReleasePara = await buildSmgReleaseParameters(client, {
|
109
|
-
smgID: smgConfig.smgId,
|
110
|
-
tokenPairID: tokenInfo[key].tokenPairId,
|
111
|
-
releaseValue: smgReleaseValue,
|
112
|
-
value: transValueSmg,
|
113
|
-
queryID: BigInt(await (0, utils_1.getQueryID)()),
|
114
|
-
uniqueID: BigInt(await (0, utils_1.getQueryID)()), // should be txHas->bigInt, here is the example.
|
115
|
-
tokenCoinAccount: core_1.Address.parse(tokenInfo[key].dstTokenAcc),
|
116
|
-
//tokenCoinAccount:Address.parseFriendly(tokenInfo.tokenOrg.dstTokenAcc).address,
|
117
|
-
destAccount: bobAddress,
|
118
|
-
fwTonAmount: fee_1.TON_FEE.FWD_TON_AMOUNT_TRANSFER_JETTON,
|
119
|
-
totalTonAmount: fee_1.TON_FEE.TOTAL_TON_AMOUNT_TRANSFER_JETTON
|
120
|
-
}, tokenInfo[key].srcChainId, tokenInfo[key].dstChainId, core_1.Address.parse(bridgeScAddr));
|
121
|
-
let ret = await ba.writeContract('sendSmgRelease', aliceSender, smgReleasePara);
|
122
129
|
await (0, utils_1.sleep)(3000);
|
123
|
-
console.log("key = %s, ret of smRelease is %s", key, ret);
|
124
130
|
}
|
125
131
|
}
|
126
132
|
catch (e) {
|
@@ -14,7 +14,7 @@ const scAddresses = require('../../testData/contractAddress.json');
|
|
14
14
|
const smgCfg = require('../../testData/smg.json');
|
15
15
|
const tokenInfo = require('../../testData/tokenInfo.json');
|
16
16
|
let smgID = smgCfg.smgId;
|
17
|
-
let crossValue = (0, core_1.toNano)('0.
|
17
|
+
let crossValue = (0, core_1.toNano)('0.001');
|
18
18
|
let bridgeScAddr = scAddresses.bridgeAddress;
|
19
19
|
//let transValueUserLock = toNano('0.4')
|
20
20
|
let transValueUserLock = (0, core_1.toNano)('1');
|
@@ -25,7 +25,8 @@ let aliceWallet, aliceAddress;
|
|
25
25
|
async function init() {
|
26
26
|
//await wanTonSdkInit(configMainnet);
|
27
27
|
//await wanTonSdkInit(configTestnet);
|
28
|
-
await
|
28
|
+
//await wanTonSdkInit(configTestTonApiNoDb);
|
29
|
+
await (0, client_1.wanTonSdkInit)(config_ex_1.configTestnetNoDb);
|
29
30
|
client = await (0, client_1.getClient)();
|
30
31
|
aliceWallet = await (0, walletContract_1.getWalletByPrvKey)(prvAlice);
|
31
32
|
aliceAddress = aliceWallet.address.toString();
|
@@ -38,11 +39,12 @@ async function userLock() {
|
|
38
39
|
let ba = bridgeAccess_1.BridgeAccess.create(client, bridgeScAddr);
|
39
40
|
for (let key of Object.keys(tokenInfo)) {
|
40
41
|
console.log("key:", key);
|
41
|
-
if (key.toString().toLowerCase() !== ("
|
42
|
-
continue;
|
43
|
-
}
|
44
|
-
if (key.toString().toLowerCase() !== ("coin").toLowerCase()) {
|
42
|
+
if (key.toString().toLowerCase() !== ("ton").toLowerCase()) {
|
45
43
|
transValue = fee_1.TON_FEE.TRANS_FEE_USER_LOCK_TOKEN;
|
44
|
+
//continue;
|
45
|
+
}
|
46
|
+
if (key.toString().toLowerCase() !== ("wan").toLowerCase()) {
|
47
|
+
continue;
|
46
48
|
}
|
47
49
|
let ret = await ba.writeContract('sendUserLock', aliceSender, {
|
48
50
|
value: transValue,
|
@@ -60,6 +62,7 @@ async function userLock() {
|
|
60
62
|
}
|
61
63
|
catch (e) {
|
62
64
|
console.log("err =%s", e.Error);
|
65
|
+
console.log("err(detailed):", e);
|
63
66
|
}
|
64
67
|
}
|
65
68
|
async function main() {
|