File tree Expand file tree Collapse file tree 4 files changed +41
-8
lines changed
packages/transaction-interpreter/src Expand file tree Collapse file tree 4 files changed +41
-8
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @3loop/transaction-interpreter ' : patch
3+ ---
4+
5+ Add options parameter to the transaction interpreter
Original file line number Diff line number Diff line change @@ -23,14 +23,28 @@ const make = Effect.succeed({
2323 id : `${ decodedTx . chainID } :${ decodedTx . toAddress } ` ,
2424 }
2525 } ,
26- interpretTx : ( decodedTx : DecodedTransaction , interpreter : Interpreter ) =>
26+ interpretTx : (
27+ decodedTx : DecodedTransaction ,
28+ interpreter : Interpreter ,
29+ options ?: {
30+ interpretAsUserAddress ?: string
31+ } ,
32+ ) =>
2733 Effect . sync ( ( ) => {
2834 // TODO: add ability to surpress warning on acknowledge
2935 Effect . logWarning ( 'Using eval in production can result in security vulnerabilities. Use at your own risk.' )
3036
31- const input = stringify ( decodedTx )
32- const code = interpreter . schema
33- const result = localEval ( code , input )
37+ let input
38+ if ( options ?. interpretAsUserAddress ) {
39+ input = stringify ( {
40+ ...decodedTx ,
41+ fromAddress : options . interpretAsUserAddress ,
42+ } )
43+ } else {
44+ input = stringify ( decodedTx )
45+ }
46+
47+ const result = localEval ( interpreter . schema , input )
3448 return result
3549 } ) . pipe ( Effect . withSpan ( 'TransactionInterpreter.interpretTx' ) ) ,
3650} )
Original file line number Diff line number Diff line change @@ -22,11 +22,22 @@ const make = Effect.gen(function* () {
2222 id : `${ decodedTx . chainID } :${ decodedTx . toAddress } ` ,
2323 }
2424 } ,
25- interpretTx : ( decodedTx : DecodedTransaction , interpreter : Interpreter ) =>
25+ interpretTx : (
26+ decodedTx : DecodedTransaction ,
27+ interpreter : Interpreter ,
28+ options ?: { interpretAsUserAddress ?: string } ,
29+ ) =>
2630 Effect . gen ( function * ( ) {
27- const input = stringify ( decodedTx )
28- const code = interpreter . schema
29- const result = yield * vm . eval ( code + '\n' + 'transformEvent(' + input + ')' )
31+ let input
32+ if ( options ?. interpretAsUserAddress ) {
33+ input = stringify ( {
34+ ...decodedTx ,
35+ fromAddress : options . interpretAsUserAddress ,
36+ } )
37+ } else {
38+ input = stringify ( decodedTx )
39+ }
40+ const result = yield * vm . eval ( interpreter . schema + '\n' + 'transformEvent(' + input + ')' )
3041 return result
3142 } ) . pipe ( Effect . withSpan ( 'TransactionInterpreter.interpretTx' ) ) ,
3243 }
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ export interface TransactionInterpreter {
88 readonly interpretTx : (
99 decodedTx : DecodedTransaction ,
1010 interpreter : Interpreter ,
11+ options ?: {
12+ interpretAsUserAddress ?: string
13+ } ,
1114 ) => Effect . Effect < InterpretedTransaction , InterpreterError , never >
1215}
1316
You can’t perform that action at this time.
0 commit comments