good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
087c44d4
Unverified
Commit
087c44d4
authored
4 years ago
by
Jaynti Kanani
Browse files
Options
Downloads
Patches
Plain Diff
chg: add log changes for fee
parent
e5058f94
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/bor_fee_log.go
+115
-0
115 additions, 0 deletions
core/bor_fee_log.go
core/evm.go
+11
-0
11 additions, 0 deletions
core/evm.go
core/state_transition.go
+21
-0
21 additions, 0 deletions
core/state_transition.go
with
147 additions
and
0 deletions
core/bor_fee_log.go
0 → 100644
+
115
−
0
View file @
087c44d4
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
,
})
}
This diff is collapsed.
Click to expand it.
core/evm.go
+
11
−
0
View file @
087c44d4
...
...
@@ -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
)
}
This diff is collapsed.
Click to expand it.
core/state_transition.go
+
21
−
0
View file @
087c44d4
...
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment