@@ -5,6 +5,7 @@ import { alea } from 'seedrandom';
55import { VmContext } from "../models/Context" ;
66import { ExecuteResult } from '../models/ExecuteResult' ;
77import { generateFixedBuffer } from './CryptoService' ;
8+ import VirtualFs from './VirtualFsService' ;
89import WasmImports from './WasmImports' ;
910
1011const metering = require ( 'wasm-metering' ) ;
@@ -19,6 +20,7 @@ export function prepareWasmBinary(binary: Uint8Array): Uint8Array {
1920
2021export async function executeWasm ( context : VmContext ) : Promise < ExecuteResult > {
2122 const wasmFs = new WasmFs ( ) ;
23+ const virtualFs = new VirtualFs ( wasmFs ) ;
2224
2325 try {
2426 const random = alea ( context . randomSeed ) ;
@@ -27,7 +29,7 @@ export async function executeWasm(context: VmContext): Promise<ExecuteResult> {
2729 env : context . env ,
2830 bindings : {
2931 ...WASIBindings ,
30- fs : wasmFs . fs ,
32+ fs : virtualFs . getFs ( ) ,
3133 hrtime : ( ) => BigInt ( context . timestamp ) ,
3234 randomFillSync : ( buffer : any , offset , size ) => {
3335 const randomBuffer = generateFixedBuffer ( random . int32 ( ) . toString ( ) , size ?? buffer . length - offset ) ;
@@ -46,25 +48,15 @@ export async function executeWasm(context: VmContext): Promise<ExecuteResult> {
4648 wasmImports . setMemory ( instance . exports . memory as WebAssembly . Memory ) ;
4749 wasi . start ( instance ) ;
4850
49- const logs = [ ] ;
50- const stdout = await wasmFs . getStdOut ( ) as string ;
51-
52- if ( stdout ) {
53- logs . push ( ...stdout . split ( "\n" ) ) ;
54- }
51+ const logs = virtualFs . getLogOutput ( ) ;
5552
5653 return {
5754 code : 0 ,
5855 logs,
5956 gasUsed : context . gasUsed . toString ( ) ,
6057 }
6158 } catch ( error : any ) {
62- const stdout = await wasmFs . getStdOut ( ) ;
63- const logs = [ ] ;
64-
65- if ( stdout ) {
66- logs . push ( stdout ) ;
67- }
59+ const logs = virtualFs . getLogOutput ( ) ;
6860
6961 logs . push ( error ?. message ) ;
7062
0 commit comments