Skip to content

Commit 34075d6

Browse files
committed
Scope VM at interpretation level
1 parent 604ffca commit 34075d6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

packages/transaction-interpreter/src/QuickjsInterpreter.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { Interpreter, InterpreterOptions } from './types.js'
55
import { getInterpreter } from './interpreters.js'
66
import { QuickjsVM } from './quickjs.js'
77
import { TransactionInterpreter } from './interpreter.js'
8+
import { QuickjsConfig } from './QuickjsConfig.js'
89

910
const make = Effect.gen(function* () {
10-
const vm = yield* QuickjsVM
11+
const config = yield* QuickjsConfig
1112

1213
return {
1314
findInterpreter: (decodedTx: DecodedTransaction) => {
@@ -28,23 +29,35 @@ const make = Effect.gen(function* () {
2829
options?: { interpretAsUserAddress?: string },
2930
) =>
3031
Effect.gen(function* () {
32+
const vm = yield* QuickjsVM
33+
3134
const input = stringify(decodedTransaction) + (options ? `,${stringify(options)}` : '')
3235
const code = interpreter.schema + '\n' + 'transformEvent(' + input + ')'
3336
const result = yield* vm.eval(code)
3437
return result
35-
}).pipe(Effect.withSpan('TransactionInterpreter.interpretTx')),
38+
}).pipe(
39+
Effect.withSpan('TransactionInterpreter.interpretTx'),
40+
Effect.scoped,
41+
Effect.provideService(QuickjsConfig, config),
42+
),
3643

3744
interpretTransaction: (
3845
decodedTransaction: DecodedTransaction,
3946
interpreter: Interpreter,
4047
options?: InterpreterOptions,
4148
) =>
4249
Effect.gen(function* () {
50+
const vm = yield* QuickjsVM
51+
4352
const input = stringify(decodedTransaction) + (options ? `,${stringify(options)}` : '')
4453
const code = interpreter.schema + '\n' + 'transformEvent(' + input + ')'
4554
const result = yield* vm.eval(code)
4655
return result
47-
}).pipe(Effect.withSpan('TransactionInterpreter.interpretTransaction')),
56+
}).pipe(
57+
Effect.withSpan('TransactionInterpreter.interpretTransaction'),
58+
Effect.scoped,
59+
Effect.provideService(QuickjsConfig, config),
60+
),
4861
}
4962
})
5063

0 commit comments

Comments
 (0)