Skip to content

Commit

Permalink
feat(eth/tracers): add coinbase to ctx (#12321)
Browse files Browse the repository at this point in the history
backport ethereum/go-ethereum#30231

Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa authored Oct 16, 2024
1 parent a99732e commit 0f6f89f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions eth/tracers/js/goja.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ func (t *jsTracer) CaptureStart(env *vm.EVM, from libcommon.Address, to libcommo
}
t.ctx["value"] = valueBig
t.ctx["block"] = t.vm.ToValue(env.Context.BlockNumber)
coinbase, err := t.toBuf(t.vm, env.Context.Coinbase.Bytes())
if err != nil {
t.err = err
return
}
t.ctx["coinbase"] = t.vm.ToValue(coinbase)
// Update list of precompiles based on current block
rules := env.ChainRules()
t.activePrecompiles = vm.ActivePrecompiles(rules)
Expand Down
3 changes: 3 additions & 0 deletions eth/tracers/js/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ func TestTracer(t *testing.T) {
want: "",
fail: "tracer reached limit for padding memory slice: end 1049600, memorySize 32 at step (<eval>:1:83(23)) in server-side tracer function 'step'",
contract: []byte{byte(vm.PUSH1), byte(0xff), byte(vm.PUSH1), byte(0x00), byte(vm.MSTORE8), byte(vm.STOP)},
}, { // tests ctx.coinbase
code: "{lengths: [], step: function(log) { }, fault: function() {}, result: function(ctx) { var coinbase = ctx.coinbase; return toAddress(coinbase); }}",
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}`,
},
} {
if have, err := execTracer(tt.code, tt.contract); tt.want != string(have) || tt.fail != err {
Expand Down

0 comments on commit 0f6f89f

Please sign in to comment.