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
1bf6f8b4
Commit
1bf6f8b4
authored
Jun 11, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a buy gas method
parent
4d3209ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
state_object.go
ethchain/state_object.go
+18
-3
No files found.
ethchain/state_object.go
View file @
1bf6f8b4
...
...
@@ -108,10 +108,14 @@ func (c *StateObject) ReturnGas(gas, price *big.Int, state *State) {
func
(
c
*
StateObject
)
AddAmount
(
amount
*
big
.
Int
)
{
c
.
SetAmount
(
new
(
big
.
Int
)
.
Add
(
c
.
Amount
,
amount
))
ethutil
.
Config
.
Log
.
Debugf
(
"%x: #%d %v (+ %v)"
,
c
.
Address
(),
c
.
Nonce
,
c
.
Amount
,
amount
)
}
func
(
c
*
StateObject
)
SubAmount
(
amount
*
big
.
Int
)
{
c
.
SetAmount
(
new
(
big
.
Int
)
.
Sub
(
c
.
Amount
,
amount
))
ethutil
.
Config
.
Log
.
Debugf
(
"%x: #%d %v (- %v)"
,
c
.
Address
(),
c
.
Nonce
,
c
.
Amount
,
amount
)
}
func
(
c
*
StateObject
)
SetAmount
(
amount
*
big
.
Int
)
{
...
...
@@ -129,6 +133,17 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error {
return
nil
}
func
(
self
*
StateObject
)
BuyGas
(
gas
,
price
*
big
.
Int
)
error
{
rGas
:=
new
(
big
.
Int
)
.
Set
(
gas
)
rGas
.
Mul
(
gas
,
price
)
self
.
AddAmount
(
rGas
)
// TODO Do sub from TotalGasPool
// and check if enough left
return
nil
}
// Returns the address of the contract/account
func
(
c
*
StateObject
)
Address
()
[]
byte
{
return
c
.
address
...
...
@@ -153,14 +168,14 @@ func (c *StateObject) RlpEncode() []byte {
root
=
""
}
return
ethutil
.
Encode
([]
interface
{}{
c
.
Amount
,
c
.
Nonce
,
root
,
ethutil
.
Sha3Bin
(
c
.
script
)})
return
ethutil
.
Encode
([]
interface
{}{
c
.
Nonce
,
c
.
Amount
,
root
,
ethutil
.
Sha3Bin
(
c
.
script
)})
}
func
(
c
*
StateObject
)
RlpDecode
(
data
[]
byte
)
{
decoder
:=
ethutil
.
NewValueFromBytes
(
data
)
c
.
Amount
=
decoder
.
Get
(
0
)
.
BigI
nt
()
c
.
Nonce
=
decoder
.
Get
(
1
)
.
Ui
nt
()
c
.
Nonce
=
decoder
.
Get
(
0
)
.
Ui
nt
()
c
.
Amount
=
decoder
.
Get
(
1
)
.
BigI
nt
()
c
.
state
=
NewState
(
ethutil
.
NewTrie
(
ethutil
.
Config
.
Db
,
decoder
.
Get
(
2
)
.
Interface
()))
c
.
ScriptHash
=
decoder
.
Get
(
3
)
.
Bytes
()
...
...
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