change all modified calls to ethtrie, ethutil and ethcrypto functions

This commit is contained in:
zelig 2014-06-29 18:30:05 +01:00
parent 707d413761
commit dabaa4cce0
14 changed files with 91 additions and 83 deletions

View File

@ -3,6 +3,8 @@ package ethchain
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"math/big" "math/big"
"strconv" "strconv"
@ -102,18 +104,18 @@ func CreateBlock(root interface{},
} }
block.SetUncles([]*Block{}) block.SetUncles([]*Block{})
block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, root)) block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, root))
return block return block
} }
// Returns a hash of the block // Returns a hash of the block
func (block *Block) Hash() []byte { func (block *Block) Hash() []byte {
return ethutil.Sha3Bin(block.Value().Encode()) return ethcrypto.Sha3Bin(block.Value().Encode())
} }
func (block *Block) HashNoNonce() []byte { func (block *Block) HashNoNonce() []byte {
return ethutil.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash, return ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash,
block.UncleSha, block.Coinbase, block.state.trie.Root, block.UncleSha, block.Coinbase, block.state.trie.Root,
block.TxSha, block.Difficulty, block.Number, block.MinGasPrice, block.TxSha, block.Difficulty, block.Number, block.MinGasPrice,
block.GasLimit, block.GasUsed, block.Time, block.Extra})) block.GasLimit, block.GasUsed, block.Time, block.Extra}))
@ -239,7 +241,7 @@ func (block *Block) SetUncles(uncles []*Block) {
block.Uncles = uncles block.Uncles = uncles
// Sha of the concatenated uncles // Sha of the concatenated uncles
block.UncleSha = ethutil.Sha3Bin(ethutil.Encode(block.rlpUncles())) block.UncleSha = ethcrypto.Sha3Bin(ethutil.Encode(block.rlpUncles()))
} }
func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) { 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) { func (block *Block) setTransactions(txs []*Transaction) {
block.transactions = txs block.transactions = txs
trie := ethutil.NewTrie(ethutil.Config.Db, "") trie := ethtrie.NewTrie(ethutil.Config.Db, "")
for i, tx := range txs { for i, tx := range txs {
trie.Update(strconv.Itoa(i), string(tx.RlpEncode())) 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.PrevHash = header.Get(0).Bytes()
block.UncleSha = header.Get(1).Bytes() block.UncleSha = header.Get(1).Bytes()
block.Coinbase = header.Get(2).Bytes() block.Coinbase = header.Get(2).Bytes()
block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val)) block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val))
block.TxSha = header.Get(4).Bytes() block.TxSha = header.Get(4).Bytes()
block.Difficulty = header.Get(5).BigInt() block.Difficulty = header.Get(5).BigInt()
block.Number = header.Get(6).BigInt() block.Number = header.Get(6).BigInt()
@ -329,7 +331,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block {
block.PrevHash = header.Get(0).Bytes() block.PrevHash = header.Get(0).Bytes()
block.UncleSha = header.Get(1).Bytes() block.UncleSha = header.Get(1).Bytes()
block.Coinbase = header.Get(2).Bytes() block.Coinbase = header.Get(2).Bytes()
block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val)) block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val))
block.TxSha = header.Get(4).Bytes() block.TxSha = header.Get(4).Bytes()
block.Difficulty = header.Get(5).BigInt() block.Difficulty = header.Get(5).BigInt()
block.Number = header.Get(6).BigInt() block.Number = header.Get(6).BigInt()

View File

