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
dabaa4cc
Commit
dabaa4cc
authored
Jun 29, 2014
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change all modified calls to ethtrie, ethutil and ethcrypto functions
parent
707d4137
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
91 additions
and
83 deletions
+91
-83
block.go
ethchain/block.go
+9
-7
block_chain.go
ethchain/block_chain.go
+1
-1
dagger.go
ethchain/dagger.go
+2
-1
genesis.go
ethchain/genesis.go
+4
-3
state.go
ethchain/state.go
+3
-2
state_manager.go
ethchain/state_manager.go
+3
-1
state_object.go
ethchain/state_object.go
+7
-4
transaction.go
ethchain/transaction.go
+4
-3
vm.go
ethchain/vm.go
+3
-2
ethereum.go
ethereum.go
+11
-7
pub.go
ethpub/pub.go
+16
-20
types.go
ethpub/types.go
+19
-19
packages.go
ethrpc/packages.go
+1
-1
peer.go
peer.go
+8
-12
No files found.
ethchain/block.go
View file @
dabaa4cc
...
...
@@ -3,6 +3,8 @@ package ethchain
import
(
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
"math/big"
"strconv"
...
...
@@ -102,18 +104,18 @@ func CreateBlock(root interface{},
}
block
.
SetUncles
([]
*
Block
{})
block
.
state
=
NewState
(
eth
util
.
NewTrie
(
ethutil
.
Config
.
Db
,
root
))
block
.
state
=
NewState
(
eth
trie
.
NewTrie
(
ethutil
.
Config
.
Db
,
root
))
return
block
}
// Returns a hash of the block
func
(
block
*
Block
)
Hash
()
[]
byte
{
return
eth
util
.
Sha3Bin
(
block
.
Value
()
.
Encode
())
return
eth
crypto
.
Sha3Bin
(
block
.
Value
()
.
Encode
())
}
func
(
block
*
Block
)
HashNoNonce
()
[]
byte
{
return
eth
util
.
Sha3Bin
(
ethutil
.
Encode
([]
interface
{}{
block
.
PrevHash
,
return
eth
crypto
.
Sha3Bin
(
ethutil
.
Encode
([]
interface
{}{
block
.
PrevHash
,
block
.
UncleSha
,
block
.
Coinbase
,
block
.
state
.
trie
.
Root
,
block
.
TxSha
,
block
.
Difficulty
,
block
.
Number
,
block
.
MinGasPrice
,
block
.
GasLimit
,
block
.
GasUsed
,
block
.
Time
,
block
.
Extra
}))
...
...
@@ -239,7 +241,7 @@ func (block *Block) SetUncles(uncles []*Block) {
block
.
Uncles
=
uncles
// Sha of the concatenated uncles
block
.
UncleSha
=
eth
util
.
Sha3Bin
(
ethutil
.
Encode
(
block
.
rlpUncles
()))
block
.
UncleSha
=
eth
crypto
.
Sha3Bin
(
ethutil
.
Encode
(
block
.
rlpUncles
()))
}
func
(
self
*
Block
)
SetReceipts
(
receipts
[]
*
Receipt
,
txs
[]
*
Transaction
)
{
...
...
@@ -250,7 +252,7 @@ func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) {
func
(
block
*
Block
)
setTransactions
(
txs
[]
*
Transaction
)
{
block
.
transactions
=
txs
trie
:=
eth
util
.
NewTrie
(
ethutil
.
Config
.
Db
,
""
)
trie
:=
eth
trie
.
NewTrie
(
ethutil
.
Config
.
Db
,
""
)
for
i
,
tx
:=
range
txs
{
trie
.
Update
(
strconv
.
Itoa
(
i
),
string
(
tx
.
RlpEncode
()))
}
...
...
@@ -287,7 +289,7 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) {
block
.
PrevHash
=
header
.
Get
(
0
)
.
Bytes
()
block
.
UncleSha
=
header
.
Get
(
1
)
.
Bytes
()
block
.
Coinbase
=
header
.
Get
(
2
)
.
Bytes
()
block
.
state
=
NewState
(
eth
util
.
NewTrie
(
ethutil
.
Config
.
Db
,
header
.
Get
(
3
)
.
Val
))
block
.
state
=
NewState
(
eth
trie
.
NewTrie
(
ethutil
.
Config
.
Db
,
header
.
Get
(
3
)
.
Val
))
block
.
TxSha
=
header
.
Get
(
4
)
.
Bytes
()
block
.
Difficulty
=
header
.
Get
(
5
)
.
BigInt
()
block
.
Number
=
header
.
Get
(
6
)
.
BigInt
()
...
...
@@ -329,7 +331,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block {
block
.
PrevHash
=
header
.
Get
(
0
)
.
Bytes
()
block
.
UncleSha
=
header
.
Get
(
1
)
.
Bytes
()
block
.
Coinbase
=
header
.
Get
(
2
)
.
Bytes
()
block
.
state
=
NewState
(
eth
util
.
NewTrie
(
ethutil
.
Config
.
Db
,
header
.
Get
(
3
)
.
Val
))
block
.
state
=
NewState
(
eth
trie
.
NewTrie
(
ethutil
.
Config
.
Db
,
header
.
Get
(
3
)
.
Val
))
block
.
TxSha
=
header
.
Get
(
4
)
.
Bytes
()
block
.
Difficulty
=
header
.
Get
(
5
)
.
BigInt
()
block
.
Number
=
header
.
Get
(
6
)
.
BigInt
()
...
...
ethchain/block_chain.go
View file @
dabaa4cc
...
...
@@ -278,7 +278,7 @@ func AddTestNetFunds(block *Block) {
"e6716f9544a56c530d868e4bfbacb172315bdead"
,
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4"
,
}
{
codedAddr
:=
ethutil
.
FromHex
(
addr
)
codedAddr
:=
ethutil
.
Hex2Bytes
(
addr
)
account
:=
block
.
state
.
GetAccount
(
codedAddr
)
account
.
Amount
=
ethutil
.
Big
(
"1606938044258990275541962092341162602522202993782792835301376"
)
//ethutil.BigPow(2, 200)
block
.
state
.
UpdateStateObject
(
account
)
...
...
ethchain/dagger.go
View file @
dabaa4cc
package
ethchain
import
(
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/sha3"
...
...
@@ -40,7 +41,7 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethutil.React) []byte {
powlogger
.
Infoln
(
"Hashing @"
,
int64
(
hashes
),
"khash"
)
}
sha
:=
eth
util
.
Sha3Bin
(
big
.
NewInt
(
r
.
Int63
())
.
Bytes
())
sha
:=
eth
crypto
.
Sha3Bin
(
big
.
NewInt
(
r
.
Int63
())
.
Bytes
())
if
pow
.
Verify
(
hash
,
diff
,
sha
)
{
return
sha
}
...
...
ethchain/genesis.go
View file @
dabaa4cc
package
ethchain
import
(
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethutil"
"math/big"
)
...
...
@@ -11,13 +12,13 @@ import (
var
ZeroHash256
=
make
([]
byte
,
32
)
var
ZeroHash160
=
make
([]
byte
,
20
)
var
EmptyShaList
=
eth
util
.
Sha3Bin
(
ethutil
.
Encode
([]
interface
{}{}))
var
EmptyShaList
=
eth
crypto
.
Sha3Bin
(
ethutil
.
Encode
([]
interface
{}{}))
var
GenesisHeader
=
[]
interface
{}{
// Previous hash (none)
ZeroHash256
,
// Sha of uncles
eth
util
.
Sha3Bin
(
ethutil
.
Encode
([]
interface
{}{})),
eth
crypto
.
Sha3Bin
(
ethutil
.
Encode
([]
interface
{}{})),
// Coinbase
ZeroHash160
,
// Root state
...
...
@@ -39,7 +40,7 @@ var GenesisHeader = []interface{}{
// Extra
nil
,
// Nonce
eth
util
.
Sha3Bin
(
big
.
NewInt
(
42
)
.
Bytes
()),
eth
crypto
.
Sha3Bin
(
big
.
NewInt
(
42
)
.
Bytes
()),
}
var
Genesis
=
[]
interface
{}{
GenesisHeader
,
[]
interface
{}{},
[]
interface
{}{}}
ethchain/state.go
View file @
dabaa4cc
package
ethchain
import
(
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
"math/big"
...
...
@@ -74,7 +75,7 @@ func (s *State) Purge() int {
return
s
.
trie
.
NewIterator
()
.
Purge
()
}
func
(
s
*
State
)
EachStorage
(
cb
eth
util
.
EachCallback
)
{
func
(
s
*
State
)
EachStorage
(
cb
eth
trie
.
EachCallback
)
{
it
:=
s
.
trie
.
NewIterator
()
it
.
Each
(
cb
)
}
...
...
@@ -92,7 +93,7 @@ func (self *State) UpdateStateObject(stateObject *StateObject) {
self
.
stateObjects
[
string
(
addr
)]
=
stateObject
}
ethutil
.
Config
.
Db
.
Put
(
eth
util
.
Sha3Bin
(
stateObject
.
Script
()),
stateObject
.
Script
())
ethutil
.
Config
.
Db
.
Put
(
eth
crypto
.
Sha3Bin
(
stateObject
.
Script
()),
stateObject
.
Script
())
self
.
trie
.
Update
(
string
(
addr
),
string
(
stateObject
.
RlpEncode
()))
...
...
ethchain/state_manager.go
View file @
dabaa4cc
...
...
@@ -3,6 +3,7 @@ package ethchain
import
(
"bytes"
"container/list"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
...
...
@@ -38,6 +39,7 @@ type EthManager interface {
IsMining
()
bool
IsListening
()
bool
Peers
()
*
list
.
List
KeyManager
()
*
ethcrypto
.
KeyManager
}
type
StateManager
struct
{
...
...
@@ -293,7 +295,7 @@ func (sm *StateManager) ValidateBlock(block *Block) error {
// Verify the nonce of the block. Return an error if it's not valid
if
!
sm
.
Pow
.
Verify
(
block
.
HashNoNonce
(),
block
.
Difficulty
,
block
.
Nonce
)
{
return
ValidationError
(
"Block's nonce is invalid (= %v)"
,
ethutil
.
Hex
(
block
.
Nonce
))
return
ValidationError
(
"Block's nonce is invalid (= %v)"
,
ethutil
.
Bytes2
Hex
(
block
.
Nonce
))
}
return
nil
...
...
ethchain/state_object.go
View file @
dabaa4cc
...
...
@@ -2,6 +2,8 @@ package ethchain
import
(
"fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
"math/big"
"strings"
...
...
@@ -39,7 +41,7 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
contract
:=
state
.
NewStateObject
(
addr
)
contract
.
initScript
=
tx
.
Data
contract
.
state
=
NewState
(
eth
util
.
NewTrie
(
ethutil
.
Config
.
Db
,
""
))
contract
.
state
=
NewState
(
eth
trie
.
NewTrie
(
ethutil
.
Config
.
Db
,
""
))
return
contract
}
...
...
@@ -53,7 +55,7 @@ func NewStateObject(addr []byte) *StateObject {
func
NewContract
(
address
[]
byte
,
Amount
*
big
.
Int
,
root
[]
byte
)
*
StateObject
{
contract
:=
&
StateObject
{
address
:
address
,
Amount
:
Amount
,
Nonce
:
0
}
contract
.
state
=
NewState
(
eth
util
.
NewTrie
(
ethutil
.
Config
.
Db
,
string
(
root
)))
contract
.
state
=
NewState
(
eth
trie
.
NewTrie
(
ethutil
.
Config
.
Db
,
string
(
root
)))
return
contract
}
...
...
@@ -246,7 +248,7 @@ func (c *StateObject) RlpEncode() []byte {
root
=
""
}
return
ethutil
.
Encode
([]
interface
{}{
c
.
Nonce
,
c
.
Amount
,
root
,
eth
util
.
Sha3Bin
(
c
.
script
)})
return
ethutil
.
Encode
([]
interface
{}{
c
.
Nonce
,
c
.
Amount
,
root
,
eth
crypto
.
Sha3Bin
(
c
.
script
)})
}
func
(
c
*
StateObject
)
RlpDecode
(
data
[]
byte
)
{
...
...
@@ -254,7 +256,8 @@ func (c *StateObject) RlpDecode(data []byte) {
c
.
Nonce
=
decoder
.
Get
(
0
)
.
Uint
()
c
.
Amount
=
decoder
.
Get
(
1
)
.
BigInt
()
c
.
state
=
NewState
(
ethutil
.
NewTrie
(
ethutil
.
Config
.
Db
,
decoder
.
Get
(
2
)
.
Interface
()))
c
.
state
=
NewState
(
ethtrie
.
NewTrie
(
ethutil
.
Config
.
Db
,
decoder
.
Get
(
2
)
.
Interface
()))
c
.
state
=
NewState
(
ethtrie
.
NewTrie
(
ethutil
.
Config
.
Db
,
decoder
.
Get
(
2
)
.
Interface
()))
c
.
ScriptHash
=
decoder
.
Get
(
3
)
.
Bytes
()
...
...
ethchain/transaction.go
View file @
dabaa4cc
...
...
@@ -3,6 +3,7 @@ package ethchain
import
(
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/secp256k1-go"
"math/big"
...
...
@@ -62,7 +63,7 @@ func (self *Transaction) TotalValue() *big.Int {
func
(
tx
*
Transaction
)
Hash
()
[]
byte
{
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
GasPrice
,
tx
.
Gas
,
tx
.
Recipient
,
tx
.
Value
,
tx
.
Data
}
return
eth
util
.
Sha3Bin
(
ethutil
.
NewValue
(
data
)
.
Encode
())
return
eth
crypto
.
Sha3Bin
(
ethutil
.
NewValue
(
data
)
.
Encode
())
}
func
(
tx
*
Transaction
)
CreatesContract
()
bool
{
...
...
@@ -75,7 +76,7 @@ func (tx *Transaction) IsContract() bool {
}
func
(
tx
*
Transaction
)
CreationAddress
()
[]
byte
{
return
eth
util
.
Sha3Bin
(
ethutil
.
NewValue
([]
interface
{}{
tx
.
Sender
(),
tx
.
Nonce
})
.
Encode
())[
12
:
]
return
eth
crypto
.
Sha3Bin
(
ethutil
.
NewValue
([]
interface
{}{
tx
.
Sender
(),
tx
.
Nonce
})
.
Encode
())[
12
:
]
}
func
(
tx
*
Transaction
)
Signature
(
key
[]
byte
)
[]
byte
{
...
...
@@ -111,7 +112,7 @@ func (tx *Transaction) Sender() []byte {
return
nil
}
return
eth
util
.
Sha3Bin
(
pubkey
[
1
:
])[
12
:
]
return
eth
crypto
.
Sha3Bin
(
pubkey
[
1
:
])[
12
:
]
}
func
(
tx
*
Transaction
)
Sign
(
privk
[]
byte
)
error
{
...
...
ethchain/vm.go
View file @
dabaa4cc
...
...
@@ -2,6 +2,7 @@ package ethchain
import
(
"fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil"
"math"
...
...
@@ -398,7 +399,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
case
SHA3
:
require
(
2
)
size
,
offset
:=
stack
.
Popn
()
data
:=
eth
util
.
Sha3Bin
(
mem
.
Get
(
offset
.
Int64
(),
size
.
Int64
()))
data
:=
eth
crypto
.
Sha3Bin
(
mem
.
Get
(
offset
.
Int64
(),
size
.
Int64
()))
stack
.
Push
(
ethutil
.
BigD
(
data
))
// 0x30 range
...
...
@@ -594,7 +595,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
snapshot
:=
vm
.
state
.
Copy
()
// Generate a new address
addr
:=
eth
util
.
CreateAddress
(
closure
.
caller
.
Address
(),
closure
.
caller
.
N
())
addr
:=
eth
crypto
.
CreateAddress
(
closure
.
caller
.
Address
(),
closure
.
caller
.
N
())
vm
.
Printf
(
" (*) %x"
,
addr
)
.
Endl
()
...
...
ethereum.go
View file @
dabaa4cc
...
...
@@ -4,7 +4,7 @@ import (
"container/list"
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/eth
db
"
"github.com/ethereum/eth-go/eth
crypto
"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethrpc"
"github.com/ethereum/eth-go/ethutil"
...
...
@@ -74,16 +74,15 @@ type Ethereum struct {
reactor
*
ethutil
.
ReactorEngine
RpcServer
*
ethrpc
.
JsonRpcServer
keyManager
*
ethcrypto
.
KeyManager
}
func
New
(
caps
Caps
,
usePnp
bool
)
(
*
Ethereum
,
error
)
{
db
,
err
:=
ethdb
.
NewLDBDatabase
(
"database"
)
//db, err := ethdb.NewMemDatabase()
if
err
!=
nil
{
return
nil
,
err
}
func
New
(
db
ethutil
.
Database
,
keyManager
*
ethcrypto
.
KeyManager
,
caps
Caps
,
usePnp
bool
)
(
*
Ethereum
,
error
)
{
var
err
error
var
nat
NAT
if
usePnp
{
nat
,
err
=
Discover
()
if
err
!=
nil
{
...
...
@@ -102,6 +101,7 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) {
Nonce
:
nonce
,
serverCaps
:
caps
,
nat
:
nat
,
keyManager
:
keyManager
,
}
ethereum
.
reactor
=
ethutil
.
NewReactorEngine
()
...
...
@@ -119,6 +119,10 @@ func (s *Ethereum) Reactor() *ethutil.ReactorEngine {
return
s
.
reactor
}
func
(
s
*
Ethereum
)
KeyManager
()
*
ethcrypto
.
KeyManager
{
return
s
.
keyManager
}
func
(
s
*
Ethereum
)
BlockChain
()
*
ethchain
.
BlockChain
{
return
s
.
blockChain
}
...
...
ethpub/pub.go
View file @
dabaa4cc
...
...
@@ -2,9 +2,9 @@ package ethpub
import
(
"bytes"
"encoding/hex"
"encoding/json"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil"
"math/big"
...
...
@@ -19,6 +19,7 @@ type PEthereum struct {
stateManager
*
ethchain
.
StateManager
blockChain
*
ethchain
.
BlockChain
txPool
*
ethchain
.
TxPool
keyManager
*
ethcrypto
.
KeyManager
}
func
NewPEthereum
(
manager
ethchain
.
EthManager
)
*
PEthereum
{
...
...
@@ -27,24 +28,23 @@ func NewPEthereum(manager ethchain.EthManager) *PEthereum {
manager
.
StateManager
(),
manager
.
BlockChain
(),
manager
.
TxPool
(),
manager
.
KeyManager
(),
}
}
func
(
lib
*
PEthereum
)
GetBlock
(
hexHash
string
)
*
PBlock
{
hash
:=
ethutil
.
FromHex
(
hexHash
)
hash
:=
ethutil
.
Hex2Bytes
(
hexHash
)
block
:=
lib
.
blockChain
.
GetBlock
(
hash
)
return
NewPBlock
(
block
)
}
func
(
lib
*
PEthereum
)
GetKey
()
*
PKey
{
keyPair
:=
ethutil
.
GetKeyRing
()
.
Get
(
0
)
return
NewPKey
(
keyPair
)
return
NewPKey
(
lib
.
keyManager
.
KeyPair
())
}
func
(
lib
*
PEthereum
)
GetStateObject
(
address
string
)
*
PStateObject
{
stateObject
:=
lib
.
stateManager
.
CurrentState
()
.
GetStateObject
(
ethutil
.
FromHex
(
address
))
stateObject
:=
lib
.
stateManager
.
CurrentState
()
.
GetStateObject
(
ethutil
.
Hex2Bytes
(
address
))
if
stateObject
!=
nil
{
return
NewPStateObject
(
stateObject
)
}
...
...
@@ -79,17 +79,13 @@ func (lib *PEthereum) GetIsListening() bool {
}
func
(
lib
*
PEthereum
)
GetCoinBase
()
string
{
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
keyRing
:=
ethutil
.
NewValueFromBytes
(
data
)
key
:=
keyRing
.
Get
(
0
)
.
Bytes
()
return
lib
.
SecretToAddress
(
hex
.
EncodeToString
(
key
))
return
ethutil
.
Bytes2Hex
(
lib
.
keyManager
.
Address
())
}
func
(
lib
*
PEthereum
)
GetTransactionsFor
(
address
string
,
asJson
bool
)
interface
{}
{
sBlk
:=
lib
.
manager
.
BlockChain
()
.
LastBlockHash
blk
:=
lib
.
manager
.
BlockChain
()
.
GetBlock
(
sBlk
)
addr
:=
[]
byte
(
ethutil
.
FromHex
(
address
))
addr
:=
[]
byte
(
ethutil
.
Hex2Bytes
(
address
))
var
txs
[]
*
PTx
...
...
@@ -129,12 +125,12 @@ func (lib *PEthereum) IsContract(address string) bool {
}
func
(
lib
*
PEthereum
)
SecretToAddress
(
key
string
)
string
{
pair
,
err
:=
eth
util
.
NewKeyPairFromSec
(
ethutil
.
FromHex
(
key
))
pair
,
err
:=
eth
crypto
.
NewKeyPairFromSec
(
ethutil
.
Hex2Bytes
(
key
))
if
err
!=
nil
{
return
""
}
return
ethutil
.
Hex
(
pair
.
Address
())
return
ethutil
.
Bytes2
Hex
(
pair
.
Address
())
}
func
(
lib
*
PEthereum
)
Transact
(
key
,
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
*
PReceipt
,
error
)
{
...
...
@@ -145,7 +141,7 @@ func (lib *PEthereum) Create(key, valueStr, gasStr, gasPriceStr, script string)
return
lib
.
createTx
(
key
,
""
,
valueStr
,
gasStr
,
gasPriceStr
,
script
)
}
var
namereg
=
ethutil
.
FromHex
(
"bb5f186604d057c1c5240ca2ae0f6430138ac010"
)
var
namereg
=
ethutil
.
Hex2Bytes
(
"bb5f186604d057c1c5240ca2ae0f6430138ac010"
)
func
GetAddressFromNameReg
(
stateManager
*
ethchain
.
StateManager
,
name
string
)
[]
byte
{
recp
:=
new
(
big
.
Int
)
.
SetBytes
([]
byte
(
name
))
...
...
@@ -169,16 +165,16 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, sc
if
len
(
addr
)
>
0
{
hash
=
addr
}
else
{
hash
=
ethutil
.
FromHex
(
recipient
)
hash
=
ethutil
.
Hex2Bytes
(
recipient
)
}
}
var
keyPair
*
eth
util
.
KeyPair
var
keyPair
*
eth
crypto
.
KeyPair
var
err
error
if
key
[
0
:
2
]
==
"0x"
{
keyPair
,
err
=
eth
util
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
FromHex
(
key
[
2
:
])))
keyPair
,
err
=
eth
crypto
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
Hex2Bytes
(
key
[
2
:
])))
}
else
{
keyPair
,
err
=
eth
util
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
FromHex
(
key
)))
keyPair
,
err
=
eth
crypto
.
NewKeyPairFromSec
([]
byte
(
ethutil
.
Hex2Bytes
(
key
)))
}
if
err
!=
nil
{
...
...
@@ -194,7 +190,7 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, sc
var
script
[]
byte
var
err
error
if
ethutil
.
IsHex
(
scriptStr
)
{
script
=
ethutil
.
FromHex
(
scriptStr
)
script
=
ethutil
.
Hex2Bytes
(
scriptStr
[
2
:
]
)
}
else
{
script
,
err
=
ethutil
.
Compile
(
scriptStr
)
if
err
!=
nil
{
...
...
ethpub/types.go
View file @
dabaa4cc
package
ethpub
import
(
"encoding/hex"
"encoding/json"
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethutil"
"strings"
)
...
...
@@ -66,7 +66,7 @@ func NewPBlock(block *ethchain.Block) *PBlock {
return
nil
}
return
&
PBlock
{
ref
:
block
,
Number
:
int
(
block
.
Number
.
Uint64
()),
GasUsed
:
block
.
GasUsed
.
String
(),
GasLimit
:
block
.
GasLimit
.
String
(),
Hash
:
ethutil
.
Hex
(
block
.
Hash
()),
Transactions
:
string
(
txJson
),
Time
:
block
.
Time
,
Coinbase
:
ethutil
.
Hex
(
block
.
Coinbase
)}
return
&
PBlock
{
ref
:
block
,
Number
:
int
(
block
.
Number
.
Uint64
()),
GasUsed
:
block
.
GasUsed
.
String
(),
GasLimit
:
block
.
GasLimit
.
String
(),
Hash
:
ethutil
.
Bytes2Hex
(
block
.
Hash
()),
Transactions
:
string
(
txJson
),
Time
:
block
.
Time
,
Coinbase
:
ethutil
.
Bytes2
Hex
(
block
.
Coinbase
)}
}
func
(
self
*
PBlock
)
ToString
()
string
{
...
...
@@ -78,7 +78,7 @@ func (self *PBlock) ToString() string {
}
func
(
self
*
PBlock
)
GetTransaction
(
hash
string
)
*
PTx
{
tx
:=
self
.
ref
.
GetTransaction
(
ethutil
.
FromHex
(
hash
))
tx
:=
self
.
ref
.
GetTransaction
(
ethutil
.
Hex2Bytes
(
hash
))
if
tx
==
nil
{
return
nil
}
...
...
@@ -103,22 +103,22 @@ type PTx struct {
}
func
NewPTx
(
tx
*
ethchain
.
Transaction
)
*
PTx
{
hash
:=
hex
.
EncodeToString
(
tx
.
Hash
())
receiver
:=
hex
.
EncodeToString
(
tx
.
Recipient
)
hash
:=
ethutil
.
Bytes2Hex
(
tx
.
Hash
())
receiver
:=
ethutil
.
Bytes2Hex
(
tx
.
Recipient
)
if
receiver
==
"0000000000000000000000000000000000000000"
{
receiver
=
hex
.
EncodeToString
(
tx
.
CreationAddress
())
receiver
=
ethutil
.
Bytes2Hex
(
tx
.
CreationAddress
())
}
sender
:=
hex
.
EncodeToString
(
tx
.
Sender
())
sender
:=
ethutil
.
Bytes2Hex
(
tx
.
Sender
())
createsContract
:=
tx
.
CreatesContract
()
var
data
string
if
tx
.
CreatesContract
()
{
data
=
strings
.
Join
(
ethchain
.
Disassemble
(
tx
.
Data
),
"
\n
"
)
}
else
{
data
=
hex
.
EncodeToString
(
tx
.
Data
)
data
=
ethutil
.
Bytes2Hex
(
tx
.
Data
)
}
return
&
PTx
{
ref
:
tx
,
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
),
Address
:
receiver
,
Contract
:
tx
.
CreatesContract
(),
Gas
:
tx
.
Gas
.
String
(),
GasPrice
:
tx
.
GasPrice
.
String
(),
Data
:
data
,
Sender
:
sender
,
CreatesContract
:
createsContract
,
RawData
:
hex
.
EncodeToString
(
tx
.
Data
)}
return
&
PTx
{
ref
:
tx
,
Hash
:
hash
,
Value
:
ethutil
.
CurrencyToString
(
tx
.
Value
),
Address
:
receiver
,
Contract
:
tx
.
CreatesContract
(),
Gas
:
tx
.
Gas
.
String
(),
GasPrice
:
tx
.
GasPrice
.
String
(),
Data
:
data
,
Sender
:
sender
,
CreatesContract
:
createsContract
,
RawData
:
ethutil
.
Bytes2Hex
(
tx
.
Data
)}
}
func
(
self
*
PTx
)
ToString
()
string
{
...
...
@@ -131,8 +131,8 @@ type PKey struct {
PublicKey
string
`json:"publicKey"`
}
func
NewPKey
(
key
*
eth
util
.
KeyPair
)
*
PKey
{
return
&
PKey
{
ethutil
.
Hex
(
key
.
Address
()),
ethutil
.
Hex
(
key
.
PrivateKey
),
ethutil
.
Hex
(
key
.
PublicKey
)}
func
NewPKey
(
key
*
eth
crypto
.
KeyPair
)
*
PKey
{
return
&
PKey
{
ethutil
.
Bytes2Hex
(
key
.
Address
()),
ethutil
.
Bytes2Hex
(
key
.
PrivateKey
),
ethutil
.
Bytes2
Hex
(
key
.
PublicKey
)}
}
type
PReceipt
struct
{
...
...
@@ -145,9 +145,9 @@ type PReceipt struct {
func
NewPReciept
(
contractCreation
bool
,
creationAddress
,
hash
,
address
[]
byte
)
*
PReceipt
{
return
&
PReceipt
{
contractCreation
,
ethutil
.
Hex
(
creationAddress
),
ethutil
.
Hex
(
hash
),
ethutil
.
Hex
(
address
),
ethutil
.
Bytes2
Hex
(
creationAddress
),
ethutil
.
Bytes2
Hex
(
hash
),
ethutil
.
Bytes2
Hex
(
address
),
}
}
...
...
@@ -182,7 +182,7 @@ func (c *PStateObject) Value() string {
func
(
c
*
PStateObject
)
Address
()
string
{
if
c
.
object
!=
nil
{
return
ethutil
.
Hex
(
c
.
object
.
Address
())
return
ethutil
.
Bytes2
Hex
(
c
.
object
.
Address
())
}
return
""
...
...
@@ -198,7 +198,7 @@ func (c *PStateObject) Nonce() int {
func
(
c
*
PStateObject
)
Root
()
string
{
if
c
.
object
!=
nil
{
return
ethutil
.
Hex
(
ethutil
.
NewValue
(
c
.
object
.
State
()
.
Root
())
.
Bytes
())
return
ethutil
.
Bytes2
Hex
(
ethutil
.
NewValue
(
c
.
object
.
State
()
.
Root
())
.
Bytes
())
}
return
"<err>"
...
...
@@ -221,7 +221,7 @@ func (c *PStateObject) StateKeyVal(asJson bool) interface{} {
var
values
[]
KeyVal
if
c
.
object
!=
nil
{
c
.
object
.
State
()
.
EachStorage
(
func
(
name
string
,
value
*
ethutil
.
Value
)
{
values
=
append
(
values
,
KeyVal
{
name
,
ethutil
.
Hex
(
value
.
Bytes
())})
values
=
append
(
values
,
KeyVal
{
name
,
ethutil
.
Bytes2
Hex
(
value
.
Bytes
())})
})
}
...
...
@@ -247,7 +247,7 @@ func (c *PStateObject) Script() string {
func
(
c
*
PStateObject
)
HexScript
()
string
{
if
c
.
object
!=
nil
{
return
ethutil
.
Hex
(
c
.
object
.
Script
())
return
ethutil
.
Bytes2
Hex
(
c
.
object
.
Script
())
}
return
""
...
...
@@ -260,5 +260,5 @@ type PStorageState struct {
}
func
NewPStorageState
(
storageObject
*
ethchain
.
StorageState
)
*
PStorageState
{
return
&
PStorageState
{
ethutil
.
Hex
(
storageObject
.
StateAddress
),
ethutil
.
Hex
(
storageObject
.
Address
),
storageObject
.
Value
.
String
()}
return
&
PStorageState
{
ethutil
.
Bytes2Hex
(
storageObject
.
StateAddress
),
ethutil
.
Bytes2
Hex
(
storageObject
.
Address
),
storageObject
.
Value
.
String
()}
}
ethrpc/packages.go
View file @
dabaa4cc
...
...
@@ -182,7 +182,7 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *string) error {
}
else
{
// Convert the incoming string (which is a bigint) into hex
i
,
_
:=
new
(
big
.
Int
)
.
SetString
(
args
.
Key
,
10
)
hx
=
ethutil
.
Hex
(
i
.
Bytes
())
hx
=
ethutil
.
Bytes2
Hex
(
i
.
Bytes
())
}
logger
.
Debugf
(
"GetStorageAt(%s, %s)
\n
"
,
args
.
Address
,
hx
)
value
:=
state
.
GetStorage
(
hx
)
...
...
peer.go
View file @
dabaa4cc
...
...
@@ -146,7 +146,7 @@ type Peer struct {
}
func
NewPeer
(
conn
net
.
Conn
,
ethereum
*
Ethereum
,
inbound
bool
)
*
Peer
{
pubkey
:=
eth
util
.
GetKeyRing
()
.
Get
(
0
)
.
PublicKey
[
1
:
]
pubkey
:=
eth
ereum
.
KeyManager
()
.
PublicKey
()
[
1
:
]
return
&
Peer
{
outputQueue
:
make
(
chan
*
ethwire
.
Msg
,
outputBufferSize
),
...
...
@@ -590,16 +590,12 @@ func (p *Peer) Stop() {
}
func
(
p
*
Peer
)
pushHandshake
()
error
{
keyRing
:=
ethutil
.
GetKeyRing
()
.
Get
(
0
)
if
keyRing
!=
nil
{
pubkey
:=
keyRing
.
PublicKey
pubkey
:=
p
.
ethereum
.
KeyManager
()
.
PublicKey
()
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgHandshakeTy
,
[]
interface
{}{
uint32
(
ProtocolVersion
),
uint32
(
0
),
[]
byte
(
p
.
version
),
byte
(
p
.
caps
),
p
.
port
,
pubkey
[
1
:
],
})
p
.
QueueMessage
(
msg
)
}
return
nil
}
...
...
@@ -664,8 +660,8 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
p
.
port
=
uint16
(
c
.
Get
(
4
)
.
Uint
())
// Self connect detection
keyPair
:=
ethutil
.
GetKeyRing
()
.
Get
(
0
)
if
bytes
.
Compare
(
keyPair
.
PublicK
ey
,
p
.
pubkey
)
==
0
{
pubkey
:=
p
.
ethereum
.
KeyManager
()
.
PublicKey
(
)
if
bytes
.
Compare
(
pubk
ey
,
p
.
pubkey
)
==
0
{
p
.
Stop
()
return
...
...
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