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
da50c751
Commit
da50c751
authored
Aug 06, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added state dump method
parent
4edf7cfb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
18 deletions
+71
-18
block_chain.go
ethchain/block_chain.go
+12
-4
mnemonic.go
ethcrypto/mnemonic.go
+0
-3
pub.go
ethpub/pub.go
+12
-11
dump.go
ethstate/dump.go
+47
-0
No files found.
ethchain/block_chain.go
View file @
da50c751
...
...
@@ -290,7 +290,6 @@ func (bc *BlockChain) setLastBlock() {
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"LastBlock"
))
if
len
(
data
)
!=
0
{
block
:=
NewBlockFromBytes
(
data
)
//info := bc.BlockInfo(block)
bc
.
CurrentBlock
=
block
bc
.
LastBlockHash
=
block
.
Hash
()
bc
.
LastBlockNumber
=
block
.
Number
.
Uint64
()
...
...
@@ -301,9 +300,6 @@ func (bc *BlockChain) setLastBlock() {
bc
.
genesisBlock
.
state
.
Trie
.
Sync
()
// Prepare the genesis block
bc
.
Add
(
bc
.
genesisBlock
)
//chainlogger.Infof("root %x\n", bm.bc.genesisBlock.State().Root)
//bm.bc.genesisBlock.PrintHash()
}
// Set the last know difficulty (might be 0x0 as initial value, Genesis)
...
...
@@ -339,6 +335,18 @@ func (bc *BlockChain) GetBlock(hash []byte) *Block {
return
NewBlockFromBytes
(
data
)
}
func
(
self
*
BlockChain
)
GetBlockByNumber
(
num
uint64
)
*
Block
{
block
:=
self
.
CurrentBlock
for
;
block
.
Number
.
Uint64
()
!=
num
;
block
=
self
.
GetBlock
(
block
.
PrevHash
)
{
}
if
block
.
Number
.
Uint64
()
==
0
&&
num
!=
0
{
return
nil
}
return
block
}
func
(
bc
*
BlockChain
)
BlockInfoByHash
(
hash
[]
byte
)
BlockInfo
{
bi
:=
BlockInfo
{}
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
(
append
(
hash
,
[]
byte
(
"Info"
)
...
))
...
...
ethcrypto/mnemonic.go
View file @
da50c751
...
...
@@ -13,12 +13,9 @@ import (
func
InitWords
(
wordsPath
string
)
{
filename
:=
path
.
Join
(
wordsPath
,
"mnemonic.words.lst"
)
if
_
,
err
:=
os
.
Stat
(
filename
);
os
.
IsNotExist
(
err
)
{
fmt
.
Printf
(
"reading mnemonic word list file from supplied path not found. Looked in %s. Trying next option.
\n
"
,
filename
)
dir
:=
path
.
Join
(
os
.
Getenv
(
"GOPATH"
),
"src"
,
"github.com"
,
"ethereum"
,
"eth-go"
,
"ethcrypto"
)
filename
=
path
.
Join
(
dir
,
"mnemonic.words.lst"
)
if
_
,
err
:=
os
.
Stat
(
filename
);
os
.
IsNotExist
(
err
)
{
fmt
.
Printf
(
"reading mnemonic word list file 'mnemonic.words.lst' from source folder failed: %s.
\n
"
,
filename
)
dir
,
err
:=
filepath
.
Abs
(
filepath
.
Dir
(
os
.
Args
[
0
]))
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"problem getting current folder: "
,
err
))
...
...
ethpub/pub.go
View file @
da50c751
...
...
@@ -3,14 +3,15 @@ package ethpub
import
(
"bytes"
"encoding/json"
"math/big"
"strings"
"sync/atomic"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"math/big"
"strings"
"sync/atomic"
)
var
logger
=
ethlog
.
NewLogger
(
"PUB"
)
...
...
@@ -165,14 +166,6 @@ func (lib *PEthereum) SecretToAddress(key string) string {
return
ethutil
.
Bytes2Hex
(
pair
.
Address
())
}
func
(
lib
*
PEthereum
)
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
*
PReceipt
,
error
)
{
return
lib
.
createTx
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
)
}
func
(
lib
*
PEthereum
)
Create
(
key
,
valueStr
,
gasStr
,
gasPriceStr
,
script
string
)
(
*
PReceipt
,
error
)
{
return
lib
.
createTx
(
key
,
""
,
valueStr
,
gasStr
,
gasPriceStr
,
script
)
}
func
FindAddressInNameReg
(
stateManager
*
ethchain
.
StateManager
,
name
string
)
[]
byte
{
nameReg
:=
EthereumConfig
(
stateManager
)
.
NameReg
()
if
nameReg
!=
nil
{
...
...
@@ -199,6 +192,14 @@ func FindNameInNameReg(stateManager *ethchain.StateManager, addr []byte) string
return
""
}
func
(
lib
*
PEthereum
)
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
*
PReceipt
,
error
)
{
return
lib
.
createTx
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
)
}
func
(
lib
*
PEthereum
)
Create
(
key
,
valueStr
,
gasStr
,
gasPriceStr
,
script
string
)
(
*
PReceipt
,
error
)
{
return
lib
.
createTx
(
key
,
""
,
valueStr
,
gasStr
,
gasPriceStr
,
script
)
}
func
(
lib
*
PEthereum
)
createTx
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
scriptStr
string
)
(
*
PReceipt
,
error
)
{
var
hash
[]
byte
var
contractCreation
bool
...
...
ethstate/dump.go
0 → 100644
View file @
da50c751
package
ethstate
import
(
"encoding/json"
"fmt"
"github.com/ethereum/eth-go/ethutil"
)
type
Account
struct
{
Balance
string
`json:"balance"`
Nonce
uint64
`json:"nonce"`
CodeHash
string
`json:"codeHash"`
Storage
map
[
string
]
string
`json:"storage"`
}
type
World
struct
{
Root
string
`json:"root"`
Accounts
map
[
string
]
Account
`json:"accounts"`
}
func
(
self
*
State
)
Dump
()
string
{
world
:=
World
{
Root
:
ethutil
.
Bytes2Hex
(
self
.
Trie
.
Root
.
([]
byte
)),
Accounts
:
make
(
map
[
string
]
Account
),
}
self
.
Trie
.
NewIterator
()
.
Each
(
func
(
key
string
,
value
*
ethutil
.
Value
)
{
stateObject
:=
NewStateObjectFromBytes
([]
byte
(
key
),
value
.
Bytes
())
account
:=
Account
{
Balance
:
stateObject
.
Balance
.
String
(),
Nonce
:
stateObject
.
Nonce
,
CodeHash
:
ethutil
.
Bytes2Hex
(
stateObject
.
CodeHash
)}
account
.
Storage
=
make
(
map
[
string
]
string
)
stateObject
.
EachStorage
(
func
(
key
string
,
value
*
ethutil
.
Value
)
{
value
.
Decode
()
account
.
Storage
[
ethutil
.
Bytes2Hex
([]
byte
(
key
))]
=
ethutil
.
Bytes2Hex
(
value
.
Bytes
())
})
world
.
Accounts
[
ethutil
.
Bytes2Hex
([]
byte
(
key
))]
=
account
})
json
,
err
:=
json
.
MarshalIndent
(
world
,
""
,
" "
)
if
err
!=
nil
{
fmt
.
Println
(
"dump err"
,
err
)
}
return
string
(
json
)
}
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