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
cca85855
Commit
cca85855
authored
Feb 21, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get a chain of blocks made simple
parent
18cc3533
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
block_chain.go
ethchain/block_chain.go
+23
-0
No files found.
ethchain/block_chain.go
View file @
cca85855
...
...
@@ -2,6 +2,7 @@ package ethchain
import
(
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethutil"
"log"
"math"
...
...
@@ -111,6 +112,25 @@ func (bc *BlockChain) GetChainFromHash(hash []byte, max uint64) []interface{} {
return
chain
}
func
(
bc
*
BlockChain
)
GetChain
(
hash
[]
byte
,
amount
int
)
[]
*
Block
{
genHash
:=
bc
.
genesisBlock
.
Hash
()
block
:=
bc
.
GetBlock
(
hash
)
var
blocks
[]
*
Block
for
i
:=
0
;
i
<
amount
&&
block
!=
nil
;
block
=
bc
.
GetBlock
(
block
.
PrevHash
)
{
fmt
.
Println
(
block
)
blocks
=
append
([]
*
Block
{
block
},
blocks
...
)
if
bytes
.
Compare
(
genHash
,
block
.
Hash
())
==
0
{
break
}
i
++
}
return
blocks
}
func
(
bc
*
BlockChain
)
setLastBlock
()
{
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"LastBlock"
))
if
len
(
data
)
!=
0
{
...
...
@@ -147,6 +167,9 @@ func (bc *BlockChain) Add(block *Block) {
func
(
bc
*
BlockChain
)
GetBlock
(
hash
[]
byte
)
*
Block
{
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
(
hash
)
if
len
(
data
)
==
0
{
return
nil
}
return
NewBlockFromData
(
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