Skip to content

Commit 7a149a1

Browse files
authored
eth/tracers/js: add coinbase addr to ctx (#30231)
Add coinbase address to javascript tracer context. This PR adds the `coinbase` address to `jsTracer.ctx`, allowing access to the coinbase address (fee receipient) in custom JavaScript tracers. Example usage: ```javascript result: function(ctx) { return toAddress(ctx.coinbase); } ``` This change enables custom tracers to access coinbase address, previously unavailable, enhancing their capabilities to match built-in tracers.
1 parent c356847 commit 7a149a1

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

eth/tracers/js/goja.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ func (t *jsTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, from
254254
return
255255
}
256256
t.ctx["gasPrice"] = gasPriceBig
257+
coinbase, err := t.toBuf(t.vm, env.Coinbase.Bytes())
258+
if err != nil {
259+
t.err = err
260+
return
261+
}
262+
t.ctx["coinbase"] = t.vm.ToValue(coinbase)
257263
}
258264

259265
// OnTxEnd implements the Tracer interface and is invoked at the end of

eth/tracers/js/tracer_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ func TestTracer(t *testing.T) {
154154
want: "",
155155
fail: "reached limit for padding memory slice: 1049568 at step (<eval>:1:83(20)) in server-side tracer function 'step'",
156156
contract: []byte{byte(vm.PUSH1), byte(0xff), byte(vm.PUSH1), byte(0x00), byte(vm.MSTORE8), byte(vm.STOP)},
157+
}, { // tests ctx.coinbase
158+
code: "{lengths: [], step: function(log) { }, fault: function() {}, result: function(ctx) { var coinbase = ctx.coinbase; return toAddress(coinbase); }}",
159+
want: `{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0}`,
157160
},
158161
} {
159162
if have, err := execTracer(tt.code, tt.contract); tt.want != string(have) || tt.fail != err {

0 commit comments

Comments
 (0)