[tracers][vm] expose transaction query api for js vm.

pull/3640/head
peekpi 4 years ago
parent 721c5e3af7
commit 011d78b530
  1. 4
      core/state/statedb.go
  2. 9
      core/types/derive_sha_test.go
  3. 6
      core/vm/evm.go
  4. 4
      core/vm/interface.go
  5. 4
      core/vm/logger.go
  6. 2
      core/vm/logger_json.go
  7. 10
      hmy/tracers/tracer.go

@ -259,6 +259,10 @@ func (db *DB) TxIndex() int {
return db.txIndex
}
func (s *DB) TxHash() common.Hash {
return s.thash
}
// BlockHash returns the current block hash set by Prepare.
func (db *DB) BlockHash() common.Hash {
return db.bhash

@ -0,0 +1,9 @@
package types
import "testing"
func TestBloomxxx(t *testing.T) {
r := NewReceipt([]byte("helloworld"), false, 1)
t.Log(r)
//DeriveSha
}

@ -228,7 +228,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
if precompiles[addr] == nil && evm.ChainConfig().IsS3(evm.EpochNumber) && value.Sign() == 0 {
// Calling a non existing account, don't do anything, but ping the tracer
if evm.vmConfig.Debug && evm.depth == 0 {
evm.vmConfig.Tracer.CaptureStart(caller.Address(), addr, false, input, gas, value)
evm.vmConfig.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
evm.vmConfig.Tracer.CaptureEnd(ret, 0, 0, nil)
}
return nil, gas, nil
@ -255,7 +255,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
// Capture the tracer start/end events in debug mode
if evm.vmConfig.Debug && evm.depth == 0 {
evm.vmConfig.Tracer.CaptureStart(caller.Address(), addr, false, input, gas, value)
evm.vmConfig.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
defer func() { // Lazy evaluation of the parameters
evm.vmConfig.Tracer.CaptureEnd(ret, gas-contract.Gas, time.Since(start), err)
@ -440,7 +440,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
}
if evm.vmConfig.Debug && evm.depth == 0 {
evm.vmConfig.Tracer.CaptureStart(caller.Address(), address, true, codeAndHash.code, gas, value)
evm.vmConfig.Tracer.CaptureStart(evm, caller.Address(), address, true, codeAndHash.code, gas, value)
}
start := time.Now()

@ -74,6 +74,10 @@ type StateDB interface {
AddPreimage(common.Hash, []byte)
ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
TxIndex() int
BlockHash() common.Hash
TxHash() common.Hash
}
// CallContext provides a basic interface for the EVM calling conventions. The EVM

@ -100,7 +100,7 @@ func (s *StructLog) ErrorString() string {
// Note that reference types are actual VM data structures; make copies
// if you need to retain them beyond the current call.
type Tracer interface {
CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error
CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error
CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error
CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error
CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error
@ -132,7 +132,7 @@ func NewStructLogger(cfg *LogConfig) *StructLogger {
}
// CaptureStart implements the Tracer interface to initialize the tracing operation.
func (l *StructLogger) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
func (l *StructLogger) CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
return nil
}

@ -43,7 +43,7 @@ func NewJSONLogger(cfg *LogConfig, writer io.Writer) *JSONLogger {
}
// CaptureStart ...
func (l *JSONLogger) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
func (l *JSONLogger) CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
return nil
}

@ -526,7 +526,7 @@ func wrapError(context string, err error) error {
}
// CaptureStart implements the Tracer interface to initialize the tracing operation.
func (jst *Tracer) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
func (jst *Tracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error {
jst.ctx["type"] = "CALL"
if create {
jst.ctx["type"] = "CREATE"
@ -536,7 +536,9 @@ func (jst *Tracer) CaptureStart(from common.Address, to common.Address, create b
jst.ctx["input"] = input
jst.ctx["gas"] = gas
jst.ctx["value"] = value
jst.ctx["blockHash"] = env.StateDB.BlockHash()
jst.ctx["transactionPosition"] = uint64(env.StateDB.TxIndex())
jst.ctx["transactionHash"] = env.StateDB.TxHash()
return nil
}
@ -627,6 +629,10 @@ func (jst *Tracer) GetResult() (json.RawMessage, error) {
ptr := jst.vm.PushFixedBuffer(20)
copy(makeSlice(ptr, 20), val[:])
case common.Hash:
ptr := jst.vm.PushFixedBuffer(32)
copy(makeSlice(ptr, 32), val[:])
case *big.Int:
pushBigInt(val, jst.vm)

Loading…
Cancel
Save