@ton/sandbox 0.21.0 → 0.22.0-ecbeta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/blockchain/Blockchain.d.ts +5 -0
- package/dist/blockchain/Blockchain.js +7 -0
- package/dist/blockchain/SmartContract.d.ts +4 -0
- package/dist/blockchain/SmartContract.js +33 -0
- package/dist/utils/message.d.ts +2 -1
- package/dist/utils/message.js +13 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.22.0] - 2024-09-17
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Added `blockchain.recordStorage` flag. If set to `true`, `BlockchainTransaction` will have `oldStorage` and `newStorage` fields. Note that enabling this flag will disable a certain optimization, which will slow down contract emulation
|
|
13
|
+
|
|
8
14
|
## [0.21.0] - 2024-09-16
|
|
9
15
|
|
|
10
16
|
### Added
|
|
@@ -26,6 +26,8 @@ export type BlockchainTransaction = Transaction & {
|
|
|
26
26
|
parent?: BlockchainTransaction;
|
|
27
27
|
children: BlockchainTransaction[];
|
|
28
28
|
externals: ExternalOut[];
|
|
29
|
+
oldStorage?: Cell;
|
|
30
|
+
newStorage?: Cell;
|
|
29
31
|
};
|
|
30
32
|
/**
|
|
31
33
|
* @type SendMessageResult Represents the result of sending a message.
|
|
@@ -98,6 +100,7 @@ export declare class Blockchain {
|
|
|
98
100
|
protected lock: AsyncLock;
|
|
99
101
|
protected contractFetches: Map<string, Promise<SmartContract>>;
|
|
100
102
|
protected nextCreateWalletIndex: number;
|
|
103
|
+
protected shouldRecordStorage: boolean;
|
|
101
104
|
readonly executor: IExecutor;
|
|
102
105
|
/**
|
|
103
106
|
* Saves snapshot of current blockchain.
|
|
@@ -115,6 +118,8 @@ export declare class Blockchain {
|
|
|
115
118
|
* @param snapshot Snapshot of blockchain
|
|
116
119
|
*/
|
|
117
120
|
loadFrom(snapshot: BlockchainSnapshot): Promise<void>;
|
|
121
|
+
get recordStorage(): boolean;
|
|
122
|
+
set recordStorage(v: boolean);
|
|
118
123
|
/**
|
|
119
124
|
* @returns Current time in blockchain
|
|
120
125
|
*/
|
|
@@ -81,6 +81,12 @@ class Blockchain {
|
|
|
81
81
|
this.globalLibs = snapshot.libs;
|
|
82
82
|
this.nextCreateWalletIndex = snapshot.nextCreateWalletIndex;
|
|
83
83
|
}
|
|
84
|
+
get recordStorage() {
|
|
85
|
+
return this.shouldRecordStorage;
|
|
86
|
+
}
|
|
87
|
+
set recordStorage(v) {
|
|
88
|
+
this.shouldRecordStorage = v;
|
|
89
|
+
}
|
|
84
90
|
/**
|
|
85
91
|
* @returns Current time in blockchain
|
|
86
92
|
*/
|
|
@@ -112,6 +118,7 @@ class Blockchain {
|
|
|
112
118
|
this.lock = new AsyncLock_1.AsyncLock();
|
|
113
119
|
this.contractFetches = new Map();
|
|
114
120
|
this.nextCreateWalletIndex = 0;
|
|
121
|
+
this.shouldRecordStorage = false;
|
|
115
122
|
this.networkConfig = blockchainConfigToBase64(opts.config);
|
|
116
123
|
this.executor = opts.executor;
|
|
117
124
|
this.storage = opts.storage;
|
|
@@ -21,6 +21,8 @@ export type SmartContractTransaction = Transaction & {
|
|
|
21
21
|
blockchainLogs: string;
|
|
22
22
|
vmLogs: string;
|
|
23
23
|
debugLogs: string;
|
|
24
|
+
oldStorage?: Cell;
|
|
25
|
+
newStorage?: Cell;
|
|
24
26
|
};
|
|
25
27
|
export type MessageParams = Partial<{
|
|
26
28
|
now: number;
|
|
@@ -76,6 +78,8 @@ export declare class SmartContract {
|
|
|
76
78
|
constructor(shardAccount: ShardAccount, blockchain: Blockchain);
|
|
77
79
|
snapshot(): SmartContractSnapshot;
|
|
78
80
|
loadFrom(snapshot: SmartContractSnapshot): void;
|
|
81
|
+
get ec(): [number, bigint][];
|
|
82
|
+
set ec(nv: [number, bigint][]);
|
|
79
83
|
get balance(): bigint;
|
|
80
84
|
set balance(v: bigint);
|
|
81
85
|
get lastTransactionHash(): bigint;
|
|
@@ -122,6 +122,14 @@ class EmulationError extends Error {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
exports.EmulationError = EmulationError;
|
|
125
|
+
function extractEc(cc) {
|
|
126
|
+
const r = [];
|
|
127
|
+
for (const [k, v] of cc) {
|
|
128
|
+
r.push([k, v]);
|
|
129
|
+
}
|
|
130
|
+
r.sort((a, b) => a[0] - b[0]);
|
|
131
|
+
return r;
|
|
132
|
+
}
|
|
125
133
|
class SmartContract {
|
|
126
134
|
constructor(shardAccount, blockchain) {
|
|
127
135
|
_SmartContract_account.set(this, void 0);
|
|
@@ -150,6 +158,21 @@ class SmartContract {
|
|
|
150
158
|
__classPrivateFieldSet(this, _SmartContract_lastTxTime, snapshot.lastTxTime, "f");
|
|
151
159
|
__classPrivateFieldSet(this, _SmartContract_verbosity, snapshot.verbosity === undefined ? undefined : { ...snapshot.verbosity }, "f");
|
|
152
160
|
}
|
|
161
|
+
get ec() {
|
|
162
|
+
return extractEc(this.account.account?.storage.balance.other ?? core_1.Dictionary.empty());
|
|
163
|
+
}
|
|
164
|
+
set ec(nv) {
|
|
165
|
+
const cc = core_1.Dictionary.empty();
|
|
166
|
+
for (const [k, v] of nv) {
|
|
167
|
+
cc.set(k, v);
|
|
168
|
+
}
|
|
169
|
+
const acc = this.account;
|
|
170
|
+
if (acc.account === undefined) {
|
|
171
|
+
acc.account = createEmptyAccount(this.address);
|
|
172
|
+
}
|
|
173
|
+
acc.account.storage.balance.other = cc;
|
|
174
|
+
this.account = acc;
|
|
175
|
+
}
|
|
153
176
|
get balance() {
|
|
154
177
|
return this.account.account?.storage.balance.coins ?? 0n;
|
|
155
178
|
}
|
|
@@ -222,6 +245,10 @@ class SmartContract {
|
|
|
222
245
|
}));
|
|
223
246
|
}
|
|
224
247
|
async runCommon(run) {
|
|
248
|
+
let oldStorage = undefined;
|
|
249
|
+
if (this.blockchain.recordStorage && this.account.account?.storage.state.type === 'active') {
|
|
250
|
+
oldStorage = this.account.account?.storage.state.state.data ?? undefined;
|
|
251
|
+
}
|
|
225
252
|
const res = await run();
|
|
226
253
|
if (this.verbosity.print && this.verbosity.blockchainLogs && res.logs.length > 0) {
|
|
227
254
|
console.log(res.logs);
|
|
@@ -239,11 +266,17 @@ class SmartContract {
|
|
|
239
266
|
__classPrivateFieldSet(this, _SmartContract_account, res.result.shardAccount, "f");
|
|
240
267
|
__classPrivateFieldSet(this, _SmartContract_parsedAccount, undefined, "f");
|
|
241
268
|
__classPrivateFieldSet(this, _SmartContract_lastTxTime, tx.now, "f");
|
|
269
|
+
let newStorage = undefined;
|
|
270
|
+
if (this.blockchain.recordStorage && this.account.account?.storage.state.type === 'active') {
|
|
271
|
+
newStorage = this.account.account?.storage.state.state.data ?? undefined;
|
|
272
|
+
}
|
|
242
273
|
return {
|
|
243
274
|
...tx,
|
|
244
275
|
blockchainLogs: res.logs,
|
|
245
276
|
vmLogs: res.result.vmLog,
|
|
246
277
|
debugLogs: res.debugLogs,
|
|
278
|
+
oldStorage,
|
|
279
|
+
newStorage,
|
|
247
280
|
};
|
|
248
281
|
}
|
|
249
282
|
async get(method, stack = [], params) {
|
package/dist/utils/message.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, Cell, Message, StateInit } from "@ton/core";
|
|
1
|
+
import { Address, Cell, Dictionary, Message, StateInit } from "@ton/core";
|
|
2
2
|
/**
|
|
3
3
|
* Creates {@link Message} from params.
|
|
4
4
|
*/
|
|
@@ -15,4 +15,5 @@ export declare function internal(params: {
|
|
|
15
15
|
forwardFee?: bigint;
|
|
16
16
|
createdAt?: number;
|
|
17
17
|
createdLt?: bigint;
|
|
18
|
+
ec?: Dictionary<number, bigint> | [number, bigint][];
|
|
18
19
|
}): Message;
|
package/dist/utils/message.js
CHANGED
|
@@ -6,12 +6,24 @@ const core_1 = require("@ton/core");
|
|
|
6
6
|
* Creates {@link Message} from params.
|
|
7
7
|
*/
|
|
8
8
|
function internal(params) {
|
|
9
|
+
let ecd = undefined;
|
|
10
|
+
if (params.ec !== undefined) {
|
|
11
|
+
if (Array.isArray(params.ec)) {
|
|
12
|
+
ecd = core_1.Dictionary.empty();
|
|
13
|
+
for (const [k, v] of params.ec) {
|
|
14
|
+
ecd.set(k, v);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
ecd = params.ec;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
9
21
|
return {
|
|
10
22
|
info: {
|
|
11
23
|
type: 'internal',
|
|
12
24
|
dest: params.to,
|
|
13
25
|
src: params.from,
|
|
14
|
-
value: { coins: params.value },
|
|
26
|
+
value: { coins: params.value, other: ecd },
|
|
15
27
|
bounce: params.bounce ?? true,
|
|
16
28
|
ihrDisabled: params.ihrDisabled ?? true,
|
|
17
29
|
bounced: params.bounced ?? false,
|