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
15bf5ee4
Commit
15bf5ee4
authored
Jan 03, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Contract creation, updating and fee processing
parent
f97716eb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
3 deletions
+28
-3
block.go
block.go
+28
-3
No files found.
block.go
View file @
15bf5ee4
package
main
package
main
import
(
import
(
_
"fmt"
"fmt"
"time"
"time"
_
"bytes"
_
"bytes"
_
"encoding/hex"
_
"encoding/hex"
...
@@ -73,7 +73,8 @@ func CreateBlock(root string, num int, prevHash string, base string, difficulty
...
@@ -73,7 +73,8 @@ func CreateBlock(root string, num int, prevHash string, base string, difficulty
contract
:=
NewContract
(
tx
.
value
,
[]
byte
(
""
))
contract
:=
NewContract
(
tx
.
value
,
[]
byte
(
""
))
block
.
state
.
Update
(
string
(
addr
),
string
(
contract
.
MarshalRlp
()))
block
.
state
.
Update
(
string
(
addr
),
string
(
contract
.
MarshalRlp
()))
for
i
,
val
:=
range
tx
.
data
{
for
i
,
val
:=
range
tx
.
data
{
contract
.
state
.
Update
(
string
(
Encode
(
uint32
(
i
))),
val
)
contract
.
state
.
Update
(
string
(
NumberToBytes
(
uint64
(
i
),
32
)),
val
)
//contract.state.Update(string(Encode(uint32(i))), val)
}
}
block
.
UpdateContract
(
addr
,
contract
)
block
.
UpdateContract
(
addr
,
contract
)
}
}
...
@@ -84,6 +85,10 @@ func CreateBlock(root string, num int, prevHash string, base string, difficulty
...
@@ -84,6 +85,10 @@ func CreateBlock(root string, num int, prevHash string, base string, difficulty
func
(
block
*
Block
)
GetContract
(
addr
[]
byte
)
*
Contract
{
func
(
block
*
Block
)
GetContract
(
addr
[]
byte
)
*
Contract
{
data
:=
block
.
state
.
Get
(
string
(
addr
))
data
:=
block
.
state
.
Get
(
string
(
addr
))
if
data
==
""
{
return
nil
}
contract
:=
&
Contract
{}
contract
:=
&
Contract
{}
contract
.
UnmarshalRlp
([]
byte
(
data
))
contract
.
UnmarshalRlp
([]
byte
(
data
))
...
@@ -94,7 +99,27 @@ func (block *Block) UpdateContract(addr []byte, contract *Contract) {
...
@@ -94,7 +99,27 @@ func (block *Block) UpdateContract(addr []byte, contract *Contract) {
block
.
state
.
Update
(
string
(
addr
),
string
(
contract
.
MarshalRlp
()))
block
.
state
.
Update
(
string
(
addr
),
string
(
contract
.
MarshalRlp
()))
}
}
func
(
block
*
Block
)
Update
()
{
func
(
block
*
Block
)
PayFee
(
addr
[]
byte
,
fee
uint64
)
bool
{
contract
:=
block
.
GetContract
(
addr
)
// If we can't pay the fee return
if
contract
==
nil
||
contract
.
amount
<
fee
{
fmt
.
Println
(
"Contract has insufficient funds"
,
contract
.
amount
,
fee
)
return
false
}
contract
.
amount
-=
fee
block
.
state
.
Update
(
string
(
addr
),
string
(
contract
.
MarshalRlp
()))
data
:=
block
.
state
.
Get
(
string
(
block
.
coinbase
))
println
(
data
)
// Get the ether (coinbase) and add the fee (gief fee to miner)
ether
:=
NewEtherFromData
([]
byte
(
data
))
ether
.
amount
+=
fee
block
.
state
.
Update
(
string
(
block
.
coinbase
),
string
(
ether
.
MarshalRlp
()))
return
true
}
}
// Returns a hash of the block
// Returns a hash of the block
...
...
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