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
8301d154
Commit
8301d154
authored
Dec 27, 2013
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Serializing block
parent
d8c0b0c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
1 deletion
+44
-1
block.go
block.go
+44
-1
No files found.
block.go
View file @
8301d154
...
...
@@ -2,16 +2,29 @@ package main
import
(
_
"fmt"
"time"
)
type
Block
struct
{
transactions
[]
*
Transaction
RlpSerializer
number
uint32
prevHash
string
uncles
[]
*
Block
coinbase
string
// state xxx
difficulty
int
time
time
.
Time
nonce
int
transactions
[]
*
Transaction
}
func
NewBlock
(
/* TODO use raw data */
transactions
[]
*
Transaction
)
*
Block
{
block
:=
&
Block
{
// Slice of transactions to include in this block
transactions
:
transactions
,
time
:
time
.
Now
(),
}
return
block
...
...
@@ -19,3 +32,33 @@ func NewBlock(/* TODO use raw data */transactions []*Transaction) *Block {
func
(
block
*
Block
)
Update
()
{
}
func
(
block
*
Block
)
Hash
()
string
{
return
Sha256Hex
(
block
.
MarshalRlp
())
}
func
(
block
*
Block
)
MarshalRlp
()
[]
byte
{
// Encoding method requires []interface{} type. It's actual a slice of strings
encTx
:=
make
([]
string
,
len
(
block
.
transactions
))
for
i
,
tx
:=
range
block
.
transactions
{
encTx
[
i
]
=
string
(
tx
.
MarshalRlp
())
}
enc
:=
RlpEncode
([]
interface
{}{
block
.
number
,
block
.
prevHash
,
// Sha of uncles
block
.
coinbase
,
// root state
Sha256Bin
([]
byte
(
RlpEncode
(
encTx
))),
block
.
difficulty
,
block
.
time
,
block
.
nonce
,
// extra?
})
return
[]
byte
(
enc
)
}
func
(
block
*
Block
)
UnmarshalRlp
(
data
[]
byte
)
{
}
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