@layerzerolabs/ton-sdk-tools 3.0.84 → 3.0.86
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/CHANGELOG.md +12 -0
- package/dist/index.cjs +894 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +504 -22
- package/dist/index.d.ts +504 -22
- package/dist/index.mjs +846 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -4
package/dist/index.cjs
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
var fs = require('fs');
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var core = require('@ton/core');
|
|
6
|
-
var bigintBuffer = require('bigint-buffer');
|
|
7
6
|
var crc32 = require('crc-32');
|
|
7
|
+
var bigintBuffer = require('bigint-buffer');
|
|
8
8
|
var Event = require('@ton/sandbox/dist/event/Event');
|
|
9
9
|
var testUtils = require('@ton/test-utils');
|
|
10
10
|
var sha256Js = require('@aws-crypto/sha256-js');
|
|
11
|
+
var crypto = require('@ton/crypto');
|
|
12
|
+
var ton = require('@ton/ton');
|
|
11
13
|
|
|
12
14
|
function _interopNamespace(e) {
|
|
13
15
|
if (e && e.__esModule) return e;
|
|
@@ -32,43 +34,33 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
|
32
34
|
var crc32__namespace = /*#__PURE__*/_interopNamespace(crc32);
|
|
33
35
|
|
|
34
36
|
// src/sdk-tools.ts
|
|
35
|
-
var cellFromArtifact = ({ hex }) => core.Cell.fromHex(hex);
|
|
36
|
-
function getOpcodeCRC(input) {
|
|
37
|
-
return BigInt(crc32__namespace.str(input) >>> 0);
|
|
38
|
-
}
|
|
39
37
|
var MASTER_CHAIN_ID = -1;
|
|
40
38
|
var BASE_CHAIN_ID = 0;
|
|
41
39
|
var MASTER_CHAIN_SHARD = "8000000000000000";
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
var PUBLIC_KEY_BYTE_LENGTH = 64;
|
|
41
|
+
function publicKeyToHash(publicKey) {
|
|
42
|
+
const publicKeyCell = core.beginCell().storeBuffer(Buffer.from(publicKey), PUBLIC_KEY_BYTE_LENGTH).endCell();
|
|
43
|
+
const publicKeyHash = BigInt("0x" + publicKeyCell.hash().toString("hex"));
|
|
44
|
+
return publicKeyHash;
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (typeof value === "string") {
|
|
51
|
-
if (!isValidHex(value)) {
|
|
52
|
-
throw new Error("only hex string is supported");
|
|
53
|
-
}
|
|
54
|
-
let hex = trim0x(value);
|
|
55
|
-
if (hex.length % 2 !== 0) {
|
|
56
|
-
hex = "0" + hex;
|
|
57
|
-
}
|
|
58
|
-
value = bigintBuffer.toBigIntBE(Buffer.from(hex, "hex"));
|
|
59
|
-
}
|
|
60
|
-
if (value instanceof Uint8Array) {
|
|
61
|
-
value = bigintBuffer.toBigIntBE(Buffer.from(value));
|
|
46
|
+
function createVerifierDictSet(verifiers) {
|
|
47
|
+
const verifierDict = core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
48
|
+
for (const verifier of verifiers) {
|
|
49
|
+
verifierDict.set(publicKeyToHash(verifier), core.beginCell().endCell());
|
|
62
50
|
}
|
|
63
|
-
|
|
64
|
-
return bf.subarray(-32);
|
|
51
|
+
return core.beginCell().storeDictDirect(verifierDict, core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell()).endCell();
|
|
65
52
|
}
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
53
|
+
var getBocStringFromMessage = (message) => {
|
|
54
|
+
return core.beginCell().store(core.storeMessageRelaxed(message)).endCell().toBoc().toString("base64");
|
|
55
|
+
};
|
|
56
|
+
var getMessageFromBocString = (bocString) => {
|
|
57
|
+
const cell = core.Cell.fromBase64(bocString);
|
|
58
|
+
const cellSlice = cell.beginParse();
|
|
59
|
+
return core.loadMessageRelaxed(cellSlice);
|
|
60
|
+
};
|
|
61
|
+
var cellFromArtifact = ({ hex }) => core.Cell.fromHex(hex);
|
|
62
|
+
function getOpcodeCRC(input) {
|
|
63
|
+
return BigInt(crc32__namespace.str(input) >>> 0);
|
|
72
64
|
}
|
|
73
65
|
function findDeepestCell(cell) {
|
|
74
66
|
const refs = Array.from({ length: cell.refs.length }, (_, i) => cell.refs.at(i));
|
|
@@ -1143,7 +1135,8 @@ function saveViewFunctions(viewFunctions, directory, filename) {
|
|
|
1143
1135
|
const generated = [
|
|
1144
1136
|
file_signature_header,
|
|
1145
1137
|
`import { Address, Cell, Tuple, TupleItem, beginCell } from '@ton/core'`,
|
|
1146
|
-
`import {
|
|
1138
|
+
`import { TonContractWrapper } from '../wrappers'`,
|
|
1139
|
+
`import { ExtendedContract } from '@layerzerolabs/ton-sdk-tools'`,
|
|
1147
1140
|
""
|
|
1148
1141
|
];
|
|
1149
1142
|
for (const [contractName, functions] of Object.entries(viewFunctions)) {
|
|
@@ -1154,6 +1147,65 @@ function saveViewFunctions(viewFunctions, directory, filename) {
|
|
|
1154
1147
|
}
|
|
1155
1148
|
fs__namespace.writeFileSync(path__namespace.join(directory, filename), generated.join("\n"));
|
|
1156
1149
|
}
|
|
1150
|
+
function to32ByteBuffer(value, maxIntermediateBufferSize = 66) {
|
|
1151
|
+
if (typeof value === "string") {
|
|
1152
|
+
if (!isValidHex(value)) {
|
|
1153
|
+
throw new Error("only hex string is supported");
|
|
1154
|
+
}
|
|
1155
|
+
let hex = trim0x(value);
|
|
1156
|
+
if (hex.length % 2 !== 0) {
|
|
1157
|
+
hex = "0" + hex;
|
|
1158
|
+
}
|
|
1159
|
+
value = bigintBuffer.toBigIntBE(Buffer.from(hex, "hex"));
|
|
1160
|
+
}
|
|
1161
|
+
if (value instanceof Uint8Array) {
|
|
1162
|
+
value = bigintBuffer.toBigIntBE(Buffer.from(value));
|
|
1163
|
+
}
|
|
1164
|
+
const bf = bigintBuffer.toBufferBE(BigInt(value), maxIntermediateBufferSize);
|
|
1165
|
+
return bf.subarray(-32);
|
|
1166
|
+
}
|
|
1167
|
+
function trim0x(str2) {
|
|
1168
|
+
return str2.replace(/^0x/, "");
|
|
1169
|
+
}
|
|
1170
|
+
function isValidHex(str2) {
|
|
1171
|
+
const hexRegex = /^(0x)?[0-9A-Fa-f]+$/;
|
|
1172
|
+
return hexRegex.test(str2);
|
|
1173
|
+
}
|
|
1174
|
+
function bigintToAddress(value) {
|
|
1175
|
+
const buf = to32ByteBuffer(value);
|
|
1176
|
+
return core.Address.parse(`0:${buf.toString("hex")}`);
|
|
1177
|
+
}
|
|
1178
|
+
var parseTonAddress = (address) => {
|
|
1179
|
+
if (address instanceof core.Address) {
|
|
1180
|
+
return address;
|
|
1181
|
+
}
|
|
1182
|
+
if (typeof address === "bigint" || typeof address === "number") {
|
|
1183
|
+
return bigintToAddress(BigInt(address));
|
|
1184
|
+
}
|
|
1185
|
+
if (address.startsWith("0x")) {
|
|
1186
|
+
return bigintToAddress(BigInt(address));
|
|
1187
|
+
}
|
|
1188
|
+
try {
|
|
1189
|
+
return core.Address.parse(address);
|
|
1190
|
+
} catch (e) {
|
|
1191
|
+
return bigintToAddress(BigInt(`0x${address}`));
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
var _addressToNotPaddedHex = (address) => {
|
|
1195
|
+
return `0x${parseTonAddress(address).hash.toString("hex")}`;
|
|
1196
|
+
};
|
|
1197
|
+
var bigIntToHex = (bigInt) => {
|
|
1198
|
+
return `0x${bigInt.toString(16)}`.toLowerCase();
|
|
1199
|
+
};
|
|
1200
|
+
var addressToHex = (address) => {
|
|
1201
|
+
return `0x${to32ByteBuffer(_addressToNotPaddedHex(address)).toString("hex")}`.toLowerCase();
|
|
1202
|
+
};
|
|
1203
|
+
var addressToBigInt = (address) => {
|
|
1204
|
+
return BigInt(_addressToNotPaddedHex(address));
|
|
1205
|
+
};
|
|
1206
|
+
var compareAddresses = (addressA, addressB) => {
|
|
1207
|
+
return parseTonAddress(addressA).equals(parseTonAddress(addressB));
|
|
1208
|
+
};
|
|
1157
1209
|
var BaseWrapper = class {
|
|
1158
1210
|
constructor(address, init) {
|
|
1159
1211
|
this.address = address;
|
|
@@ -3103,11 +3155,12 @@ import ExecutorArtifact from '@layerzerolabs/layerzero-v2-ton/build/Executor.com
|
|
|
3103
3155
|
import ExecutorFeelibArtifact from '@layerzerolabs/layerzero-v2-ton/build/ExecutorFeeLib.compiled.json'
|
|
3104
3156
|
import PriceFeedCacheArtifact from '@layerzerolabs/layerzero-v2-ton/build/PriceFeedCache.compiled.json'
|
|
3105
3157
|
import PriceFeedFeeLibDefaultArtifact from '@layerzerolabs/layerzero-v2-ton/build/PriceFeedFeeLibDefault.compiled.json'
|
|
3158
|
+
import MaliciousFeeLibArtifact from '@layerzerolabs/layerzero-v2-ton/build/MaliciousFeeLib.compiled.json'
|
|
3106
3159
|
import ProxyArtifact from '@layerzerolabs/layerzero-v2-ton/build/Proxy.compiled.json'
|
|
3107
3160
|
import UlnArtifact from '@layerzerolabs/layerzero-v2-ton/build/Uln.compiled.json'
|
|
3108
3161
|
import UlnConnectionArtifact from '@layerzerolabs/layerzero-v2-ton/build/UlnConnection.compiled.json'
|
|
3109
3162
|
import UlnManagerArtifact from '@layerzerolabs/layerzero-v2-ton/build/UlnManager.compiled.json'
|
|
3110
|
-
import { ExtendedContract, Profile, addressToBigInt, cellFromArtifact, sendInternalMessageAndExpect, sendMessageViaMultisigAndExpect, } from '@layerzerolabs/ton-sdk-tools'
|
|
3163
|
+
import { BlueprintArtfiact, ExtendedContract, Profile, addressToBigInt, cellFromArtifact, sendInternalMessageAndExpect, sendMessageViaMultisigAndExpect, } from '@layerzerolabs/ton-sdk-tools'
|
|
3111
3164
|
|
|
3112
3165
|
import {
|
|
3113
3166
|
OAppFixture,
|
|
@@ -3347,19 +3400,26 @@ export async function addDvnWorkers(
|
|
|
3347
3400
|
receiveDvnFixtures: DvnFixture[],
|
|
3348
3401
|
dstEid: bigint,
|
|
3349
3402
|
priceFeedCacheAddress: Address,
|
|
3350
|
-
eventHandler: LzEventHandler
|
|
3403
|
+
eventHandler: LzEventHandler,
|
|
3404
|
+
addMaliciousWorker = false
|
|
3351
3405
|
): Promise<void> {
|
|
3352
3406
|
requireDefined(sendDvnFixtures)
|
|
3353
3407
|
requireDefined(receiveDvnFixtures)
|
|
3354
3408
|
const msglib = uln.get(dstEid)
|
|
3355
3409
|
requireDefined(msglib)
|
|
3410
|
+
let feelibArtifact: BlueprintArtfiact
|
|
3411
|
+
if (addMaliciousWorker) {
|
|
3412
|
+
feelibArtifact = MaliciousFeeLibArtifact
|
|
3413
|
+
} else {
|
|
3414
|
+
feelibArtifact = DvnFeelibArtifact
|
|
3415
|
+
}
|
|
3356
3416
|
for (const dvnFixture of [...sendDvnFixtures, ...receiveDvnFixtures]) {
|
|
3357
3417
|
const dvnWorkerCallMd = await allStorages.getNewMdExecuteParams({
|
|
3358
3418
|
target: addressToBigInt(msglibManager.address),
|
|
3359
3419
|
forwardingAddress: 0n,
|
|
3360
3420
|
callData: await allStorages.getNewUlnWorkerFeelibInfo({
|
|
3361
3421
|
workerAddress: addressToBigInt(dvnFixture.dvn.address),
|
|
3362
|
-
workerFeelibBytecode: cellFromArtifact(
|
|
3422
|
+
workerFeelibBytecode: cellFromArtifact(feelibArtifact),
|
|
3363
3423
|
workerFeelibStorage: await allStorages.getNewDvnFeelib({
|
|
3364
3424
|
quorum: BigInt(0),
|
|
3365
3425
|
remoteGas: BigInt(0),
|
|
@@ -3932,6 +3992,18 @@ export async function deployConfigAndRegisterUln(
|
|
|
3932
3992
|
)
|
|
3933
3993
|
await eventHandler.addCurrentEventsToAllEvents(internalMsgResults, srcFixture.msglibManager)
|
|
3934
3994
|
|
|
3995
|
+
// ===================================registerUlnWorkerInfo - maliciousFeeLib=======================================
|
|
3996
|
+
|
|
3997
|
+
internalMsgResults = await registerUlnWorkerInfo(
|
|
3998
|
+
blockchain,
|
|
3999
|
+
multiSigners,
|
|
4000
|
+
srcFixture,
|
|
4001
|
+
await allStorages.getNewMdUlnWorkerFeelibBytecode({
|
|
4002
|
+
bytecode: cellFromArtifact(MaliciousFeeLibArtifact),
|
|
4003
|
+
})
|
|
4004
|
+
)
|
|
4005
|
+
await eventHandler.addCurrentEventsToAllEvents(internalMsgResults, srcFixture.msglibManager)
|
|
4006
|
+
|
|
3935
4007
|
// ============================registerUlnWorkerInfo - executorFeeLib=======================================
|
|
3936
4008
|
|
|
3937
4009
|
internalMsgResults = await registerUlnWorkerInfo(
|
|
@@ -6207,6 +6279,742 @@ async function openAndDeployAllStoragesTemplate(blockchain, deployer, artifact,
|
|
|
6207
6279
|
});
|
|
6208
6280
|
return allStorages;
|
|
6209
6281
|
}
|
|
6282
|
+
function toPathArray(path4) {
|
|
6283
|
+
if (!/^[mM]'?/.test(path4)) {
|
|
6284
|
+
throw new Error('Path must start with "m" or "M"');
|
|
6285
|
+
}
|
|
6286
|
+
const parts = path4.replace(/^[mM]'?\//, "").split("/");
|
|
6287
|
+
const ret = Array(parts.length);
|
|
6288
|
+
for (let i = 0; i < parts.length; i++) {
|
|
6289
|
+
const tmp = /^(\d{1,10})[hH']$/.exec(parts[i]);
|
|
6290
|
+
if (tmp === null) {
|
|
6291
|
+
throw new Error("Invalid input");
|
|
6292
|
+
}
|
|
6293
|
+
ret[i] = parseInt(tmp[1], 10);
|
|
6294
|
+
if (ret[i] >= 2147483648) {
|
|
6295
|
+
throw new Error("Invalid child index");
|
|
6296
|
+
}
|
|
6297
|
+
}
|
|
6298
|
+
return ret;
|
|
6299
|
+
}
|
|
6300
|
+
async function getTonWalletFromMnemonic(mnemonic, path4 = "m/44'/607'/0'/0'/0'", workchain = 0) {
|
|
6301
|
+
const seed = await crypto.mnemonicToHDSeed(mnemonic.split(" "));
|
|
6302
|
+
const indices = toPathArray(path4);
|
|
6303
|
+
const derivedSeed = await crypto.deriveEd25519Path(seed, indices);
|
|
6304
|
+
const keyPair = crypto.keyPairFromSeed(derivedSeed);
|
|
6305
|
+
return {
|
|
6306
|
+
wallet: ton.WalletContractV4.create({
|
|
6307
|
+
publicKey: keyPair.publicKey,
|
|
6308
|
+
workchain
|
|
6309
|
+
}),
|
|
6310
|
+
keyPair
|
|
6311
|
+
};
|
|
6312
|
+
}
|
|
6313
|
+
var getTonWalletFromMnemonicLegacy = async (mnemonic, workchain = 0) => {
|
|
6314
|
+
const key = await crypto.mnemonicToWalletKey(mnemonic.split(" "));
|
|
6315
|
+
const wallet = ton.WalletContractV4.create({
|
|
6316
|
+
publicKey: key.publicKey,
|
|
6317
|
+
workchain
|
|
6318
|
+
});
|
|
6319
|
+
return { wallet, keyPair: key };
|
|
6320
|
+
};
|
|
6321
|
+
var hexToCells = (hex) => {
|
|
6322
|
+
const bitString = new core.BitString(Buffer.from(trim0x(hex), "hex"), 0, hex.slice(2).length * 4);
|
|
6323
|
+
const cells = [];
|
|
6324
|
+
let offset = 0;
|
|
6325
|
+
while (offset < bitString.length) {
|
|
6326
|
+
cells.push(core.beginCell());
|
|
6327
|
+
cells[cells.length - 1].storeBits(
|
|
6328
|
+
bitString.substring(offset, Math.min(bitString.length - offset, MAX_CELL_BITS))
|
|
6329
|
+
);
|
|
6330
|
+
offset += MAX_CELL_BITS;
|
|
6331
|
+
}
|
|
6332
|
+
if (cells.length === 0) {
|
|
6333
|
+
return core.beginCell().asCell();
|
|
6334
|
+
}
|
|
6335
|
+
cells.reverse();
|
|
6336
|
+
return cells.slice(1).reduce((children, parent) => parent.storeRef(children), cells[0]).asCell();
|
|
6337
|
+
};
|
|
6338
|
+
var getTotalBits = (cell) => {
|
|
6339
|
+
const parser = cell.beginParse();
|
|
6340
|
+
return parser.remainingBits + (parser.remainingRefs > 0 ? getTotalBits(parser.loadRef()) : 0);
|
|
6341
|
+
};
|
|
6342
|
+
var getClosestByteAlignedBits = (bits) => {
|
|
6343
|
+
return Math.ceil(bits / 8) * 8;
|
|
6344
|
+
};
|
|
6345
|
+
var cellsToHex = (cell) => {
|
|
6346
|
+
let parser = cell.beginParse();
|
|
6347
|
+
const totalBits = getClosestByteAlignedBits(getTotalBits(cell));
|
|
6348
|
+
const bitBuilder = new core.BitBuilder(totalBits);
|
|
6349
|
+
while (parser.remainingRefs >= 0) {
|
|
6350
|
+
const bitsString = parser.loadBits(parser.remainingBits);
|
|
6351
|
+
bitBuilder.writeBits(bitsString);
|
|
6352
|
+
if (parser.remainingRefs === 0) {
|
|
6353
|
+
break;
|
|
6354
|
+
}
|
|
6355
|
+
parser = parser.loadRef().beginParse();
|
|
6356
|
+
}
|
|
6357
|
+
return `0x${bitBuilder.buffer().toString("hex")}`;
|
|
6358
|
+
};
|
|
6359
|
+
var calculateCellConsumption = (cell) => {
|
|
6360
|
+
let parser = cell.beginParse();
|
|
6361
|
+
let numberOfCells = 1;
|
|
6362
|
+
let bits = parser.remainingBits;
|
|
6363
|
+
while (parser.remainingRefs > 0) {
|
|
6364
|
+
parser = parser.loadRef().beginParse();
|
|
6365
|
+
numberOfCells++;
|
|
6366
|
+
bits += parser.remainingBits;
|
|
6367
|
+
}
|
|
6368
|
+
return { numberOfCells, bits };
|
|
6369
|
+
};
|
|
6370
|
+
var calculateCellConsumptionFromHex = (hex) => {
|
|
6371
|
+
return calculateCellConsumption(hexToCells(hex));
|
|
6372
|
+
};
|
|
6373
|
+
|
|
6374
|
+
// src/common-ton/src/class/generators.ts
|
|
6375
|
+
var baseObjects = {
|
|
6376
|
+
POOO: {
|
|
6377
|
+
"0": {
|
|
6378
|
+
fieldName: "POOO::nextEmpty",
|
|
6379
|
+
fieldType: "cl::t::uint64"
|
|
6380
|
+
},
|
|
6381
|
+
"1": {
|
|
6382
|
+
fieldName: "POOO::bitmap",
|
|
6383
|
+
fieldType: "cl::t::cellRef"
|
|
6384
|
+
},
|
|
6385
|
+
name: "POOO"
|
|
6386
|
+
},
|
|
6387
|
+
BaseStorage: {
|
|
6388
|
+
"0": {
|
|
6389
|
+
fieldName: "BaseStorage::owner",
|
|
6390
|
+
fieldType: "cl::t::address"
|
|
6391
|
+
},
|
|
6392
|
+
"1": {
|
|
6393
|
+
fieldName: "BaseStorage::authenticated",
|
|
6394
|
+
fieldType: "cl::t::bool"
|
|
6395
|
+
},
|
|
6396
|
+
"2": {
|
|
6397
|
+
fieldName: "BaseStorage::initialized",
|
|
6398
|
+
fieldType: "cl::t::bool"
|
|
6399
|
+
},
|
|
6400
|
+
"3": {
|
|
6401
|
+
fieldName: "BaseStorage::initialStorage",
|
|
6402
|
+
fieldType: "cl::t::cellRef"
|
|
6403
|
+
},
|
|
6404
|
+
name: "baseStore"
|
|
6405
|
+
},
|
|
6406
|
+
"action::event": {
|
|
6407
|
+
"0": {
|
|
6408
|
+
fieldName: "action::event::topic",
|
|
6409
|
+
fieldType: "cl::t::uint256"
|
|
6410
|
+
},
|
|
6411
|
+
"1": {
|
|
6412
|
+
fieldName: "action::event::body",
|
|
6413
|
+
fieldType: "cl::t::objRef"
|
|
6414
|
+
},
|
|
6415
|
+
"2": {
|
|
6416
|
+
fieldName: "action::event::initialStorage",
|
|
6417
|
+
fieldType: "cl::t::objRef"
|
|
6418
|
+
},
|
|
6419
|
+
name: "event"
|
|
6420
|
+
}
|
|
6421
|
+
};
|
|
6422
|
+
var fieldTypes = [
|
|
6423
|
+
"cl::t::uint1",
|
|
6424
|
+
// 1 bit
|
|
6425
|
+
"cl::t::bool",
|
|
6426
|
+
// 1 bit
|
|
6427
|
+
"cl::t::uint2",
|
|
6428
|
+
// 2 bits
|
|
6429
|
+
"cl::t::uint4",
|
|
6430
|
+
// 4 bits
|
|
6431
|
+
"cl::t::uint8",
|
|
6432
|
+
// 8 bits
|
|
6433
|
+
"cl::t::uint16",
|
|
6434
|
+
// 16 bits
|
|
6435
|
+
"cl::t::uint32",
|
|
6436
|
+
// 32 bits
|
|
6437
|
+
"cl::t::uint64",
|
|
6438
|
+
// 64 bits
|
|
6439
|
+
"cl::t::uint128",
|
|
6440
|
+
// 128 bits
|
|
6441
|
+
"cl::t::coins",
|
|
6442
|
+
// 128 bits
|
|
6443
|
+
"cl::t::uint256",
|
|
6444
|
+
// 256 bits
|
|
6445
|
+
"cl::t::address",
|
|
6446
|
+
// 256 bits
|
|
6447
|
+
"cl::t::dict256",
|
|
6448
|
+
// cell
|
|
6449
|
+
"cl::t::cellRef",
|
|
6450
|
+
// cell
|
|
6451
|
+
"cl::t::objRef",
|
|
6452
|
+
// cell
|
|
6453
|
+
"cl::t::addressList"
|
|
6454
|
+
// cell
|
|
6455
|
+
];
|
|
6456
|
+
var isClassName = (_tonObjects, fieldType) => {
|
|
6457
|
+
return fieldType in _tonObjects;
|
|
6458
|
+
};
|
|
6459
|
+
var getClassNameAndDefinition = (_tonObjects) => (_className) => {
|
|
6460
|
+
let className = _className;
|
|
6461
|
+
let classDefinition = _tonObjects[className];
|
|
6462
|
+
if (!(className in _tonObjects)) {
|
|
6463
|
+
[className, classDefinition] = Object.entries(_tonObjects).find(
|
|
6464
|
+
([_, value]) => value.name === className
|
|
6465
|
+
);
|
|
6466
|
+
throw new Error(`Class ${className} not found`);
|
|
6467
|
+
}
|
|
6468
|
+
return { className, classDefinition };
|
|
6469
|
+
};
|
|
6470
|
+
var generateEncodeClass = (_tonObjects) => (_className, fields) => {
|
|
6471
|
+
const { className, classDefinition } = getClassNameAndDefinition(_tonObjects)(_className);
|
|
6472
|
+
const fieldsArray = Object.entries(classDefinition).filter(([_, field]) => typeof field !== "string");
|
|
6473
|
+
const results = Object.entries(fields).map(([fieldName, fieldValue]) => {
|
|
6474
|
+
const [index, field] = fieldsArray.find(
|
|
6475
|
+
([_, field2]) => field2.fieldName === `${className}::${fieldName}`
|
|
6476
|
+
);
|
|
6477
|
+
if (field.fieldType === "cl::t::dict256" && !(fieldValue instanceof core.Cell)) {
|
|
6478
|
+
return [
|
|
6479
|
+
Number(index),
|
|
6480
|
+
cl.t.objRef,
|
|
6481
|
+
fieldValue.rawCell ?? core.beginCell().storeDict(fieldValue).endCell().asSlice().loadRef()
|
|
6482
|
+
];
|
|
6483
|
+
}
|
|
6484
|
+
if (field.fieldType === "cl::t::addressList" && !(fieldValue instanceof core.Cell)) {
|
|
6485
|
+
return [
|
|
6486
|
+
Number(index),
|
|
6487
|
+
cl.t.objRef,
|
|
6488
|
+
serializeAddressList(fieldValue)
|
|
6489
|
+
];
|
|
6490
|
+
}
|
|
6491
|
+
if (isClassName(_tonObjects, field.fieldType) && !(fieldValue instanceof core.Cell)) {
|
|
6492
|
+
return [
|
|
6493
|
+
Number(index),
|
|
6494
|
+
cl.t.objRef,
|
|
6495
|
+
generateEncodeClass(_tonObjects)(
|
|
6496
|
+
field.fieldType,
|
|
6497
|
+
fieldValue
|
|
6498
|
+
)
|
|
6499
|
+
];
|
|
6500
|
+
}
|
|
6501
|
+
const typeMetadata = field.fieldType.split("cl::t::")[1];
|
|
6502
|
+
let tNumber;
|
|
6503
|
+
if (typeMetadata in cl.t) {
|
|
6504
|
+
tNumber = cl.t[typeMetadata];
|
|
6505
|
+
} else {
|
|
6506
|
+
tNumber = cl.t.objRef;
|
|
6507
|
+
}
|
|
6508
|
+
return [Number(index), tNumber, fieldValue, typeMetadata];
|
|
6509
|
+
}).sort(([a], [b]) => a - b).map(([_, type, value, typeMetadata]) => ({
|
|
6510
|
+
type,
|
|
6511
|
+
value,
|
|
6512
|
+
typeMetadata
|
|
6513
|
+
}));
|
|
6514
|
+
return clDeclare(asciiStringToBigint2(_tonObjects[className].name), results);
|
|
6515
|
+
};
|
|
6516
|
+
var generateDecodeClass = (_tonObjects) => (_className, cell) => {
|
|
6517
|
+
const { className, classDefinition } = getClassNameAndDefinition(_tonObjects)(_className);
|
|
6518
|
+
const enhanceCell = (cell2) => {
|
|
6519
|
+
return new Proxy(cell2, {
|
|
6520
|
+
get(target, prop) {
|
|
6521
|
+
if (prop === "getAddressList") {
|
|
6522
|
+
return () => enhanceAddressList(cell2);
|
|
6523
|
+
}
|
|
6524
|
+
if (prop === "cellsToHex") {
|
|
6525
|
+
return () => cellsToHex(cell2);
|
|
6526
|
+
}
|
|
6527
|
+
if (prop === "getDict") {
|
|
6528
|
+
return enhancedLoadDict(cell2).getDict;
|
|
6529
|
+
}
|
|
6530
|
+
if (prop === "decode") {
|
|
6531
|
+
return (className2) => generateDecodeClass(_tonObjects)(className2, cell2);
|
|
6532
|
+
}
|
|
6533
|
+
if (prop === "clGetCellRef") {
|
|
6534
|
+
return (index) => enhanceCell(clGetCellRef(cell2, index));
|
|
6535
|
+
}
|
|
6536
|
+
if (prop === "clGetUint") {
|
|
6537
|
+
return (index, width) => clGetUint(cell2, index, width);
|
|
6538
|
+
}
|
|
6539
|
+
if (prop === "getCellName") {
|
|
6540
|
+
return () => getCellName(cell2);
|
|
6541
|
+
}
|
|
6542
|
+
return Reflect.get(target, prop);
|
|
6543
|
+
}
|
|
6544
|
+
});
|
|
6545
|
+
};
|
|
6546
|
+
const injectRawCell = (value, rawCell) => {
|
|
6547
|
+
return new Proxy(value, {
|
|
6548
|
+
get(target, prop) {
|
|
6549
|
+
if (prop === "rawCell") {
|
|
6550
|
+
return enhanceCell(rawCell);
|
|
6551
|
+
}
|
|
6552
|
+
return Reflect.get(target, prop);
|
|
6553
|
+
}
|
|
6554
|
+
});
|
|
6555
|
+
};
|
|
6556
|
+
const enhanceAddress = (address) => {
|
|
6557
|
+
return new Proxy(bigintToAddress(address), {
|
|
6558
|
+
get(target, prop) {
|
|
6559
|
+
if (prop === "toHex") {
|
|
6560
|
+
return () => bigIntToHex(address);
|
|
6561
|
+
}
|
|
6562
|
+
if (prop === "toBigInt") {
|
|
6563
|
+
return () => address;
|
|
6564
|
+
}
|
|
6565
|
+
return Reflect.get(target, prop);
|
|
6566
|
+
}
|
|
6567
|
+
});
|
|
6568
|
+
};
|
|
6569
|
+
const enhanceAddressList = (rawCell) => {
|
|
6570
|
+
const addressList = deserializeAddressList(rawCell).map(enhanceAddress);
|
|
6571
|
+
return injectRawCell(
|
|
6572
|
+
new Proxy(addressList, {
|
|
6573
|
+
get(target, prop) {
|
|
6574
|
+
if (prop === "toHex") {
|
|
6575
|
+
return () => addressList.map((address) => address.toHex());
|
|
6576
|
+
}
|
|
6577
|
+
if (prop === "toBigInt") {
|
|
6578
|
+
return () => addressList.map((address) => address.toBigInt());
|
|
6579
|
+
}
|
|
6580
|
+
return Reflect.get(target, prop);
|
|
6581
|
+
}
|
|
6582
|
+
}),
|
|
6583
|
+
rawCell
|
|
6584
|
+
);
|
|
6585
|
+
};
|
|
6586
|
+
const enhancedLoadDict = (rawCell) => {
|
|
6587
|
+
return {
|
|
6588
|
+
getDict: (value) => {
|
|
6589
|
+
return rawCell.bits.length === 0 ? core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), value) : rawCell.beginParse().loadDictDirect(core.Dictionary.Keys.BigUint(256), value);
|
|
6590
|
+
},
|
|
6591
|
+
rawCell: enhanceCell(rawCell)
|
|
6592
|
+
};
|
|
6593
|
+
};
|
|
6594
|
+
return Object.fromEntries(
|
|
6595
|
+
Object.entries(classDefinition).filter(([_, field]) => typeof field !== "string").map(([index, field]) => {
|
|
6596
|
+
const tNumber = cl.t[field.fieldType.split("cl::t::")[1]];
|
|
6597
|
+
const fieldName = field.fieldName.split(`${className}::`)[1];
|
|
6598
|
+
if (field.fieldType in _tonObjects) {
|
|
6599
|
+
const rawCell = clGetCellRef(cell, Number(index));
|
|
6600
|
+
if (field.fieldType === baseObjects.POOO.name && emptyCell().hash().equals(rawCell.hash())) {
|
|
6601
|
+
return [
|
|
6602
|
+
fieldName,
|
|
6603
|
+
new Proxy(emptyPOOO(), {
|
|
6604
|
+
get(target, prop) {
|
|
6605
|
+
if (prop === "rawCell") {
|
|
6606
|
+
return enhanceCell(rawCell);
|
|
6607
|
+
}
|
|
6608
|
+
return Reflect.get(target, prop);
|
|
6609
|
+
}
|
|
6610
|
+
})
|
|
6611
|
+
];
|
|
6612
|
+
}
|
|
6613
|
+
return [
|
|
6614
|
+
fieldName,
|
|
6615
|
+
new Proxy(
|
|
6616
|
+
generateDecodeClass(_tonObjects)(field.fieldType, clGetCellRef(cell, Number(index))),
|
|
6617
|
+
{
|
|
6618
|
+
get(target, prop) {
|
|
6619
|
+
if (prop === "rawCell") {
|
|
6620
|
+
return enhanceCell(rawCell);
|
|
6621
|
+
}
|
|
6622
|
+
return Reflect.get(target, prop);
|
|
6623
|
+
}
|
|
6624
|
+
}
|
|
6625
|
+
)
|
|
6626
|
+
];
|
|
6627
|
+
}
|
|
6628
|
+
if (field.fieldType === "cl::t::addressList") {
|
|
6629
|
+
const rawCell = clGetCellRef(cell, Number(index));
|
|
6630
|
+
return [fieldName, enhanceAddressList(rawCell)];
|
|
6631
|
+
}
|
|
6632
|
+
if (field.fieldType === "cl::t::dict256") {
|
|
6633
|
+
return [fieldName, enhancedLoadDict(clGetCellRef(cell, Number(index)))];
|
|
6634
|
+
}
|
|
6635
|
+
if (tNumber === cl.t.objRef) {
|
|
6636
|
+
return [fieldName, enhanceCell(clGetCellRef(cell, Number(index)))];
|
|
6637
|
+
}
|
|
6638
|
+
if (field.fieldType === "cl::t::address") {
|
|
6639
|
+
return [fieldName, enhanceAddress(clGetUint(cell, Number(index), _getTypeWidth(tNumber)))];
|
|
6640
|
+
}
|
|
6641
|
+
if (field.fieldType === "cl::t::bool") {
|
|
6642
|
+
return [fieldName, clGetUint(cell, Number(index), _getTypeWidth(tNumber)) === 1n];
|
|
6643
|
+
}
|
|
6644
|
+
return [fieldName, clGetUint(cell, Number(index), _getTypeWidth(tNumber))];
|
|
6645
|
+
})
|
|
6646
|
+
);
|
|
6647
|
+
};
|
|
6648
|
+
var baseEncodeClass = generateEncodeClass(baseObjects);
|
|
6649
|
+
var baseDecodeClass = generateDecodeClass(baseObjects);
|
|
6650
|
+
|
|
6651
|
+
// src/common-ton/src/class/helpers.ts
|
|
6652
|
+
var asciiStringToBigint2 = (target) => {
|
|
6653
|
+
return BigInt(`0x${Buffer.from(target).toString("hex")}`);
|
|
6654
|
+
};
|
|
6655
|
+
var bigintToAsciiString = (target) => {
|
|
6656
|
+
return Buffer.from(target.toString(16), "hex").toString("ascii");
|
|
6657
|
+
};
|
|
6658
|
+
var getCellNameNumber = (cell) => {
|
|
6659
|
+
const slice = cell.beginParse();
|
|
6660
|
+
const name = slice.loadUintBig(NAME_WIDTH);
|
|
6661
|
+
return name;
|
|
6662
|
+
};
|
|
6663
|
+
var getCellName = (cell) => {
|
|
6664
|
+
const nameNumber = getCellNameNumber(cell);
|
|
6665
|
+
return bigintToAsciiString(nameNumber);
|
|
6666
|
+
};
|
|
6667
|
+
var emptyCell = () => {
|
|
6668
|
+
return core.beginCell().asCell();
|
|
6669
|
+
};
|
|
6670
|
+
var nullObject = () => {
|
|
6671
|
+
return emptyCell();
|
|
6672
|
+
};
|
|
6673
|
+
var emptyMap = () => {
|
|
6674
|
+
return emptyCell();
|
|
6675
|
+
};
|
|
6676
|
+
var emptyPOOO = () => {
|
|
6677
|
+
return baseEncodeClass("POOO", {
|
|
6678
|
+
nextEmpty: 1,
|
|
6679
|
+
bitmap: (() => {
|
|
6680
|
+
const builder = new core.BitBuilder(MAX_CELL_BITS);
|
|
6681
|
+
builder.writeUint(0, 1023);
|
|
6682
|
+
const bitString = builder.build();
|
|
6683
|
+
const bitReader = new core.BitReader(bitString);
|
|
6684
|
+
const slice = new core.Slice(bitReader, []);
|
|
6685
|
+
return slice.asCell();
|
|
6686
|
+
})()
|
|
6687
|
+
});
|
|
6688
|
+
};
|
|
6689
|
+
var initBaseStorage = (owner) => {
|
|
6690
|
+
return baseEncodeClass("BaseStorage", {
|
|
6691
|
+
owner,
|
|
6692
|
+
authenticated: false,
|
|
6693
|
+
initialized: false,
|
|
6694
|
+
initialStorage: emptyCell()
|
|
6695
|
+
});
|
|
6696
|
+
};
|
|
6697
|
+
function serializeAddressList(addresses) {
|
|
6698
|
+
if (addresses instanceof core.Cell) {
|
|
6699
|
+
return addresses;
|
|
6700
|
+
}
|
|
6701
|
+
const addressListBuilder = [core.beginCell()];
|
|
6702
|
+
for (let idx = 0; idx < addresses.length; idx++) {
|
|
6703
|
+
if (addressListBuilder[addressListBuilder.length - 1].availableBits < 256) {
|
|
6704
|
+
addressListBuilder.push(core.beginCell());
|
|
6705
|
+
}
|
|
6706
|
+
addressListBuilder[addressListBuilder.length - 1].storeUint(addressToBigInt(addresses[idx]), 256);
|
|
6707
|
+
}
|
|
6708
|
+
let resultCell = addressListBuilder.pop().endCell();
|
|
6709
|
+
while (addressListBuilder.length > 0) {
|
|
6710
|
+
const head = addressListBuilder.pop();
|
|
6711
|
+
resultCell = head.storeRef(resultCell).endCell();
|
|
6712
|
+
}
|
|
6713
|
+
return resultCell;
|
|
6714
|
+
}
|
|
6715
|
+
function deserializeAddressList(cell) {
|
|
6716
|
+
const addresses = [];
|
|
6717
|
+
let currentCell = cell;
|
|
6718
|
+
while (currentCell) {
|
|
6719
|
+
const slice = currentCell.beginParse();
|
|
6720
|
+
while (slice.remainingBits >= 256) {
|
|
6721
|
+
addresses.push(slice.loadUintBig(256));
|
|
6722
|
+
}
|
|
6723
|
+
currentCell = slice.remainingRefs > 0 ? slice.loadRef() : null;
|
|
6724
|
+
}
|
|
6725
|
+
return addresses;
|
|
6726
|
+
}
|
|
6727
|
+
function serializePayees(payeesInfo) {
|
|
6728
|
+
const numPayees = payeesInfo.length;
|
|
6729
|
+
if (numPayees === 0) {
|
|
6730
|
+
return emptyCell();
|
|
6731
|
+
}
|
|
6732
|
+
let linkedList = core.beginCell();
|
|
6733
|
+
let idx = 1;
|
|
6734
|
+
while (idx <= numPayees) {
|
|
6735
|
+
const curPayee = payeesInfo[numPayees - idx];
|
|
6736
|
+
if (idx % 3 === 0) {
|
|
6737
|
+
linkedList = core.beginCell().storeRef(linkedList.endCell()).storeUint(addressToBigInt(curPayee.address), 256).storeUint(BigInt(curPayee.amount), 64);
|
|
6738
|
+
} else {
|
|
6739
|
+
linkedList = linkedList.storeUint(addressToBigInt(curPayee.address), 256).storeUint(BigInt(curPayee.amount), 64);
|
|
6740
|
+
}
|
|
6741
|
+
idx += 1;
|
|
6742
|
+
}
|
|
6743
|
+
return linkedList.endCell();
|
|
6744
|
+
}
|
|
6745
|
+
function deserializePayees(serializedPayees) {
|
|
6746
|
+
let payeesSlice = serializedPayees.beginParse();
|
|
6747
|
+
if (payeesSlice.remainingBits === 0) {
|
|
6748
|
+
return [];
|
|
6749
|
+
}
|
|
6750
|
+
const payees = [];
|
|
6751
|
+
const payeeBits = 256 + 64;
|
|
6752
|
+
while (payeesSlice.remainingBits >= payeeBits || payeesSlice.remainingRefs > 0) {
|
|
6753
|
+
if (payeesSlice.remainingBits >= payeeBits) {
|
|
6754
|
+
payees.push({
|
|
6755
|
+
address: addressToHex(payeesSlice.loadUintBig(256)),
|
|
6756
|
+
amount: payeesSlice.loadUintBig(64)
|
|
6757
|
+
});
|
|
6758
|
+
} else if (payeesSlice.remainingRefs > 0) {
|
|
6759
|
+
payeesSlice = payeesSlice.loadRef().beginParse();
|
|
6760
|
+
} else {
|
|
6761
|
+
break;
|
|
6762
|
+
}
|
|
6763
|
+
}
|
|
6764
|
+
return payees;
|
|
6765
|
+
}
|
|
6766
|
+
|
|
6767
|
+
// src/common-ton/src/class/class.ts
|
|
6768
|
+
var cl = {
|
|
6769
|
+
t: {
|
|
6770
|
+
uint1: 0,
|
|
6771
|
+
bool: 0,
|
|
6772
|
+
// same as uint1
|
|
6773
|
+
uint2: 1,
|
|
6774
|
+
uint4: 2,
|
|
6775
|
+
uint8: 3,
|
|
6776
|
+
uint16: 4,
|
|
6777
|
+
uint32: 5,
|
|
6778
|
+
uint64: 6,
|
|
6779
|
+
uint128: 7,
|
|
6780
|
+
coins: 7,
|
|
6781
|
+
// same as uint128
|
|
6782
|
+
uint256: 8,
|
|
6783
|
+
address: 8,
|
|
6784
|
+
// same as uint256
|
|
6785
|
+
cellRef: 9,
|
|
6786
|
+
// same as cellRef
|
|
6787
|
+
dict256: 9,
|
|
6788
|
+
// same as cellRef
|
|
6789
|
+
objRef: 9,
|
|
6790
|
+
// same as cellRef
|
|
6791
|
+
addressList: 9
|
|
6792
|
+
// same as cellRef
|
|
6793
|
+
},
|
|
6794
|
+
NULL_CLASS_NAME: "NULL",
|
|
6795
|
+
ERROR: {
|
|
6796
|
+
INVALID_CLASS: "INVALID_CLASS"
|
|
6797
|
+
}
|
|
6798
|
+
};
|
|
6799
|
+
var MAX_NAME_LEN = 10;
|
|
6800
|
+
var NAME_WIDTH = 8 * MAX_NAME_LEN;
|
|
6801
|
+
var FIELD_TYPE_WIDTH = 4;
|
|
6802
|
+
var CELL_ID_WIDTH = 2;
|
|
6803
|
+
var DATA_OFFSET_WIDTH = 10;
|
|
6804
|
+
var REF_OFFSET_WIDTH = 2;
|
|
6805
|
+
var FIELD_INFO_WIDTH = FIELD_TYPE_WIDTH + CELL_ID_WIDTH + DATA_OFFSET_WIDTH + REF_OFFSET_WIDTH;
|
|
6806
|
+
var MAX_CLASS_FIELDS = 15;
|
|
6807
|
+
var BASIC_HEADER_WIDTH = NAME_WIDTH;
|
|
6808
|
+
var HEADER_WIDTH = BASIC_HEADER_WIDTH + MAX_CLASS_FIELDS * FIELD_INFO_WIDTH;
|
|
6809
|
+
var MAX_CELL_BITS = 1023;
|
|
6810
|
+
var MAX_CELL_REFS = 4;
|
|
6811
|
+
var numberTypeLikeToAbsBigInt = (val, typeMetadata) => {
|
|
6812
|
+
if (val instanceof core.Address) {
|
|
6813
|
+
return addressToBigInt(val);
|
|
6814
|
+
}
|
|
6815
|
+
if (typeof val === "string") {
|
|
6816
|
+
if (core.Address.isFriendly(val) || core.Address.isRaw(val)) {
|
|
6817
|
+
return addressToBigInt(core.Address.parse(val));
|
|
6818
|
+
}
|
|
6819
|
+
if (typeMetadata === "address") {
|
|
6820
|
+
try {
|
|
6821
|
+
return BigInt("0x0" + val.substring(2));
|
|
6822
|
+
} catch {
|
|
6823
|
+
}
|
|
6824
|
+
}
|
|
6825
|
+
}
|
|
6826
|
+
const _val = BigInt(val);
|
|
6827
|
+
if (_val < -1n) {
|
|
6828
|
+
throw new Error("Invalid value. Only accepted negative value is -1");
|
|
6829
|
+
}
|
|
6830
|
+
return _val < 0 ? -_val : _val;
|
|
6831
|
+
};
|
|
6832
|
+
var _getTypeWidth = (clType) => {
|
|
6833
|
+
if (clType <= cl.t.uint256) {
|
|
6834
|
+
return 1 << clType;
|
|
6835
|
+
}
|
|
6836
|
+
return 0;
|
|
6837
|
+
};
|
|
6838
|
+
var isNumericType = (field) => {
|
|
6839
|
+
return field.type <= cl.t.uint256;
|
|
6840
|
+
};
|
|
6841
|
+
var isCellType = (field) => {
|
|
6842
|
+
return field.type == cl.t.cellRef;
|
|
6843
|
+
};
|
|
6844
|
+
var clDeclare = (name, fields) => {
|
|
6845
|
+
if (fields.length > MAX_CLASS_FIELDS) {
|
|
6846
|
+
throw new Error(cl.ERROR.INVALID_CLASS);
|
|
6847
|
+
}
|
|
6848
|
+
const classBuilder = [null, core.beginCell()];
|
|
6849
|
+
let headerBuilder = core.beginCell().storeUint(name, NAME_WIDTH);
|
|
6850
|
+
let curDataCell = 1;
|
|
6851
|
+
let curRefCell = 1;
|
|
6852
|
+
let curCellMaxRefs = 2;
|
|
6853
|
+
let curDataOffset = HEADER_WIDTH;
|
|
6854
|
+
let curRefOffset = 0;
|
|
6855
|
+
for (const field of fields) {
|
|
6856
|
+
const fieldBits = _getTypeWidth(field.type);
|
|
6857
|
+
if (curDataOffset + fieldBits > MAX_CELL_BITS) {
|
|
6858
|
+
curDataCell += 1;
|
|
6859
|
+
curDataOffset = 0;
|
|
6860
|
+
if (curDataCell >= classBuilder.length) {
|
|
6861
|
+
classBuilder.push(core.beginCell());
|
|
6862
|
+
}
|
|
6863
|
+
}
|
|
6864
|
+
if (fieldBits == 0) {
|
|
6865
|
+
if (curRefOffset + 1 > curCellMaxRefs) {
|
|
6866
|
+
curRefCell += 1;
|
|
6867
|
+
curRefOffset = 0;
|
|
6868
|
+
curCellMaxRefs = MAX_CELL_REFS;
|
|
6869
|
+
if (curRefCell >= classBuilder.length) {
|
|
6870
|
+
classBuilder.push(core.beginCell());
|
|
6871
|
+
}
|
|
6872
|
+
}
|
|
6873
|
+
}
|
|
6874
|
+
if (isNumericType(field)) {
|
|
6875
|
+
classBuilder[curDataCell] = classBuilder[curDataCell].storeUint(
|
|
6876
|
+
numberTypeLikeToAbsBigInt(field.value, field.typeMetadata),
|
|
6877
|
+
fieldBits
|
|
6878
|
+
);
|
|
6879
|
+
} else if (isCellType(field)) {
|
|
6880
|
+
classBuilder[curRefCell] = classBuilder[curRefCell].storeRef(field.value);
|
|
6881
|
+
} else {
|
|
6882
|
+
throw new Error(cl.ERROR.INVALID_CLASS);
|
|
6883
|
+
}
|
|
6884
|
+
headerBuilder = headerBuilder.storeUint(field.type, FIELD_TYPE_WIDTH);
|
|
6885
|
+
if (fieldBits > 0) {
|
|
6886
|
+
headerBuilder = headerBuilder.storeUint(curDataCell == 1 ? 0 : curDataCell, CELL_ID_WIDTH).storeUint(curDataOffset, DATA_OFFSET_WIDTH).storeUint(3, REF_OFFSET_WIDTH);
|
|
6887
|
+
curDataOffset += fieldBits;
|
|
6888
|
+
} else {
|
|
6889
|
+
headerBuilder = headerBuilder.storeUint(curRefCell == 1 ? 0 : curRefCell, CELL_ID_WIDTH).storeUint(MAX_CELL_BITS, DATA_OFFSET_WIDTH).storeUint(curRefOffset, REF_OFFSET_WIDTH);
|
|
6890
|
+
curRefOffset += 1;
|
|
6891
|
+
}
|
|
6892
|
+
}
|
|
6893
|
+
let rootBuilder = classBuilder[1];
|
|
6894
|
+
const numCells = classBuilder.length - 1;
|
|
6895
|
+
if (numCells > 1) {
|
|
6896
|
+
if (rootBuilder.refs == 0) {
|
|
6897
|
+
rootBuilder = rootBuilder.storeRef(emptyCell()).storeRef(emptyCell());
|
|
6898
|
+
} else if (rootBuilder.refs == 1) {
|
|
6899
|
+
rootBuilder = rootBuilder.storeRef(emptyCell());
|
|
6900
|
+
}
|
|
6901
|
+
}
|
|
6902
|
+
const trailingOnes = HEADER_WIDTH - headerBuilder.bits;
|
|
6903
|
+
headerBuilder = headerBuilder.storeBits(new core.BitString(Buffer.from("F".repeat(trailingOnes), "hex"), 0, trailingOnes)).storeBuilder(rootBuilder);
|
|
6904
|
+
if (numCells == 1) {
|
|
6905
|
+
return headerBuilder.endCell();
|
|
6906
|
+
}
|
|
6907
|
+
if (numCells == 2) {
|
|
6908
|
+
return headerBuilder.storeRef(classBuilder[2].endCell()).endCell();
|
|
6909
|
+
}
|
|
6910
|
+
return headerBuilder.storeRef(classBuilder[2].endCell()).storeRef(classBuilder[3].endCell()).endCell();
|
|
6911
|
+
};
|
|
6912
|
+
var loadFieldInfo = (cell, fieldName) => {
|
|
6913
|
+
const headerSlice = cell.beginParse();
|
|
6914
|
+
const fieldInfoOffset = BASIC_HEADER_WIDTH + fieldName * FIELD_INFO_WIDTH;
|
|
6915
|
+
headerSlice.skip(fieldInfoOffset + FIELD_TYPE_WIDTH);
|
|
6916
|
+
const fieldCellIndex = headerSlice.loadUint(CELL_ID_WIDTH);
|
|
6917
|
+
const fieldOffset = headerSlice.loadUint(DATA_OFFSET_WIDTH);
|
|
6918
|
+
const fieldRefIdx = headerSlice.loadUint(REF_OFFSET_WIDTH);
|
|
6919
|
+
return { fieldCellIndex, fieldOffset, fieldRefIdx };
|
|
6920
|
+
};
|
|
6921
|
+
var clGetUint = (cell, fieldName, width) => {
|
|
6922
|
+
const headerSlice = cell.beginParse();
|
|
6923
|
+
const { fieldCellIndex, fieldOffset } = loadFieldInfo(cell, fieldName);
|
|
6924
|
+
if (fieldCellIndex == 0) {
|
|
6925
|
+
return headerSlice.skip(fieldOffset).loadUintBig(width);
|
|
6926
|
+
}
|
|
6927
|
+
for (let i = 0; i < fieldCellIndex; i++) {
|
|
6928
|
+
headerSlice.loadRef();
|
|
6929
|
+
}
|
|
6930
|
+
return headerSlice.loadRef().beginParse().skip(fieldOffset).loadUintBig(width);
|
|
6931
|
+
};
|
|
6932
|
+
var clGetCellRef = (cell, fieldName) => {
|
|
6933
|
+
const headerSlice = cell.beginParse();
|
|
6934
|
+
const { fieldCellIndex, fieldRefIdx } = loadFieldInfo(cell, fieldName);
|
|
6935
|
+
if (fieldCellIndex == 0) {
|
|
6936
|
+
for (let i = 0; i < fieldRefIdx; i++) {
|
|
6937
|
+
headerSlice.loadRef();
|
|
6938
|
+
}
|
|
6939
|
+
return headerSlice.loadRef();
|
|
6940
|
+
}
|
|
6941
|
+
for (let i = 0; i < fieldCellIndex; i++) {
|
|
6942
|
+
headerSlice.loadRef();
|
|
6943
|
+
}
|
|
6944
|
+
const cellRef = headerSlice.loadRef().beginParse();
|
|
6945
|
+
for (let i = 0; i < fieldRefIdx; i++) {
|
|
6946
|
+
cellRef.loadRef();
|
|
6947
|
+
}
|
|
6948
|
+
return cellRef.loadRef();
|
|
6949
|
+
};
|
|
6950
|
+
var deepDecode = (decodeClass, cell, hashUndecodeable) => {
|
|
6951
|
+
if (!(cell instanceof core.Cell)) {
|
|
6952
|
+
return cell;
|
|
6953
|
+
}
|
|
6954
|
+
try {
|
|
6955
|
+
const decoded = decodeClass(getCellName(cell), cell);
|
|
6956
|
+
return Object.fromEntries(
|
|
6957
|
+
//cell was decoded successfully, recurse
|
|
6958
|
+
Object.entries(decoded).map(([k, v]) => [
|
|
6959
|
+
k,
|
|
6960
|
+
deepDecode(decodeClass, v, hashUndecodeable)
|
|
6961
|
+
])
|
|
6962
|
+
);
|
|
6963
|
+
} catch (e) {
|
|
6964
|
+
return hashUndecodeable === true ? cell.hash().toString("hex") : cell;
|
|
6965
|
+
}
|
|
6966
|
+
};
|
|
6967
|
+
var printDeepDecode = (decodeClass, cell) => {
|
|
6968
|
+
console.log(
|
|
6969
|
+
JSON.stringify(
|
|
6970
|
+
deepDecode(decodeClass, cell, true),
|
|
6971
|
+
(_, v) => {
|
|
6972
|
+
if (typeof v === "bigint") {
|
|
6973
|
+
return v.toString();
|
|
6974
|
+
}
|
|
6975
|
+
if (v instanceof core.Address) {
|
|
6976
|
+
return addressToHex(v);
|
|
6977
|
+
}
|
|
6978
|
+
return v;
|
|
6979
|
+
},
|
|
6980
|
+
2
|
|
6981
|
+
)
|
|
6982
|
+
);
|
|
6983
|
+
};
|
|
6984
|
+
|
|
6985
|
+
// src/common-ton/src/deepDiffCells.ts
|
|
6986
|
+
var diffRecurse = (cellA, cellB, ancestry) => {
|
|
6987
|
+
if (cellA === cellB) {
|
|
6988
|
+
return [];
|
|
6989
|
+
}
|
|
6990
|
+
if (typeof cellA !== "object" || typeof cellB !== "object") {
|
|
6991
|
+
return [{ a: cellA, b: cellB, ancestry }];
|
|
6992
|
+
}
|
|
6993
|
+
const cellAKeysSet = new Set(Object.keys(cellA));
|
|
6994
|
+
return [
|
|
6995
|
+
...Object.keys(cellA).map(
|
|
6996
|
+
(cellAKey) => diffRecurse(cellA[cellAKey], cellB[cellAKey], ancestry.concat(cellAKey))
|
|
6997
|
+
),
|
|
6998
|
+
...Object.keys(cellB).filter((k) => !cellAKeysSet.has(k)).map((cellBKey) => {
|
|
6999
|
+
return diffRecurse(cellA[cellBKey], cellB[cellBKey], ancestry.concat(cellBKey));
|
|
7000
|
+
})
|
|
7001
|
+
].flat();
|
|
7002
|
+
};
|
|
7003
|
+
var deepDiff = (decodeClass, cellA, cellB) => {
|
|
7004
|
+
const decodedA = deepDecode(decodeClass, cellA, true);
|
|
7005
|
+
const decodedB = deepDecode(decodeClass, cellB, true);
|
|
7006
|
+
const recursed = diffRecurse(decodedA, decodedB, ["diff_root"]);
|
|
7007
|
+
return { isEqual: recursed.length === 0, inequalValues: recursed };
|
|
7008
|
+
};
|
|
7009
|
+
var printDeepDiff = (decodeClass, cellA, cellB) => {
|
|
7010
|
+
console.log(
|
|
7011
|
+
JSON.stringify(
|
|
7012
|
+
deepDiff(decodeClass, cellA, cellB),
|
|
7013
|
+
(_, v) => typeof v === "bigint" ? v.toString() : v,
|
|
7014
|
+
2
|
|
7015
|
+
)
|
|
7016
|
+
);
|
|
7017
|
+
};
|
|
6210
7018
|
|
|
6211
7019
|
exports.BASE_CHAIN_ID = BASE_CHAIN_ID;
|
|
6212
7020
|
exports.BaseWrapper = BaseWrapper;
|
|
@@ -6216,24 +7024,51 @@ exports.JettonMinter = JettonMinter;
|
|
|
6216
7024
|
exports.JettonWallet = JettonWallet;
|
|
6217
7025
|
exports.MASTER_CHAIN_ID = MASTER_CHAIN_ID;
|
|
6218
7026
|
exports.MASTER_CHAIN_SHARD = MASTER_CHAIN_SHARD;
|
|
7027
|
+
exports.MAX_CELL_BITS = MAX_CELL_BITS;
|
|
6219
7028
|
exports.MultiSigErrors = MultiSigErrors;
|
|
6220
7029
|
exports.MultiSigOpCodes = MultiSigOpCodes;
|
|
6221
7030
|
exports.MultiSigParams = MultiSigParams;
|
|
6222
7031
|
exports.Multisig = Multisig;
|
|
7032
|
+
exports.NAME_WIDTH = NAME_WIDTH;
|
|
6223
7033
|
exports.Op = Op;
|
|
6224
7034
|
exports.Order = Order;
|
|
7035
|
+
exports.PUBLIC_KEY_BYTE_LENGTH = PUBLIC_KEY_BYTE_LENGTH;
|
|
6225
7036
|
exports.Txiterator = Txiterator;
|
|
7037
|
+
exports._getTypeWidth = _getTypeWidth;
|
|
6226
7038
|
exports.addressToBigInt = addressToBigInt;
|
|
7039
|
+
exports.addressToHex = addressToHex;
|
|
7040
|
+
exports.asciiStringToBigint = asciiStringToBigint2;
|
|
7041
|
+
exports.baseDecodeClass = baseDecodeClass;
|
|
7042
|
+
exports.baseEncodeClass = baseEncodeClass;
|
|
7043
|
+
exports.bigIntToHex = bigIntToHex;
|
|
6227
7044
|
exports.bigintToAddress = bigintToAddress;
|
|
7045
|
+
exports.bigintToAsciiString = bigintToAsciiString;
|
|
6228
7046
|
exports.buildOnchainMetadata = buildOnchainMetadata;
|
|
7047
|
+
exports.calculateCellConsumption = calculateCellConsumption;
|
|
7048
|
+
exports.calculateCellConsumptionFromHex = calculateCellConsumptionFromHex;
|
|
6229
7049
|
exports.cellFromArtifact = cellFromArtifact;
|
|
7050
|
+
exports.cellsToHex = cellsToHex;
|
|
7051
|
+
exports.cl = cl;
|
|
7052
|
+
exports.clDeclare = clDeclare;
|
|
7053
|
+
exports.clGetCellRef = clGetCellRef;
|
|
7054
|
+
exports.clGetUint = clGetUint;
|
|
7055
|
+
exports.compareAddresses = compareAddresses;
|
|
6230
7056
|
exports.computedGeneric = computedGeneric;
|
|
7057
|
+
exports.createVerifierDictSet = createVerifierDictSet;
|
|
7058
|
+
exports.deepDecode = deepDecode;
|
|
7059
|
+
exports.deepDiff = deepDiff;
|
|
7060
|
+
exports.deserializeAddressList = deserializeAddressList;
|
|
7061
|
+
exports.deserializePayees = deserializePayees;
|
|
6231
7062
|
exports.differentAddress = differentAddress;
|
|
7063
|
+
exports.emptyCell = emptyCell;
|
|
7064
|
+
exports.emptyMap = emptyMap;
|
|
7065
|
+
exports.emptyPOOO = emptyPOOO;
|
|
6232
7066
|
exports.executeFrom = executeFrom;
|
|
6233
7067
|
exports.executeTill = executeTill;
|
|
6234
7068
|
exports.extractErrors = extractErrors;
|
|
6235
7069
|
exports.extractEvents = extractEvents;
|
|
6236
7070
|
exports.extractOpcodes = extractOpcodes;
|
|
7071
|
+
exports.fieldTypes = fieldTypes;
|
|
6237
7072
|
exports.findDeepestCell = findDeepestCell;
|
|
6238
7073
|
exports.findTransaction = findTransaction;
|
|
6239
7074
|
exports.formatCoinsPure = formatCoinsPure;
|
|
@@ -6243,25 +7078,44 @@ exports.generateAllTonClassTypes = generateAllTonClassTypes;
|
|
|
6243
7078
|
exports.generateAllViewFunctions = generateAllViewFunctions;
|
|
6244
7079
|
exports.generateCommonTestUtils = generateCommonTestUtils;
|
|
6245
7080
|
exports.generateConstructorCode = generateConstructorCode;
|
|
7081
|
+
exports.generateDecodeClass = generateDecodeClass;
|
|
6246
7082
|
exports.generateDeconstructorCode = generateDeconstructorCode;
|
|
7083
|
+
exports.generateEncodeClass = generateEncodeClass;
|
|
6247
7084
|
exports.generateSmlTestUtils = generateSmlTestUtils;
|
|
6248
7085
|
exports.generateTonClassType = generateTonClassType;
|
|
6249
7086
|
exports.generateUlnTestUtils = generateUlnTestUtils;
|
|
7087
|
+
exports.getBocStringFromMessage = getBocStringFromMessage;
|
|
7088
|
+
exports.getCellName = getCellName;
|
|
7089
|
+
exports.getCellNameNumber = getCellNameNumber;
|
|
7090
|
+
exports.getClosestByteAlignedBits = getClosestByteAlignedBits;
|
|
7091
|
+
exports.getMessageFromBocString = getMessageFromBocString;
|
|
6250
7092
|
exports.getMsgPrices = getMsgPrices;
|
|
6251
7093
|
exports.getOpcodeCRC = getOpcodeCRC;
|
|
6252
7094
|
exports.getRandom = getRandom;
|
|
6253
7095
|
exports.getRandomInt = getRandomInt;
|
|
6254
7096
|
exports.getSpecificFiles = getSpecificFiles;
|
|
7097
|
+
exports.getTonWalletFromMnemonic = getTonWalletFromMnemonic;
|
|
7098
|
+
exports.getTonWalletFromMnemonicLegacy = getTonWalletFromMnemonicLegacy;
|
|
7099
|
+
exports.getTotalBits = getTotalBits;
|
|
7100
|
+
exports.hexToCells = hexToCells;
|
|
7101
|
+
exports.initBaseStorage = initBaseStorage;
|
|
7102
|
+
exports.isClassName = isClassName;
|
|
6255
7103
|
exports.jettonContentToCell = jettonContentToCell;
|
|
6256
7104
|
exports.jettonMinterConfigToCell = jettonMinterConfigToCell;
|
|
6257
7105
|
exports.jettonWalletConfigToCell = jettonWalletConfigToCell;
|
|
6258
7106
|
exports.makeSnakeCell = makeSnakeCell;
|
|
6259
7107
|
exports.mergeConstructorDicts = mergeConstructorDicts;
|
|
6260
7108
|
exports.multisigConfigToCell = multisigConfigToCell;
|
|
7109
|
+
exports.nullObject = nullObject;
|
|
7110
|
+
exports.numberTypeLikeToAbsBigInt = numberTypeLikeToAbsBigInt;
|
|
6261
7111
|
exports.openAndDeployAllStoragesTemplate = openAndDeployAllStoragesTemplate;
|
|
6262
7112
|
exports.orderConfigToCell = orderConfigToCell;
|
|
6263
7113
|
exports.parseDirectory = parseDirectory;
|
|
7114
|
+
exports.parseTonAddress = parseTonAddress;
|
|
7115
|
+
exports.printDeepDecode = printDeepDecode;
|
|
7116
|
+
exports.printDeepDiff = printDeepDiff;
|
|
6264
7117
|
exports.printTransactionTrace = printTransactionTrace;
|
|
7118
|
+
exports.publicKeyToHash = publicKeyToHash;
|
|
6265
7119
|
exports.saveAllTypes = saveAllTypes;
|
|
6266
7120
|
exports.saveBaseEventHandler = saveBaseEventHandler;
|
|
6267
7121
|
exports.saveConstantsFile = saveConstantsFile;
|
|
@@ -6274,10 +7128,14 @@ exports.saveTonObjectUnwrapper = saveTonObjectUnwrapper;
|
|
|
6274
7128
|
exports.saveViewFunctions = saveViewFunctions;
|
|
6275
7129
|
exports.sendInternalMessageAndExpect = sendInternalMessageAndExpect;
|
|
6276
7130
|
exports.sendMessageViaMultisigAndExpect = sendMessageViaMultisigAndExpect;
|
|
7131
|
+
exports.serializeAddressList = serializeAddressList;
|
|
7132
|
+
exports.serializePayees = serializePayees;
|
|
6277
7133
|
exports.setLzTonSdkSaveToJson = setLzTonSdkSaveToJson;
|
|
6278
7134
|
exports.setLzTonSdkWriteToConsole = setLzTonSdkWriteToConsole;
|
|
6279
7135
|
exports.storageCollected = storageCollected;
|
|
6280
7136
|
exports.to32ByteBuffer = to32ByteBuffer;
|
|
6281
7137
|
exports.toHaveTransactions = toHaveTransactions;
|
|
7138
|
+
exports.toPathArray = toPathArray;
|
|
7139
|
+
exports.trim0x = trim0x;
|
|
6282
7140
|
//# sourceMappingURL=index.cjs.map
|
|
6283
7141
|
//# sourceMappingURL=index.cjs.map
|