Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
0d776328
Commit
0d776328
authored
Jun 16, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refund gas
parent
8b15732c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
4 deletions
+22
-4
state_object.go
ethchain/state_object.go
+9
-0
state_transition.go
ethchain/state_transition.go
+13
-4
No files found.
ethchain/state_object.go
View file @
0d776328
...
@@ -163,6 +163,15 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error {
...
@@ -163,6 +163,15 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error {
return
nil
return
nil
}
}
func
(
self
*
StateObject
)
RefundGas
(
gas
,
price
*
big
.
Int
)
{
self
.
gasPool
.
Add
(
self
.
gasPool
,
gas
)
rGas
:=
new
(
big
.
Int
)
.
Set
(
gas
)
rGas
.
Mul
(
rGas
,
price
)
self
.
Amount
.
Sub
(
self
.
Amount
,
rGas
)
}
func
(
self
*
StateObject
)
Copy
()
*
StateObject
{
func
(
self
*
StateObject
)
Copy
()
*
StateObject
{
stCopy
:=
&
StateObject
{}
stCopy
:=
&
StateObject
{}
stCopy
.
address
=
make
([]
byte
,
len
(
self
.
address
))
stCopy
.
address
=
make
([]
byte
,
len
(
self
.
address
))
...
...
ethchain/state_transition.go
View file @
0d776328
...
@@ -110,6 +110,15 @@ func (self *StateTransition) BuyGas() error {
...
@@ -110,6 +110,15 @@ func (self *StateTransition) BuyGas() error {
return
nil
return
nil
}
}
func
(
self
*
StateTransition
)
RefundGas
()
{
coinbase
,
sender
:=
self
.
Coinbase
(),
self
.
Sender
()
coinbase
.
RefundGas
(
self
.
gas
,
self
.
tx
.
GasPrice
)
// Return remaining gas
remaining
:=
new
(
big
.
Int
)
.
Mul
(
self
.
gas
,
self
.
tx
.
GasPrice
)
sender
.
AddAmount
(
remaining
)
}
func
(
self
*
StateTransition
)
TransitionState
()
(
err
error
)
{
func
(
self
*
StateTransition
)
TransitionState
()
(
err
error
)
{
//snapshot := st.state.Snapshot()
//snapshot := st.state.Snapshot()
...
@@ -141,6 +150,8 @@ func (self *StateTransition) TransitionState() (err error) {
...
@@ -141,6 +150,8 @@ func (self *StateTransition) TransitionState() (err error) {
// XXX Transactions after this point are considered valid.
// XXX Transactions after this point are considered valid.
defer
func
()
{
defer
func
()
{
self
.
RefundGas
()
if
sender
!=
nil
{
if
sender
!=
nil
{
self
.
state
.
UpdateStateObject
(
sender
)
self
.
state
.
UpdateStateObject
(
sender
)
}
}
...
@@ -148,6 +159,8 @@ func (self *StateTransition) TransitionState() (err error) {
...
@@ -148,6 +159,8 @@ func (self *StateTransition) TransitionState() (err error) {
if
receiver
!=
nil
{
if
receiver
!=
nil
{
self
.
state
.
UpdateStateObject
(
receiver
)
self
.
state
.
UpdateStateObject
(
receiver
)
}
}
self
.
state
.
UpdateStateObject
(
self
.
Coinbase
())
}()
}()
// Increment the nonce for the next transaction
// Increment the nonce for the next transaction
...
@@ -203,10 +216,6 @@ func (self *StateTransition) TransitionState() (err error) {
...
@@ -203,10 +216,6 @@ func (self *StateTransition) TransitionState() (err error) {
}
}
}
}
// Return remaining gas
remaining
:=
new
(
big
.
Int
)
.
Mul
(
self
.
gas
,
tx
.
GasPrice
)
sender
.
AddAmount
(
remaining
)
return
nil
return
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment