mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-13 07:23:46 +00:00
Add canceler interface
This commit is contained in:
parent
fc35780124
commit
f434c8df56
3 changed files with 11 additions and 3 deletions
|
|
@ -565,5 +565,6 @@ func (evm *EVM) GetVMContext() *live.VMContext {
|
||||||
GasPrice: evm.TxContext.GasPrice,
|
GasPrice: evm.TxContext.GasPrice,
|
||||||
ChainConfig: evm.ChainConfig(),
|
ChainConfig: evm.ChainConfig(),
|
||||||
StateDB: evm.StateDB,
|
StateDB: evm.StateDB,
|
||||||
|
VM: evm,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,12 @@ type StateDB interface {
|
||||||
GetRefund() uint64
|
GetRefund() uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Canceler is an interface that wraps the Cancel method.
|
||||||
|
// It allows loggers to cancel EVM processing.
|
||||||
|
type Canceler interface {
|
||||||
|
Cancel()
|
||||||
|
}
|
||||||
|
|
||||||
type VMContext struct {
|
type VMContext struct {
|
||||||
Coinbase common.Address
|
Coinbase common.Address
|
||||||
BlockNumber *big.Int
|
BlockNumber *big.Int
|
||||||
|
|
@ -38,6 +44,7 @@ type VMContext struct {
|
||||||
GasPrice *big.Int
|
GasPrice *big.Int
|
||||||
ChainConfig *params.ChainConfig
|
ChainConfig *params.ChainConfig
|
||||||
StateDB StateDB
|
StateDB StateDB
|
||||||
|
VM Canceler
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockEvent is emitted upon tracing an incoming block.
|
// BlockEvent is emitted upon tracing an incoming block.
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ func (t *jsTracer) CaptureTxStart(env *live.VMContext, tx *types.Transaction, fr
|
||||||
gasPriceBig, err := t.toBig(t.vm, env.GasPrice.String())
|
gasPriceBig, err := t.toBig(t.vm, env.GasPrice.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.err = err
|
t.err = err
|
||||||
t.env.Cancel()
|
t.env.VM.Cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.ctx["gasPrice"] = gasPriceBig
|
t.ctx["gasPrice"] = gasPriceBig
|
||||||
|
|
@ -275,7 +275,7 @@ func (t *jsTracer) CaptureTxEnd(receipt *types.Receipt, err error) {
|
||||||
func (t *jsTracer) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
|
func (t *jsTracer) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
|
||||||
cancel := func(err error) {
|
cancel := func(err error) {
|
||||||
t.err = err
|
t.err = err
|
||||||
t.env.Cancel()
|
t.env.VM.Cancel()
|
||||||
}
|
}
|
||||||
if create {
|
if create {
|
||||||
t.ctx["type"] = t.vm.ToValue("CREATE")
|
t.ctx["type"] = t.vm.ToValue("CREATE")
|
||||||
|
|
@ -424,7 +424,7 @@ func (t *jsTracer) onError(context string, err error) {
|
||||||
t.err = wrapError(context, err)
|
t.err = wrapError(context, err)
|
||||||
// `env` is set on CaptureStart which comes before any JS execution.
|
// `env` is set on CaptureStart which comes before any JS execution.
|
||||||
// So it should be non-nil.
|
// So it should be non-nil.
|
||||||
t.env.Cancel()
|
t.env.VM.Cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func wrapError(context string, err error) error {
|
func wrapError(context string, err error) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue