@@ -13,6 +13,7 @@ import {
13
13
loadShardAccount ,
14
14
Transaction ,
15
15
loadTransaction ,
16
+ Dictionary ,
16
17
} from '@ton/core' ;
17
18
import {
18
19
loadConfigParamsAsSlice ,
@@ -29,7 +30,7 @@ import {
29
30
TVMLog ,
30
31
} from './types' ;
31
32
import { parseStack } from './stack' ;
32
- import { linkToTx , mcSeqnoByShard , txToLinks } from './utils' ;
33
+ import { getLib , linkToTx , mcSeqnoByShard , txToLinks } from './utils' ;
33
34
34
35
function b64ToBigInt ( b64 : string ) : bigint {
35
36
return BigInt ( '0x' + Buffer . from ( b64 , 'base64' ) . toString ( 'hex' ) ) ;
@@ -213,13 +214,37 @@ export async function getEmulationWithStack(
213
214
account = getAccountResult . account ;
214
215
let initialShardAccount = createShardAccountFromAPI ( account , address ) ;
215
216
216
- // 4.1 get account stete after all txs for (maybe) verification
217
- const { account : accountAfter } = await clientV4 . getAccount (
218
- mcBlockSeqno ,
219
- address
217
+ const state = initialShardAccount . account ?. storage . state ;
218
+
219
+ // 4.1 Get libs if needed
220
+ const _libs = Dictionary . empty (
221
+ Dictionary . Keys . BigUint ( 256 ) ,
222
+ Dictionary . Values . Cell ( )
220
223
) ;
221
- console . log ( account . balance . coins , 'coins before' ) ;
222
- if ( isOurTxLastTx ) console . log ( accountAfter . balance . coins , 'coins after' ) ;
224
+ if ( state ?. type == 'active' ) {
225
+ sendStatus ( 'Getting libs' ) ;
226
+ const code = state . state . code ;
227
+ if ( code instanceof Cell && code . bits . length == 256 + 8 ) {
228
+ const cs = code . beginParse ( true ) ;
229
+ const tag = cs . loadUint ( 8 ) ;
230
+ if ( tag == 2 ) {
231
+ const libHash = cs . loadBuffer ( 32 ) ;
232
+ const libHashHex = libHash . toString ( 'hex' ) . toUpperCase ( ) ;
233
+ const actualCode = await getLib ( libHashHex , testnet ) ;
234
+ _libs . set ( BigInt ( `0x${ libHashHex } ` ) , actualCode ) ;
235
+ }
236
+ }
237
+ }
238
+ let libs : Cell | null = null ;
239
+ if ( _libs . size > 0 ) libs = beginCell ( ) . storeDictDirect ( _libs ) . endCell ( ) ;
240
+
241
+ // 4.2 get account state after all txs for (maybe) verification
242
+ // const { account: accountAfter } = await clientV4.getAccount(
243
+ // mcBlockSeqno,
244
+ // address
245
+ // );
246
+ // console.log(account.balance.coins, 'coins before');
247
+ // if (isOurTxLastTx) console.log(accountAfter.balance.coins, 'coins after');
223
248
224
249
// 5. prep. emulator
225
250
@@ -242,7 +267,7 @@ export async function getEmulationWithStack(
242
267
243
268
let _txRes = _executor . runTransaction ( {
244
269
config : blockConfig ,
245
- libs : null ,
270
+ libs,
246
271
verbosity : _withStack ? 'full_location_stack_verbose' : 'short' ,
247
272
shardAccount : _shardAccountStr ,
248
273
message : beginCell ( ) . store ( storeMessage ( _msg ) ) . endCell ( ) ,
@@ -402,20 +427,20 @@ export async function getEmulationWithStack(
402
427
) ;
403
428
const endBalance = parsedShardAccount . account ?. storage . balance . coins || 0n ;
404
429
405
- if ( isOurTxLastTx ) {
406
- // we dont know mainnet balance if its not last tx in block
407
- const balanceCheck = endBalance === BigInt ( accountAfter . balance . coins ) ;
408
- if ( ! balanceCheck ) {
409
- console . error (
410
- `Balance check failed, expected ${ accountAfter . balance . coins } got ${ endBalance } `
411
- ) ;
412
- } else {
413
- console . log ( 'Balance check ok' ) ;
414
- }
415
- } else {
416
- console . log ( 'Balance check skipped' ) ;
417
- console . log ( endBalance , 'end balance' ) ;
418
- }
430
+ // if (isOurTxLastTx) {
431
+ // // we dont know mainnet balance if its not last tx in block
432
+ // const balanceCheck = endBalance === BigInt(accountAfter.balance.coins);
433
+ // if (!balanceCheck) {
434
+ // console.error(
435
+ // `Balance check failed, expected ${accountAfter.balance.coins} got ${endBalance}`
436
+ // );
437
+ // } else {
438
+ // console.log('Balance check ok');
439
+ // }
440
+ // } else {
441
+ // console.log('Balance check skipped');
442
+ // console.log(endBalance, 'end balance');
443
+ // }
419
444
420
445
const theTx = loadTransaction (
421
446
Cell . fromBase64 ( txResCorrect . result . transaction ) . asSlice ( )
@@ -491,9 +516,6 @@ export async function getEmulationWithStack(
491
516
gasFees : computePhase . gasFees ,
492
517
} ;
493
518
494
- console . log ( parsedShardAccount ) ;
495
- console . log ( accountAfter ) ;
496
-
497
519
return {
498
520
sender : src ,
499
521
contract : dest ,
0 commit comments