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
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
0edcbc69
Commit
0edcbc69
authored
Dec 29, 2013
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Updated serialisation
parent
0747aa3a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
block.go
+31
-11
31 additions, 11 deletions
block.go
with
31 additions
and
11 deletions
block.go
+
31
−
11
View file @
0edcbc69
package
main
import
(
"fmt"
_
"fmt"
"time"
_
"bytes"
)
...
...
@@ -17,14 +17,24 @@ type Block struct {
// state xxx
difficulty
uint32
// Creation time
time
time
.
Time
time
int64
nonce
uint32
// List of transactions and/or contracts
transactions
[]
*
Transaction
extra
string
}
// New block takes a raw encoded string
func
NewBlock
(
raw
[]
byte
)
*
Block
{
block
:=
&
Block
{}
block
.
UnmarshalRlp
(
raw
)
return
block
}
// Creates a new block. This is currently for testing
func
New
Block
(
/* TODO use raw data */
transactions
[]
*
Transaction
)
*
Block
{
func
Create
Block
(
/* TODO use raw data */
transactions
[]
*
Transaction
)
*
Block
{
block
:=
&
Block
{
// Slice of transactions to include in this block
transactions
:
transactions
,
...
...
@@ -33,8 +43,7 @@ func NewBlock(/* TODO use raw data */transactions []*Transaction) *Block {
coinbase
:
"me"
,
difficulty
:
10
,
nonce
:
0
,
time
:
time
.
Now
(),
time
:
time
.
Now
()
.
Unix
(),
}
return
block
...
...
@@ -65,15 +74,18 @@ func (block *Block) MarshalRlp() []byte {
block
.
coinbase
,
// root state
""
,
string
(
Sha256Bin
([]
byte
(
RlpEncode
(
encTx
)))),
// Sha of tx
string
(
Sha256Bin
([]
byte
(
Encode
(
encTx
)))),
block
.
difficulty
,
block
.
time
.
String
(
),
uint64
(
block
.
time
),
block
.
nonce
,
//
extra
?
block
.
extra
,
}
// TODO
uncles
:=
[]
interface
{}{}
// Encode a slice interface which contains the header and the list of transactions.
return
Encode
([]
interface
{}{
header
,
encTx
})
return
Encode
([]
interface
{}{
header
,
encTx
,
uncles
})
}
func
(
block
*
Block
)
UnmarshalRlp
(
data
[]
byte
)
{
...
...
@@ -109,13 +121,21 @@ func (block *Block) UnmarshalRlp(data []byte) {
block
.
difficulty
=
uint32
(
difficulty
)
}
if
time
,
ok
:=
header
[
7
]
.
([]
byte
);
ok
{
fmt
.
Sprintf
(
"Time is: "
,
string
(
time
))
// It's either 8bit or 64
if
time
,
ok
:=
header
[
7
]
.
(
uint8
);
ok
{
block
.
time
=
int64
(
time
)
}
if
time
,
ok
:=
header
[
7
]
.
(
uint64
);
ok
{
block
.
time
=
int64
(
time
)
}
if
nonce
,
ok
:=
header
[
8
]
.
(
uint8
);
ok
{
block
.
nonce
=
uint32
(
nonce
)
}
if
extra
,
ok
:=
header
[
9
]
.
([]
byte
);
ok
{
block
.
extra
=
string
(
extra
)
}
}
if
txSlice
,
ok
:=
slice
[
1
]
.
([]
interface
{});
ok
{
...
...
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