cleanup calldepth=0 events logic
This commit is contained in:
parent
0dbf17653a
commit
02f4219079
|
@ -230,7 +230,7 @@ func TestWSCallWait(t *testing.T) {
|
|||
|
||||
// susbscribe to the new contract
|
||||
amt = uint64(10001)
|
||||
eid2 := types.EventStringAccReceive(contractAddr)
|
||||
eid2 := types.EventStringAccOutput(contractAddr)
|
||||
subscribe(t, con, eid2)
|
||||
defer func() {
|
||||
unsubscribe(t, con, eid2)
|
||||
|
@ -254,7 +254,7 @@ func TestWSCallNoWait(t *testing.T) {
|
|||
|
||||
// susbscribe to the new contract
|
||||
amt = uint64(10001)
|
||||
eid := types.EventStringAccReceive(contractAddr)
|
||||
eid := types.EventStringAccOutput(contractAddr)
|
||||
subscribe(t, con, eid)
|
||||
defer func() {
|
||||
unsubscribe(t, con, eid)
|
||||
|
@ -284,16 +284,20 @@ func TestWSCallCall(t *testing.T) {
|
|||
// susbscribe to the new contracts
|
||||
amt = uint64(10001)
|
||||
eid1 := types.EventStringAccReceive(contractAddr1)
|
||||
eid2 := types.EventStringAccReceive(contractAddr2)
|
||||
subscribe(t, con, eid1)
|
||||
subscribe(t, con, eid2)
|
||||
defer func() {
|
||||
unsubscribe(t, con, eid1)
|
||||
unsubscribe(t, con, eid2)
|
||||
con.Close()
|
||||
}()
|
||||
// call contract2, which should call contract1, and wait for ev1
|
||||
data := []byte{0x1} // just needs to be non empty for this to be a CallTx
|
||||
|
||||
// let the contract get created first
|
||||
waitForEvent(t, con, eid1, true, func() {
|
||||
}, func(eid string, b []byte) error {
|
||||
return nil
|
||||
})
|
||||
// call it
|
||||
waitForEvent(t, con, eid1, true, func() {
|
||||
tx, _ := broadcastTx(t, "JSONRPC", userByteAddr, contractAddr2, data, userBytePriv, amt, 1000, 1000)
|
||||
*txid = account.HashSignBytes(tx)
|
||||
|
|
|
@ -130,7 +130,6 @@ func unmarshalValidateCallCall(origin, returnCode []byte, txid *[]byte) func(str
|
|||
if bytes.Compare(response.Data.TxId, *txid) != 0 {
|
||||
return fmt.Errorf("TxIds do not match up! Got %x, expected %x", response.Data.TxId, *txid)
|
||||
}
|
||||
// calldata := response.Data.CallData
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -406,6 +406,11 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
|
|||
if outAcc == nil || len(outAcc.Code) == 0 {
|
||||
// if you call an account that doesn't exist
|
||||
// or an account with no code then we take fees (sorry pal)
|
||||
// NOTE: it's fine to create a contract and call it within one
|
||||
// block (nonce will prevent re-ordering of those txs)
|
||||
// but to create with one account and call with another
|
||||
// you have to wait a block to avoid a re-ordering attack
|
||||
// that will take your fees
|
||||
inAcc.Balance -= tx.Fee
|
||||
blockCache.UpdateAccount(inAcc)
|
||||
if outAcc == nil {
|
||||
|
@ -457,7 +462,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
|
|||
// a separate event will be fired from vm for each additional call
|
||||
if evc != nil {
|
||||
evc.FireEvent(types.EventStringAccInput(tx.Input.Address), types.EventMsgCallTx{tx, ret, exception})
|
||||
evc.FireEvent(types.EventStringAccReceive(tx.Address), types.EventMsgCallTx{tx, ret, exception})
|
||||
evc.FireEvent(types.EventStringAccOutput(tx.Address), types.EventMsgCallTx{tx, ret, exception})
|
||||
}
|
||||
} else {
|
||||
// The mempool does not call txs until
|
||||
|
|
5
vm/vm.go
5
vm/vm.go
|
@ -76,10 +76,7 @@ func (vm *VM) Call(caller, callee *Account, code, input []byte, value uint64, ga
|
|||
|
||||
exception := new(string)
|
||||
defer func() {
|
||||
// if callDepth is 0 the event is fired from ExecTx (along with the Input event)
|
||||
// otherwise, we fire from here.
|
||||
if vm.callDepth != 0 && vm.evc != nil {
|
||||
fmt.Println("FIRE AWAY!", types.EventStringAccReceive(callee.Address.Postfix(20)))
|
||||
if vm.evc != nil {
|
||||
vm.evc.FireEvent(types.EventStringAccReceive(callee.Address.Postfix(20)), types.EventMsgCall{
|
||||
&types.CallData{caller.Address.Postfix(20), callee.Address.Postfix(20), input, value, *gas},
|
||||
vm.origin.Postfix(20),
|
||||
|
|
Loading…
Reference in New Issue