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
a1c5d5ac
Commit
a1c5d5ac
authored
Dec 29, 2013
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Comments
parent
5198b7b9
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
5 deletions
+28
-5
big.go
big.go
+6
-0
block.go
block.go
+18
-4
block_manager.go
block_manager.go
+3
-0
ethereum.go
ethereum.go
+0
-1
transaction.go
transaction.go
+1
-0
No files found.
big.go
View file @
a1c5d5ac
...
@@ -4,6 +4,9 @@ import (
...
@@ -4,6 +4,9 @@ import (
"math/big"
"math/big"
)
)
/*
* Returns the power of two integers
*/
func
BigPow
(
a
,
b
int
)
*
big
.
Int
{
func
BigPow
(
a
,
b
int
)
*
big
.
Int
{
c
:=
new
(
big
.
Int
)
c
:=
new
(
big
.
Int
)
c
.
Exp
(
big
.
NewInt
(
int64
(
a
)),
big
.
NewInt
(
int64
(
b
)),
big
.
NewInt
(
0
))
c
.
Exp
(
big
.
NewInt
(
int64
(
a
)),
big
.
NewInt
(
int64
(
b
)),
big
.
NewInt
(
0
))
...
@@ -11,6 +14,9 @@ func BigPow(a,b int) *big.Int {
...
@@ -11,6 +14,9 @@ func BigPow(a,b int) *big.Int {
return
c
return
c
}
}
/*
* Like big.NewInt(uint64); this takes a string instead.
*/
func
Big
(
num
string
)
*
big
.
Int
{
func
Big
(
num
string
)
*
big
.
Int
{
n
:=
new
(
big
.
Int
)
n
:=
new
(
big
.
Int
)
n
.
SetString
(
num
,
0
)
n
.
SetString
(
num
,
0
)
...
...
block.go
View file @
a1c5d5ac
...
@@ -7,17 +7,23 @@ import (
...
@@ -7,17 +7,23 @@ import (
)
)
type
Block
struct
{
type
Block
struct
{
// The number of this block
number
uint32
number
uint32
// Hash to the previous block
prevHash
string
prevHash
string
// Uncles of this block
uncles
[]
*
Block
uncles
[]
*
Block
coinbase
string
coinbase
string
// state xxx
// state xxx
difficulty
uint32
difficulty
uint32
// Creation time
time
time
.
Time
time
time
.
Time
nonce
uint32
nonce
uint32
// List of transactions and/or contracts
transactions
[]
*
Transaction
transactions
[]
*
Transaction
}
}
// Creates a new block. This is currently for testing
func
NewBlock
(
/* TODO use raw data */
transactions
[]
*
Transaction
)
*
Block
{
func
NewBlock
(
/* TODO use raw data */
transactions
[]
*
Transaction
)
*
Block
{
block
:=
&
Block
{
block
:=
&
Block
{
// Slice of transactions to include in this block
// Slice of transactions to include in this block
...
@@ -37,14 +43,16 @@ func NewBlock(/* TODO use raw data */transactions []*Transaction) *Block {
...
@@ -37,14 +43,16 @@ func NewBlock(/* TODO use raw data */transactions []*Transaction) *Block {
func
(
block
*
Block
)
Update
()
{
func
(
block
*
Block
)
Update
()
{
}
}
// Returns a hash of the block
func
(
block
*
Block
)
Hash
()
string
{
func
(
block
*
Block
)
Hash
()
string
{
return
Sha256Hex
(
block
.
MarshalRlp
())
return
Sha256Hex
(
block
.
MarshalRlp
())
}
}
func
(
block
*
Block
)
MarshalRlp
()
[]
byte
{
func
(
block
*
Block
)
MarshalRlp
()
[]
byte
{
//
Encoding method requires []interface{} type. It's actual a slice of strings
//
Marshal the transactions of this block
encTx
:=
make
([]
string
,
len
(
block
.
transactions
))
encTx
:=
make
([]
string
,
len
(
block
.
transactions
))
for
i
,
tx
:=
range
block
.
transactions
{
for
i
,
tx
:=
range
block
.
transactions
{
// Cast it to a string (safe)
encTx
[
i
]
=
string
(
tx
.
MarshalRlp
())
encTx
[
i
]
=
string
(
tx
.
MarshalRlp
())
}
}
...
@@ -64,14 +72,16 @@ func (block *Block) MarshalRlp() []byte {
...
@@ -64,14 +72,16 @@ func (block *Block) MarshalRlp() []byte {
// extra?
// extra?
}
}
encoded
:=
Encode
([]
interface
{}{
header
,
encTx
})
// Encode a slice interface which contains the header and the list of transactions.
return
Encode
([]
interface
{}{
header
,
encTx
})
return
encoded
}
}
func
(
block
*
Block
)
UnmarshalRlp
(
data
[]
byte
)
{
func
(
block
*
Block
)
UnmarshalRlp
(
data
[]
byte
)
{
t
,
_
:=
Decode
(
data
,
0
)
t
,
_
:=
Decode
(
data
,
0
)
// interface slice assertion
if
slice
,
ok
:=
t
.
([]
interface
{});
ok
{
if
slice
,
ok
:=
t
.
([]
interface
{});
ok
{
// interface slice assertion
if
header
,
ok
:=
slice
[
0
]
.
([]
interface
{});
ok
{
if
header
,
ok
:=
slice
[
0
]
.
([]
interface
{});
ok
{
if
number
,
ok
:=
header
[
0
]
.
(
uint8
);
ok
{
if
number
,
ok
:=
header
[
0
]
.
(
uint8
);
ok
{
block
.
number
=
uint32
(
number
)
block
.
number
=
uint32
(
number
)
...
@@ -109,11 +119,15 @@ func (block *Block) UnmarshalRlp(data []byte) {
...
@@ -109,11 +119,15 @@ func (block *Block) UnmarshalRlp(data []byte) {
}
}
if
txSlice
,
ok
:=
slice
[
1
]
.
([]
interface
{});
ok
{
if
txSlice
,
ok
:=
slice
[
1
]
.
([]
interface
{});
ok
{
// Create transaction slice equal to decoded tx interface slice
block
.
transactions
=
make
([]
*
Transaction
,
len
(
txSlice
))
block
.
transactions
=
make
([]
*
Transaction
,
len
(
txSlice
))
// Unmarshal transactions
for
i
,
tx
:=
range
txSlice
{
for
i
,
tx
:=
range
txSlice
{
if
t
,
ok
:=
tx
.
([]
byte
);
ok
{
if
t
,
ok
:=
tx
.
([]
byte
);
ok
{
tx
:=
&
Transaction
{}
tx
:=
&
Transaction
{}
// Use the unmarshaled data to unmarshal the transaction
// t is still decoded.
tx
.
UnmarshalRlp
(
t
)
tx
.
UnmarshalRlp
(
t
)
block
.
transactions
[
i
]
=
tx
block
.
transactions
[
i
]
=
tx
...
...
block_manager.go
View file @
a1c5d5ac
...
@@ -26,9 +26,12 @@ func NewBlockManager() *BlockManager {
...
@@ -26,9 +26,12 @@ func NewBlockManager() *BlockManager {
// Process a block.
// Process a block.
func
(
bm
*
BlockManager
)
ProcessBlock
(
block
*
Block
)
error
{
func
(
bm
*
BlockManager
)
ProcessBlock
(
block
*
Block
)
error
{
// Get the tx count. Used to create enough channels to 'join' the go routines
txCount
:=
len
(
block
.
transactions
)
txCount
:=
len
(
block
.
transactions
)
// Locking channel. When it has been fully buffered this method will return
lockChan
:=
make
(
chan
bool
,
txCount
)
lockChan
:=
make
(
chan
bool
,
txCount
)
// Process each transaction/contract
for
_
,
tx
:=
range
block
.
transactions
{
for
_
,
tx
:=
range
block
.
transactions
{
go
bm
.
ProcessTransaction
(
tx
,
lockChan
)
go
bm
.
ProcessTransaction
(
tx
,
lockChan
)
}
}
...
...
ethereum.go
View file @
a1c5d5ac
...
@@ -37,7 +37,6 @@ func main() {
...
@@ -37,7 +37,6 @@ func main() {
bm
.
ProcessBlock
(
blck
)
bm
.
ProcessBlock
(
blck
)
t
:=
blck
.
MarshalRlp
()
t
:=
blck
.
MarshalRlp
()
copyBlock
:=
&
Block
{}
copyBlock
:=
&
Block
{}
copyBlock
.
UnmarshalRlp
(
t
)
copyBlock
.
UnmarshalRlp
(
t
)
...
...
transaction.go
View file @
a1c5d5ac
...
@@ -125,6 +125,7 @@ func (tx *Transaction) UnmarshalRlp(data []byte) {
...
@@ -125,6 +125,7 @@ func (tx *Transaction) UnmarshalRlp(data []byte) {
tx
.
fee
=
uint32
(
fee
)
tx
.
fee
=
uint32
(
fee
)
}
}
// Encode the data/instructions
if
data
,
ok
:=
slice
[
5
]
.
([]
interface
{});
ok
{
if
data
,
ok
:=
slice
[
5
]
.
([]
interface
{});
ok
{
tx
.
data
=
make
([]
string
,
len
(
data
))
tx
.
data
=
make
([]
string
,
len
(
data
))
for
i
,
d
:=
range
data
{
for
i
,
d
:=
range
data
{
...
...
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