diff --git a/core/evm.go b/core/evm.go index fc68b4557940c8b2dd80379a6439d2619e22d65c..979003bda7918b98bb46df2fc21d792bfe2a8cc5 100644 --- a/core/evm.go +++ b/core/evm.go @@ -103,37 +103,6 @@ func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int) output1 := db.GetBalance(sender) output2 := db.GetBalance(recipient) - // add tranfer - db.AddLog(&types.Log{ - Address: common.HexToAddress("0x0000000000000000000000000000000000001010"), - Topics: []common.Hash{ - common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), - sender.Hash(), - recipient.Hash(), - }, - Data: common.BytesToHash(amount.Bytes()).Bytes(), - }) - - dataInputs := []*big.Int{ - amount, - input1, - input2, - output1, - output2, - } - var data []byte - for _, v := range dataInputs { - data = append(data, common.LeftPadBytes(v.Bytes(), 32)...) - } - // add transfer log - db.AddLog(&types.Log{ - Address: common.HexToAddress("0x0000000000000000000000000000000000001010"), - Topics: []common.Hash{ - common.HexToHash("0xe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c4"), - sender.Hash(), - recipient.Hash(), - }, - Data: data, - }) + AddTransferLog(db, sender, recipient, amount, input1, input2, output1, output2) } diff --git a/core/state_transition.go b/core/state_transition.go index fda081b7d11351e4e5624760ed6a4a0b0f566a06..0245e99ce436657db832d91b07f2becf396d41e6 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -22,6 +22,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" @@ -181,6 +182,9 @@ func (st *StateTransition) preCheck() error { // returning the result including the used gas. It returns an error if failed. // An error indicates a consensus issue. func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bool, err error) { + input1 := st.state.GetBalance(st.msg.From()) + input2 := st.state.GetBalance(st.evm.Coinbase) + if err = st.preCheck(); err != nil { return } @@ -224,6 +228,24 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo st.refundGas() st.state.AddBalance(st.evm.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.gasPrice)) + amount := new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), st.gasPrice) + output1 := new(big.Int).SetUint64(input1.Uint64()) + output2 := new(big.Int).SetUint64(input2.Uint64()) + + // add transfer log + AddTransferLog( + st.state, + + msg.From(), + st.evm.Coinbase, + + amount, + input1, + input2, + output1.Sub(output1, amount), + output2.Add(output2, amount), + ) + return ret, st.gasUsed(), vmerr != nil, err } @@ -248,3 +270,53 @@ func (st *StateTransition) refundGas() { func (st *StateTransition) gasUsed() uint64 { return st.initialGas - st.gas } + +// AddTransferLog adds transfer log into state +func AddTransferLog( + state vm.StateDB, + + sender, + recipient common.Address, + + amount, + input1, + input2, + output1, + output2 *big.Int, +) { + + // // add tranfer + // db.AddLog(&types.Log{ + // Address: common.HexToAddress("0x0000000000000000000000000000000000001010"), + // Topics: []common.Hash{ + // common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), + // sender.Hash(), + // recipient.Hash(), + // }, + // Data: common.BytesToHash(amount.Bytes()).Bytes(), + // }) + + dataInputs := []*big.Int{ + amount, + input1, + input2, + output1, + output2, + } + + var data []byte + for _, v := range dataInputs { + data = append(data, common.LeftPadBytes(v.Bytes(), 32)...) + } + + // add transfer log + state.AddLog(&types.Log{ + Address: common.HexToAddress("0x0000000000000000000000000000000000001010"), + Topics: []common.Hash{ + common.HexToHash("0xe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c4"), + sender.Hash(), + recipient.Hash(), + }, + Data: data, + }) +}