diff --git a/vm/test/vm_test.go b/vm/test/vm_test.go index ee3fe7e5..740d0063 100644 --- a/vm/test/vm_test.go +++ b/vm/test/vm_test.go @@ -36,7 +36,7 @@ func makeBytes(n int) []byte { } func TestVM(t *testing.T) { - ourVm := NewVM(newAppState(), newParams(), Zero256) + ourVm := NewVM(newAppState(), newParams(), Zero256, nil) // Create accounts account1 := &Account{ @@ -72,7 +72,7 @@ func TestSubcurrency(t *testing.T) { st.accounts[account1.Address.String()] = account1 st.accounts[account2.Address.String()] = account2 - ourVm := NewVM(st, newParams(), Zero256) + ourVm := NewVM(st, newParams(), Zero256, nil) var gas uint64 = 1000 code_parts := []string{"620f42403355", diff --git a/vm/types.go b/vm/types.go index 443b72c6..3d7b9239 100644 --- a/vm/types.go +++ b/vm/types.go @@ -46,3 +46,11 @@ type Params struct { BlockTime int64 GasLimit uint64 } + +type CallData struct { + Caller []byte + Callee []byte + Data []byte + Value uint64 + Gas uint64 +} diff --git a/vm/vm.go b/vm/vm.go index b37d9ca3..fe184f21 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -7,6 +7,7 @@ import ( . "github.com/tendermint/tendermint/common" "github.com/tendermint/tendermint/events" + "github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/vm/sha3" ) @@ -44,18 +45,20 @@ type VM struct { appState AppState params Params origin Word256 + txid []byte callDepth int evsw *events.EventSwitch } -func NewVM(appState AppState, params Params, origin Word256) *VM { +func NewVM(appState AppState, params Params, origin Word256, txid []byte) *VM { return &VM{ appState: appState, params: params, origin: origin, callDepth: 0, + txid: txid, } } @@ -80,12 +83,31 @@ func (vm *VM) Call(caller, callee *Account, code, input []byte, value uint64, ga vm.callDepth += 1 output, err = vm.call(caller, callee, code, input, value, gas) vm.callDepth -= 1 + exception := "" if err != nil { + exception = err.Error() err := transfer(callee, caller, value) if err != nil { panic("Could not return value to caller") } } + // if callDepth is 0 the event is fired from ExecTx (along with the Input invent) + // otherwise, we fire from here. + if vm.callDepth != 0 && vm.evsw != nil { + vm.evsw.FireEvent(types.EventStringAccReceive(callee.Address.Prefix(20)), struct { + CallData *CallData + Origin []byte + TxId []byte + Return []byte + Exception string + }{ + &CallData{caller.Address.Prefix(20), callee.Address.Prefix(20), input, value, *gas}, + vm.origin.Prefix(20), + vm.txid, + output, + exception, + }) + } return } @@ -636,6 +658,8 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value uint64, ga if ok = useGas(gas, GasGetAccount); !ok { return nil, firstErr(err, ErrInsufficientGas) } + // :( + addr = RightPadWord256(flip(addr.Prefix(20))) acc := vm.appState.GetAccount(addr) if acc == nil { return nil, firstErr(err, ErrUnknownAddress)