Skip to content

Commit 0f6f89f

Browse files
authored
feat(eth/tracers): add coinbase to ctx (#12321)
backport ethereum/go-ethereum#30231 Signed-off-by: jsvisa <[email protected]>
1 parent a99732e commit 0f6f89f

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
@@ -249,6 +249,12 @@ func (t *jsTracer) CaptureStart(env *vm.EVM, from libcommon.Address, to libcommo
249249
}
250250
t.ctx["value"] = valueBig
251251
t.ctx["block"] = t.vm.ToValue(env.Context.BlockNumber)
252+
coinbase, err := t.toBuf(t.vm, env.Context.Coinbase.Bytes())
253+
if err != nil {
254+
t.err = err
255+
return
256+
}
257+
t.ctx["coinbase"] = t.vm.ToValue(coinbase)
252258
// Update list of precompiles based on current block
253259
rules := env.ChainRules()
254260
t.activePrecompiles = vm.ActivePrecompiles(rules)

eth/tracers/js/tracer_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ func TestTracer(t *testing.T) {
161161
want: "",
162162
fail: "tracer reached limit for padding memory slice: end 1049600, memorySize 32 at step (<eval>:1:83(23)) in server-side tracer function 'step'",
163163
contract: []byte{byte(vm.PUSH1), byte(0xff), byte(vm.PUSH1), byte(0x00), byte(vm.MSTORE8), byte(vm.STOP)},
164+
}, { // tests ctx.coinbase
165+
code: "{lengths: [], step: function(log) { }, fault: function() {}, result: function(ctx) { var coinbase = ctx.coinbase; return toAddress(coinbase); }}",
166+
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}`,
164167
},
165168
} {
166169
if have, err := execTracer(tt.code, tt.contract); tt.want != string(have) || tt.fail != err {

0 commit comments

Comments
 (0)