@ -278,7 +278,7 @@ func AddTestNetFunds(block *Block) {
"e6716f9544a56c530d868e4bfbacb172315bdead", "e6716f9544a56c530d868e4bfbacb172315bdead",
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4", "1a26338f0d905e295fccb71fa9ea849ffa12aaf4",
} { } {
codedAddr := ethutil.FromHex(addr) codedAddr := ethutil.Hex2Bytes(addr)
account := block.state.GetAccount(codedAddr) account := block.state.GetAccount(codedAddr)
account.Amount = ethutil.Big("1606938044258990275541962092341162602522202993782792835301376") //ethutil.BigPow(2, 200) account.Amount = ethutil.Big("1606938044258990275541962092341162602522202993782792835301376") //ethutil.BigPow(2, 200)
block.state.UpdateStateObject(account) block.state.UpdateStateObject(account)

View File

@ -1,6 +1,7 @@
package ethchain package ethchain
import ( import (
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/sha3" "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") powlogger.Infoln("Hashing @", int64(hashes), "khash")
} }
sha := ethutil.Sha3Bin(big.NewInt(r.Int63()).Bytes()) sha := ethcrypto.Sha3Bin(big.NewInt(r.Int63()).Bytes())
if pow.Verify(hash, diff, sha) { if pow.Verify(hash, diff, sha) {
return sha return sha
} }

View File

@ -1,6 +1,7 @@
package ethchain package ethchain
import ( import (
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"math/big" "math/big"
) )
@ -11,13 +12,13 @@ import (
var ZeroHash256 = make([]byte, 32) var ZeroHash256 = make([]byte, 32)
var ZeroHash160 = make([]byte, 20) var ZeroHash160 = make([]byte, 20)
var EmptyShaList = ethutil.Sha3Bin(ethutil.Encode([]interface{}{})) var EmptyShaList = ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{}))
var GenesisHeader = []interface{}{ var GenesisHeader = []interface{}{
// Previous hash (none) // Previous hash (none)
ZeroHash256, ZeroHash256,
// Sha of uncles // Sha of uncles
ethutil.Sha3Bin(ethutil.Encode([]interface{}{})), ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{})),
// Coinbase // Coinbase
ZeroHash160, ZeroHash160,
// Root state // Root state
@ -39,7 +40,7 @@ var GenesisHeader = []interface{}{
// Extra // Extra
nil, nil,
// Nonce // Nonce
ethutil.Sha3Bin(big.NewInt(42).Bytes()), ethcrypto.Sha3Bin(big.NewInt(42).Bytes()),
} }
var Genesis = []interface{}{GenesisHeader, []interface{}{}, []interface{}{}} var Genesis = []interface{}{GenesisHeader, []interface{}{}, []interface{}{}}

View File

@ -1,6 +1,7 @@
package ethchain package ethchain
import ( import (
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethtrie" "github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"math/big" "math/big"
@ -74,7 +75,7 @@ func (s *State) Purge() int {
return s.trie.NewIterator().Purge() return s.trie.NewIterator().Purge()
} }
func (s *State) EachStorage(cb ethutil.EachCallback) { func (s *State) EachStorage(cb ethtrie.EachCallback) {
it := s.trie.NewIterator() it := s.trie.NewIterator()
it.Each(cb) it.Each(cb)
} }
@ -92,7 +93,7 @@ func (self *State) UpdateStateObject(stateObject *StateObject) {
self.stateObjects[string(addr)] = stateObject self.stateObjects[string(addr)] = stateObject
} }
ethutil.Config.Db.Put(ethutil.Sha3Bin(stateObject.Script()), stateObject.Script()) ethutil.Config.Db.Put(ethcrypto.Sha3Bin(stateObject.Script()), stateObject.Script())
self.trie.Update(string(addr), string(stateObject.RlpEncode())) self.trie.Update(string(addr), string(stateObject.RlpEncode()))

View File

@ -3,6 +3,7 @@ package ethchain
import ( import (
"bytes" "bytes"
"container/list" "container/list"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire" "github.com/ethereum/eth-go/ethwire"
@ -38,6 +39,7 @@ type EthManager interface {
IsMining() bool IsMining() bool
IsListening() bool IsListening() bool
Peers() *list.List Peers() *list.List
KeyManager() *ethcrypto.KeyManager
} }
type StateManager struct { 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 // Verify the nonce of the block. Return an error if it's not valid
if !sm.Pow.Verify(block.HashNoNonce(), block.Difficulty, block.Nonce) { 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.Bytes2Hex(block.Nonce))
} }
return nil return nil

View File

@ -2,6 +2,8 @@ package ethchain
import ( import (
"fmt" "fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"math/big" "math/big"
"strings" "strings"
@ -39,7 +41,7 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
contract := state.NewStateObject(addr) contract := state.NewStateObject(addr)
contract.initScript = tx.Data contract.initScript = tx.Data
contract.state = NewState(ethutil.NewTrie(ethutil.Config.Db, "")) contract.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, ""))
return contract return contract
} }
@ -53,7 +55,7 @@ func NewStateObject(addr []byte) *StateObject {
func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject { func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject {
contract := &StateObject{address: address, Amount: Amount, Nonce: 0} contract := &StateObject{address: address, Amount: Amount, Nonce: 0}
contract.state = NewState(ethutil.NewTrie(ethutil.Config.Db, string(root))) contract.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, string(root)))
return contract return contract
} }
@ -246,7 +248,7 @@ func (c *StateObject) RlpEncode() []byte {
root = "" root = ""
} }
return ethutil.Encode([]interface{}{c.Nonce, c.Amount, root, ethutil.Sha3Bin(c.script)}) return ethutil.Encode([]interface{}{c.Nonce, c.Amount, root, ethcrypto.Sha3Bin(c.script)})
} }
func (c *StateObject) RlpDecode(data []byte) { func (c *StateObject) RlpDecode(data []byte) {
@ -254,7 +256,8 @@ func (c *StateObject) RlpDecode(data []byte) {
c.Nonce = decoder.Get(0).Uint() c.Nonce = decoder.Get(0).Uint()
c.Amount = decoder.Get(1).BigInt() 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() c.ScriptHash = decoder.Get(3).Bytes()

View File

@ -3,6 +3,7 @@ package ethchain
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/secp256k1-go" "github.com/obscuren/secp256k1-go"
"math/big" "math/big"
@ -62,7 +63,7 @@ func (self *Transaction) TotalValue() *big.Int {
func (tx *Transaction) Hash() []byte { func (tx *Transaction) Hash() []byte {
data := []interface{}{tx.Nonce, tx.GasPrice, tx.Gas, tx.Recipient, tx.Value, tx.Data} data := []interface{}{tx.Nonce, tx.GasPrice, tx.Gas, tx.Recipient, tx.Value, tx.Data}
return ethutil.Sha3Bin(ethutil.NewValue(data).Encode()) return ethcrypto.Sha3Bin(ethutil.NewValue(data).Encode())
} }
func (tx *Transaction) CreatesContract() bool { func (tx *Transaction) CreatesContract() bool {
@ -75,7 +76,7 @@ func (tx *Transaction) IsContract() bool {
} }
func (tx *Transaction) CreationAddress() []byte { func (tx *Transaction) CreationAddress() []byte {
return ethutil.Sha3Bin(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:] return ethcrypto.Sha3Bin(ethutil.NewValue([]interface{}{tx.Sender(), tx.Nonce}).Encode())[12:]
} }
func (tx *Transaction) Signature(key []byte) []byte { func (tx *Transaction) Signature(key []byte) []byte {
@ -111,7 +112,7 @@ func (tx *Transaction) Sender() []byte {
return nil return nil
} }
return ethutil.Sha3Bin(pubkey[1:])[12:] return ethcrypto.Sha3Bin(pubkey[1:])[12:]
} }
func (tx *Transaction) Sign(privk []byte) error { func (tx *Transaction) Sign(privk []byte) error {

View File

@ -2,6 +2,7 @@ package ethchain
import ( import (
"fmt" "fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"math" "math"
@ -398,7 +399,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
case SHA3: case SHA3:
require(2) require(2)
size, offset := stack.Popn() size, offset := stack.Popn()
data := ethutil.Sha3Bin(mem.Get(offset.Int64(), size.Int64())) data := ethcrypto.Sha3Bin(mem.Get(offset.Int64(), size.Int64()))
stack.Push(ethutil.BigD(data)) stack.Push(ethutil.BigD(data))
// 0x30 range // 0x30 range
@ -594,7 +595,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
snapshot := vm.state.Copy() snapshot := vm.state.Copy()
// Generate a new address // Generate a new address
addr := ethutil.CreateAddress(closure.caller.Address(), closure.caller.N()) addr := ethcrypto.CreateAddress(closure.caller.Address(), closure.caller.N())
vm.Printf(" (*) %x", addr).Endl() vm.Printf(" (*) %x", addr).Endl()

View File

@ -4,7 +4,7 @@ import (
"container/list" "container/list"
"fmt" "fmt"
"github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethrpc" "github.com/ethereum/eth-go/ethrpc"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
@ -74,16 +74,15 @@ type Ethereum struct {
reactor *ethutil.ReactorEngine reactor *ethutil.ReactorEngine
RpcServer *ethrpc.JsonRpcServer RpcServer *ethrpc.JsonRpcServer
keyManager *ethcrypto.KeyManager
} }
func New(caps Caps, usePnp bool) (*Ethereum, error) { func New(db ethutil.Database, keyManager *ethcrypto.KeyManager, caps Caps, usePnp bool) (*Ethereum, error) {
db, err := ethdb.NewLDBDatabase("database")
//db, err := ethdb.NewMemDatabase()
if err != nil {
return nil, err
}
var err error
var nat NAT var nat NAT
if usePnp { if usePnp {
nat, err = Discover() nat, err = Discover()
if err != nil { if err != nil {
@ -102,6 +101,7 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) {
Nonce: nonce, Nonce: nonce,
serverCaps: caps, serverCaps: caps,
nat: nat, nat: nat,
keyManager: keyManager,
} }
ethereum.reactor = ethutil.NewReactorEngine() ethereum.reactor = ethutil.NewReactorEngine()
@ -119,6 +119,10 @@ func (s *Ethereum) Reactor() *ethutil.ReactorEngine {
return s.reactor return s.reactor
} }
func (s *Ethereum) KeyManager() *ethcrypto.KeyManager {
return s.keyManager
}
func (s *Ethereum) BlockChain() *ethchain.BlockChain { func (s *Ethereum) BlockChain() *ethchain.BlockChain {
return s.blockChain return s.blockChain
} }

View File

@ -2,9 +2,9 @@ package ethpub
import ( import (
"bytes" "bytes"
"encoding/hex"
"encoding/json" "encoding/json"
"github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"math/big" "math/big"
@ -19,6 +19,7 @@ type PEthereum struct {
stateManager *ethchain.StateManager stateManager *ethchain.StateManager
blockChain *ethchain.BlockChain blockChain *ethchain.BlockChain
txPool *ethchain.TxPool txPool *ethchain.TxPool
keyManager *ethcrypto.KeyManager
} }
func NewPEthereum(manager ethchain.EthManager) *PEthereum { func NewPEthereum(manager ethchain.EthManager) *PEthereum {
@ -27,24 +28,23 @@ func NewPEthereum(manager ethchain.EthManager) *PEthereum {
manager.StateManager(), manager.StateManager(),
manager.BlockChain(), manager.BlockChain(),
manager.TxPool(), manager.TxPool(),
manager.KeyManager(),
} }
} }
func (lib *PEthereum) GetBlock(hexHash string) *PBlock { func (lib *PEthereum) GetBlock(hexHash string) *PBlock {
hash := ethutil.FromHex(hexHash) hash := ethutil.Hex2Bytes(hexHash)
block := lib.blockChain.GetBlock(hash) block := lib.blockChain.GetBlock(hash)
return NewPBlock(block) return NewPBlock(block)
} }
func (lib *PEthereum) GetKey() *PKey { func (lib *PEthereum) GetKey() *PKey {
keyPair := ethutil.GetKeyRing().Get(0) return NewPKey(lib.keyManager.KeyPair())
return NewPKey(keyPair)
} }
func (lib *PEthereum) GetStateObject(address string) *PStateObject { 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 { if stateObject != nil {
return NewPStateObject(stateObject) return NewPStateObject(stateObject)
} }
@ -79,17 +79,13 @@ func (lib *PEthereum) GetIsListening() bool {
} }
func (lib *PEthereum) GetCoinBase() string { func (lib *PEthereum) GetCoinBase() string {
data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) return ethutil.Bytes2Hex(lib.keyManager.Address())
keyRing := ethutil.NewValueFromBytes(data)
key := keyRing.Get(0).Bytes()
return lib.SecretToAddress(hex.EncodeToString(key))
} }
func (lib *PEthereum) GetTransactionsFor(address string, asJson bool) interface{} { func (lib *PEthereum) GetTransactionsFor(address string, asJson bool) interface{} {
sBlk := lib.manager.BlockChain().LastBlockHash sBlk := lib.manager.BlockChain().LastBlockHash
blk := lib.manager.BlockChain().GetBlock(sBlk) blk := lib.manager.BlockChain().GetBlock(sBlk)
addr := []byte(ethutil.FromHex(address)) addr := []byte(ethutil.Hex2Bytes(address))
var txs []*PTx var txs []*PTx
@ -129,12 +125,12 @@ func (lib *PEthereum) IsContract(address string) bool {
} }
func (lib *PEthereum) SecretToAddress(key string) string { func (lib *PEthereum) SecretToAddress(key string) string {
pair, err := ethutil.NewKeyPairFromSec(ethutil.FromHex(key)) pair, err := ethcrypto.NewKeyPairFromSec(ethutil.Hex2Bytes(key))
if err != nil { if err != nil {
return "" return ""
} }
return ethutil.Hex(pair.Address()) return ethutil.Bytes2Hex(pair.Address())
} }
func (lib *PEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) (*PReceipt, error) { 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) 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 { func GetAddressFromNameReg(stateManager *ethchain.StateManager, name string) []byte {
recp := new(big.Int).SetBytes([]byte(name)) 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 { if len(addr) > 0 {
hash = addr hash = addr
} else { } else {
hash = ethutil.FromHex(recipient) hash = ethutil.Hex2Bytes(recipient)
} }
} }
var keyPair *ethutil.KeyPair var keyPair *ethcrypto.KeyPair
var err error var err error
if key[0:2] == "0x" { if key[0:2] == "0x" {
keyPair, err = ethutil.NewKeyPairFromSec([]byte(ethutil.FromHex(key[2:]))) keyPair, err = ethcrypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(key[2:])))
} else { } else {
keyPair, err = ethutil.NewKeyPairFromSec([]byte(ethutil.FromHex(key))) keyPair, err = ethcrypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(key)))
} }
if err != nil { if err != nil {
@ -194,7 +190,7 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, sc
var script []byte var script []byte
var err error var err error
if ethutil.IsHex(scriptStr) { if ethutil.IsHex(scriptStr) {
script = ethutil.FromHex(scriptStr) script = ethutil.Hex2Bytes(scriptStr[2:])
} else { } else {
script, err = ethutil.Compile(scriptStr) script, err = ethutil.Compile(scriptStr)
if err != nil { if err != nil {

View File

@ -1,10 +1,10 @@
package ethpub package ethpub
import ( import (
"encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"strings" "strings"
) )
@ -66,7 +66,7 @@ func NewPBlock(block *ethchain.Block) *PBlock {
return nil 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.Bytes2Hex(block.Coinbase)}
} }
func (self *PBlock) ToString() string { func (self *PBlock) ToString() string {
@ -78,7 +78,7 @@ func (self *PBlock) ToString() string {
} }
func (self *PBlock) GetTransaction(hash string) *PTx { func (self *PBlock) GetTransaction(hash string) *PTx {
tx := self.ref.GetTransaction(ethutil.FromHex(hash)) tx := self.ref.GetTransaction(ethutil.Hex2Bytes(hash))
if tx == nil { if tx == nil {
return nil return nil
} }
@ -103,22 +103,22 @@ type PTx struct {
} }
func NewPTx(tx *ethchain.Transaction) *PTx { func NewPTx(tx *ethchain.Transaction) *PTx {
hash := hex.EncodeToString(tx.Hash()) hash := ethutil.Bytes2Hex(tx.Hash())
receiver := hex.EncodeToString(tx.Recipient) receiver := ethutil.Bytes2Hex(tx.Recipient)
if receiver == "0000000000000000000000000000000000000000" { 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() createsContract := tx.CreatesContract()
var data string var data string
if tx.CreatesContract() { if tx.CreatesContract() {
data = strings.Join(ethchain.Disassemble(tx.Data), "\n") data = strings.Join(ethchain.Disassemble(tx.Data), "\n")
} else { } 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 { func (self *PTx) ToString() string {
@ -131,8 +131,8 @@ type PKey struct {
PublicKey string `json:"publicKey"` PublicKey string `json:"publicKey"`
} }
func NewPKey(key *ethutil.KeyPair) *PKey { func NewPKey(key *ethcrypto.KeyPair) *PKey {
return &PKey{ethutil.Hex(key.Address()), ethutil.Hex(key.PrivateKey), ethutil.Hex(key.PublicKey)} return &PKey{ethutil.Bytes2Hex(key.Address()), ethutil.Bytes2Hex(key.PrivateKey), ethutil.Bytes2Hex(key.PublicKey)}
} }
type PReceipt struct { type PReceipt struct {
@ -145,9 +145,9 @@ type PReceipt struct {
func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt { func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt {
return &PReceipt{ return &PReceipt{
contractCreation, contractCreation,
ethutil.Hex(creationAddress), ethutil.Bytes2Hex(creationAddress),
ethutil.Hex(hash), ethutil.Bytes2Hex(hash),
ethutil.Hex(address), ethutil.Bytes2Hex(address),
} }
} }
@ -182,7 +182,7 @@ func (c *PStateObject) Value() string {
func (c *PStateObject) Address() string { func (c *PStateObject) Address() string {
if c.object != nil { if c.object != nil {
return ethutil.Hex(c.object.Address()) return ethutil.Bytes2Hex(c.object.Address())
} }
return "" return ""
@ -198,7 +198,7 @@ func (c *PStateObject) Nonce() int {
func (c *PStateObject) Root() string { func (c *PStateObject) Root() string {
if c.object != nil { if c.object != nil {
return ethutil.Hex(ethutil.NewValue(c.object.State().Root()).Bytes()) return ethutil.Bytes2Hex(ethutil.NewValue(c.object.State().Root()).Bytes())
} }
return "<err>" return "<err>"
@ -221,7 +221,7 @@ func (c *PStateObject) StateKeyVal(asJson bool) interface{} {
var values []KeyVal var values []KeyVal
if c.object != nil { if c.object != nil {
c.object.State().EachStorage(func(name string, value *ethutil.Value) { 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.Bytes2Hex(value.Bytes())})
}) })
} }
@ -247,7 +247,7 @@ func (c *PStateObject) Script() string {
func (c *PStateObject) HexScript() string { func (c *PStateObject) HexScript() string {
if c.object != nil { if c.object != nil {
return ethutil.Hex(c.object.Script()) return ethutil.Bytes2Hex(c.object.Script())
} }
return "" return ""
@ -260,5 +260,5 @@ type PStorageState struct {
} }
func NewPStorageState(storageObject *ethchain.StorageState) *PStorageState { 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.Bytes2Hex(storageObject.Address), storageObject.Value.String()}
} }

View File

@ -182,7 +182,7 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *string) error {
} else { } else {
// Convert the incoming string (which is a bigint) into hex // Convert the incoming string (which is a bigint) into hex
i, _ := new(big.Int).SetString(args.Key, 10) i, _ := new(big.Int).SetString(args.Key, 10)
hx = ethutil.Hex(i.Bytes()) hx = ethutil.Bytes2Hex(i.Bytes())
} }
logger.Debugf("GetStorageAt(%s, %s)\n", args.Address, hx) logger.Debugf("GetStorageAt(%s, %s)\n", args.Address, hx)
value := state.GetStorage(hx) value := state.GetStorage(hx)

20
peer.go
View File

@ -146,7 +146,7 @@ type Peer struct {
} }
func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer { func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
pubkey := ethutil.GetKeyRing().Get(0).PublicKey[1:] pubkey := ethereum.KeyManager().PublicKey()[1:]
return &Peer{ return &Peer{
outputQueue: make(chan *ethwire.Msg, outputBufferSize), outputQueue: make(chan *ethwire.Msg, outputBufferSize),
@ -590,16 +590,12 @@ func (p *Peer) Stop() {
} }
func (p *Peer) pushHandshake() error { func (p *Peer) pushHandshake() error {
keyRing := ethutil.GetKeyRing().Get(0) pubkey := p.ethereum.KeyManager().PublicKey()
if keyRing != nil { msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{
pubkey := keyRing.PublicKey uint32(ProtocolVersion), uint32(0), []byte(p.version), byte(p.caps), p.port, pubkey[1:],
})
msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{ p.QueueMessage(msg)
uint32(ProtocolVersion), uint32(0), []byte(p.version), byte(p.caps), p.port, pubkey[1:],
})
p.QueueMessage(msg)
}
return nil return nil
} }
@ -664,8 +660,8 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
p.port = uint16(c.Get(4).Uint()) p.port = uint16(c.Get(4).Uint())
// Self connect detection // Self connect detection
keyPair := ethutil.GetKeyRing().Get(0) pubkey := p.ethereum.KeyManager().PublicKey()
if bytes.Compare(keyPair.PublicKey, p.pubkey) == 0 { if bytes.Compare(pubkey, p.pubkey) == 0 {
p.Stop() p.Stop()
return return