good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 087c44d4 authored by Jaynti Kanani's avatar Jaynti Kanani
Browse files

chg: add log changes for fee

parent e5058f94
No related branches found
No related tags found
No related merge requests found
package core
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
)
var transferLogSig = common.HexToHash("0xe6497e3ee548a3372136af2fcb0696db31fc6cf20260707645068bd3fe97f3c4")
var transferFeeLogSig = common.HexToHash("0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63")
var feeAddress = common.HexToAddress("0x0000000000000000000000000000000000001010")
var bigZero = big.NewInt(0)
// AddTransferLog adds transfer log into state
func AddTransferLog(
state vm.StateDB,
sender,
recipient common.Address,
amount,
input1,
input2,
output1,
output2 *big.Int,
) {
addTransferLog(
state,
transferLogSig,
sender,
recipient,
amount,
input1,
input2,
output1,
output2,
)
}
// AddFeeTransferLog adds transfer log into state
func AddFeeTransferLog(
state vm.StateDB,
sender,
recipient common.Address,
amount,
input1,
input2,
output1,
output2 *big.Int,
) {
addTransferLog(
state,
transferFeeLogSig,
sender,
recipient,
amount,
input1,
input2,
output1,
output2,
)
}
// addTransferLog adds transfer log into state
func addTransferLog(
state vm.StateDB,
eventSig common.Hash,
sender,
recipient common.Address,
amount,
input1,
input2,
output1,
output2 *big.Int,
) {
// ignore if amount is 0
if amount.Cmp(bigZero) <= 0 {
return
}
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: feeAddress,
Topics: []common.Hash{
eventSig,
feeAddress.Hash(),
sender.Hash(),
recipient.Hash(),
},
Data: data,
})
}
......@@ -100,6 +100,17 @@ func CanTransfer(db vm.StateDB, addr common.Address, amount *big.Int) bool {
// Transfer subtracts amount from sender and adds amount to recipient using the given Db
func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int) {
// get inputs before
input1 := db.GetBalance(sender)
input2 := db.GetBalance(recipient)
db.SubBalance(sender, amount)
db.AddBalance(recipient, amount)
// get outputs after
output1 := db.GetBalance(sender)
output2 := db.GetBalance(recipient)
// add transfer log
AddTransferLog(db, sender, recipient, amount, input1, input2, output1, output2)
}
......@@ -214,6 +214,9 @@ func (st *StateTransition) preCheck() error {
// However if any consensus issue encountered, return the error directly with
// nil evm execution result.
func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
input1 := st.state.GetBalance(st.msg.From())
input2 := st.state.GetBalance(st.evm.Coinbase)
// First check this message satisfies all consensus rules before
// applying the message. The rules include these clauses
//
......@@ -262,6 +265,24 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
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).SetBytes(input1.Bytes())
output2 := new(big.Int).SetBytes(input2.Bytes())
// add transfer log
AddFeeTransferLog(
st.state,
msg.From(),
st.evm.Coinbase,
amount,
input1,
input2,
output1.Sub(output1, amount),
output2.Add(output2, amount),
)
return &ExecutionResult{
UsedGas: st.gasUsed(),
Err: vmerr,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment