diff options
-rw-r--r-- | ethchain/block.go | 16 | ||||
-rw-r--r-- | ethchain/block_chain.go | 2 | ||||
-rw-r--r-- | ethchain/dagger.go | 3 | ||||
-rw-r--r-- | ethchain/genesis.go | 7 | ||||
-rw-r--r-- | ethchain/state.go | 5 | ||||
-rw-r--r-- | ethchain/state_manager.go | 4 | ||||
-rw-r--r-- | ethchain/state_object.go | 11 | ||||
-rw-r--r-- | ethchain/transaction.go | 7 | ||||
-rw-r--r-- | ethchain/vm.go | 5 | ||||
-rw-r--r-- | ethereum.go | 18 | ||||
-rw-r--r-- | ethpub/pub.go | 36 | ||||
-rw-r--r-- | ethpub/types.go | 38 | ||||
-rw-r--r-- | ethrpc/packages.go | 2 | ||||
-rw-r--r-- | peer.go | 20 |
14 files changed, 91 insertions, 83 deletions
diff --git a/ethchain/block.go b/ethchain/block.go index fee4a2d59..ed5b754f8 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -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(ethutil.NewTrie(ethutil.Config.Db, root)) + block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, root)) return block } // Returns a hash of the block func (block *Block) Hash() []byte { - return ethutil.Sha3Bin(block.Value().Encode()) + return ethcrypto.Sha3Bin(block.Value().Encode()) } 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.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 = ethutil.Sha3Bin(ethutil.Encode(block.rlpUncles())) + block.UncleSha = ethcrypto.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 := ethutil.NewTrie(ethutil.Config.Db, "") + trie := ethtrie.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(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.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(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.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go index 6e4c72b27..7a481ed7c 100644 --- a/ethchain/block_chain.go +++ b/ethchain/block_chain.go @@ -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) diff --git a/ethchain/dagger.go b/ethchain/dagger.go index 08c4826db..46b1081e9 100644 --- a/ethchain/dagger.go +++ b/ethchain/dagger.go @@ -1,6 +1,7 @@ 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 := ethutil.Sha3Bin(big.NewInt(r.Int63()).Bytes()) + sha := ethcrypto.Sha3Bin(big.NewInt(r.Int63()).Bytes()) if pow.Verify(hash, diff, sha) { return sha } diff --git a/ethchain/genesis.go b/ethchain/genesis.go index 359c47c26..54a3bc766 100644 --- a/ethchain/genesis.go +++ b/ethchain/genesis.go @@ -1,6 +1,7 @@ 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 = ethutil.Sha3Bin(ethutil.Encode([]interface{}{})) +var EmptyShaList = ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{})) var GenesisHeader = []interface{}{ // Previous hash (none) ZeroHash256, // Sha of uncles - ethutil.Sha3Bin(ethutil.Encode([]interface{}{})), + ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{})), // Coinbase ZeroHash160, // Root state @@ -39,7 +40,7 @@ var GenesisHeader = []interface{}{ // Extra nil, // Nonce - ethutil.Sha3Bin(big.NewInt(42).Bytes()), + ethcrypto.Sha3Bin(big.NewInt(42).Bytes()), } var Genesis = []interface{}{GenesisHeader, []interface{}{}, []interface{}{}} diff --git a/ethchain/state.go b/ethchain/state.go index 4c66a973e..dc2d3c73b 100644 --- a/ethchain/state.go +++ b/ethchain/state.go @@ -1,6 +1,7 @@ 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 ethutil.EachCallback) { +func (s *State) EachStorage(cb ethtrie.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(ethutil.Sha3Bin(stateObject.Script()), stateObject.Script()) + ethutil.Config.Db.Put(ethcrypto.Sha3Bin(stateObject.Script()), stateObject.Script()) self.trie.Update(string(addr), string(stateObject.RlpEncode())) diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go index 312ba3084..f199e20ec 100644 --- a/ethchain/state_manager.go +++ b/ethchain/state_manager.go @@ -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.Bytes2Hex(block.Nonce)) } return nil diff --git a/ethchain/state_object.go b/ethchain/state_object.go index 480b4055d..e55540153 100644 --- a/ethchain/state_object.go +++ b/ethchain/state_object.go @@ -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(ethutil.NewTrie(ethutil.Config.Db, "")) + contract.state = NewState(ethtrie.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(ethutil.NewTrie(ethutil.Config.Db, string(root))) + contract.state = NewState(ethtrie.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, ethutil.Sha3Bin(c.script)}) + return ethutil.Encode([]interface{}{c.Nonce, c.Amount, root, ethcrypto.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() diff --git a/ethchain/transaction.go b/ethchain/transaction.go index 2ab681030..11f786b36 100644 --- a/ethchain/transaction.go +++ b/ethchain/transaction.go @@ -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 ethutil.Sha3Bin(ethutil.NewValue(data).Encode()) + return ethcrypto.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 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 { @@ -111,7 +112,7 @@ func (tx *Transaction) Sender() []byte { return nil } - return ethutil.Sha3Bin(pubkey[1:])[12:] + return ethcrypto.Sha3Bin(pubkey[1:])[12:] } func (tx *Transaction) Sign(privk []byte) error { diff --git a/ethchain/vm.go b/ethchain/vm.go index 82591e274..66b5a9182 100644 --- a/ethchain/vm.go +++ b/ethchain/vm.go @@ -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 := ethutil.Sha3Bin(mem.Get(offset.Int64(), size.Int64())) + data := ethcrypto.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 := ethutil.CreateAddress(closure.caller.Address(), closure.caller.N()) + addr := ethcrypto.CreateAddress(closure.caller.Address(), closure.caller.N()) vm.Printf(" (*) %x", addr).Endl() diff --git a/ethereum.go b/ethereum.go index a3df23e92..b78b0658f 100644 --- a/ethereum.go +++ b/ethereum.go @@ -4,7 +4,7 @@ import ( "container/list" "fmt" "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/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 } diff --git a/ethpub/pub.go b/ethpub/pub.go index 1bc9e0ce7..cd30d0260 100644 --- a/ethpub/pub.go +++ b/ethpub/pub.go @@ -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 := ethutil.NewKeyPairFromSec(ethutil.FromHex(key)) + pair, err := ethcrypto.NewKeyPairFromSec(ethutil.Hex2Bytes(key)) if err != nil { return "" } - return ethutil.Hex(pair.Address()) + return ethutil.Bytes2Hex(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 *ethutil.KeyPair + var keyPair *ethcrypto.KeyPair var err error if key[0:2] == "0x" { - keyPair, err = ethutil.NewKeyPairFromSec([]byte(ethutil.FromHex(key[2:]))) + keyPair, err = ethcrypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(key[2:]))) } else { - keyPair, err = ethutil.NewKeyPairFromSec([]byte(ethutil.FromHex(key))) + keyPair, err = ethcrypto.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 { diff --git a/ethpub/types.go b/ethpub/types.go index 0ced68ad1..05031dea2 100644 --- a/ethpub/types.go +++ b/ethpub/types.go @@ -1,10 +1,10 @@ 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.Bytes2Hex(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 *ethutil.KeyPair) *PKey { - return &PKey{ethutil.Hex(key.Address()), ethutil.Hex(key.PrivateKey), ethutil.Hex(key.PublicKey)} +func NewPKey(key *ethcrypto.KeyPair) *PKey { + return &PKey{ethutil.Bytes2Hex(key.Address()), ethutil.Bytes2Hex(key.PrivateKey), ethutil.Bytes2Hex(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.Bytes2Hex(creationAddress), + ethutil.Bytes2Hex(hash), + ethutil.Bytes2Hex(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.Bytes2Hex(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.Bytes2Hex(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.Bytes2Hex(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.Bytes2Hex(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.Bytes2Hex(storageObject.Address), storageObject.Value.String()} } diff --git a/ethrpc/packages.go b/ethrpc/packages.go index 710275780..0662f0edd 100644 --- a/ethrpc/packages.go +++ b/ethrpc/packages.go @@ -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.Bytes2Hex(i.Bytes()) } logger.Debugf("GetStorageAt(%s, %s)\n", args.Address, hx) value := state.GetStorage(hx) @@ -146,7 +146,7 @@ type Peer struct { } func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer { - pubkey := ethutil.GetKeyRing().Get(0).PublicKey[1:] + pubkey := ethereum.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 - - msg := ethwire.NewMessage(ethwire.MsgHandshakeTy, []interface{}{ - uint32(ProtocolVersion), uint32(0), []byte(p.version), byte(p.caps), p.port, pubkey[1:], - }) + 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) - } + 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.PublicKey, p.pubkey) == 0 { + pubkey := p.ethereum.KeyManager().PublicKey() + if bytes.Compare(pubkey, p.pubkey) == 0 { p.Stop() return |