aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-18 20:00:01 +0800
committerobscuren <geffobscura@gmail.com>2015-03-18 20:00:01 +0800
commit0a1eeca41e6ba5920ba65d9b41654768299bc7e3 (patch)
tree0c286872355608c317f9e0ec1897bb79386ae94f /eth
parent942980609fb8a36873689bd3bd0a15488f327d56 (diff)
downloaddexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.gz
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.bz2
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.lz
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.xz
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.zst
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.zip
conversions. -compilable-
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go10
-rw-r--r--eth/protocol.go61
2 files changed, 36 insertions, 35 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 18093008b..c26bdceb5 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -10,11 +10,11 @@ import (
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/blockpool"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner"
@@ -288,7 +288,7 @@ func (s *Ethereum) StartMining() error {
servlogger.Errorf("Cannot start mining without coinbase: %v\n", err)
return fmt.Errorf("no coinbase: %v", err)
}
- s.miner.Start(cb)
+ s.miner.Start(common.BytesToAddress(cb))
return nil
}
@@ -304,9 +304,9 @@ func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
func (s *Ethereum) BlockPool() *blockpool.BlockPool { return s.blockPool }
func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper }
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
-func (s *Ethereum) BlockDb() common.Database { return s.blockDb }
-func (s *Ethereum) StateDb() common.Database { return s.stateDb }
-func (s *Ethereum) ExtraDb() common.Database { return s.extraDb }
+func (s *Ethereum) BlockDb() common.Database { return s.blockDb }
+func (s *Ethereum) StateDb() common.Database { return s.stateDb }
+func (s *Ethereum) ExtraDb() common.Database { return s.extraDb }
func (s *Ethereum) IsListening() bool { return true } // Always listening
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
func (s *Ethereum) PeerInfo() int { return s.net.PeerCount() }
diff --git a/eth/protocol.go b/eth/protocol.go
index e368bbec5..15a8e1831 100644
--- a/eth/protocol.go
+++ b/eth/protocol.go
@@ -1,13 +1,12 @@
package eth
import (
- "bytes"
"fmt"
"math/big"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/errs"
- "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
@@ -76,15 +75,15 @@ type txPool interface {
}
type chainManager interface {
- GetBlockHashesFromHash(hash []byte, amount uint64) (hashes [][]byte)
- GetBlock(hash []byte) (block *types.Block)
- Status() (td *big.Int, currentBlock []byte, genesisBlock []byte)
+ GetBlockHashesFromHash(hash common.Hash, amount uint64) (hashes []common.Hash)
+ GetBlock(hash common.Hash) (block *types.Block)
+ Status() (td *big.Int, currentBlock common.Hash, genesisBlock common.Hash)
}
type blockPool interface {
- AddBlockHashes(next func() ([]byte, bool), peerId string)
+ AddBlockHashes(next func() (common.Hash, bool), peerId string)
AddBlock(block *types.Block, peerId string)
- AddPeer(td *big.Int, currentBlock []byte, peerId string, requestHashes func([]byte) error, requestBlocks func([][]byte) error, peerError func(*errs.Error)) (best bool)
+ AddPeer(td *big.Int, currentBlock common.Hash, peerId string, requestHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool)
RemovePeer(peerId string)
}
@@ -95,7 +94,7 @@ type newBlockMsgData struct {
}
type getBlockHashesMsgData struct {
- Hash []byte
+ Hash common.Hash
Amount uint64
}
@@ -167,7 +166,7 @@ func (self *ethProtocol) handle() error {
}
for _, tx := range txs {
jsonlogger.LogJson(&logger.EthTxReceived{
- TxHash: common.Bytes2Hex(tx.Hash()),
+ TxHash: tx.Hash().Hex(),
RemoteId: self.peer.ID().String(),
})
}
@@ -183,7 +182,7 @@ func (self *ethProtocol) handle() error {
request.Amount = maxHashes
}
hashes := self.chainManager.GetBlockHashesFromHash(request.Hash, request.Amount)
- return p2p.EncodeMsg(self.rw, BlockHashesMsg, common.ByteSliceToInterface(hashes)...)
+ return p2p.EncodeMsg(self.rw, BlockHashesMsg, rlp.Flat(hashes))
case BlockHashesMsg:
msgStream := rlp.NewStream(msg.Payload)
@@ -192,14 +191,16 @@ func (self *ethProtocol) handle() error {
}
var i int
- iter := func() (hash []byte, ok bool) {
- hash, err := msgStream.Bytes()
+ iter := func() (hash common.Hash, ok bool) {
+ var h common.Hash
+ err := msgStream.Decode(&h)
if err == rlp.EOL {
- return nil, false
+ return common.Hash{}, false
} else if err != nil {
self.protoError(ErrDecode, "msg %v: after %v hashes : %v", msg, i, err)
- return nil, false
+ return common.Hash{}, false
}
+
i++
return hash, true
}
@@ -215,14 +216,14 @@ func (self *ethProtocol) handle() error {
var i int
for {
i++
- var hash []byte
- if err := msgStream.Decode(&hash); err != nil {
- if err == rlp.EOL {
- break
- } else {
- return self.protoError(ErrDecode, "msg %v: %v", msg, err)
- }
+ var hash common.Hash
+ err := msgStream.Decode(&hash)
+ if err == rlp.EOL {
+ break
+ } else {
+ return self.protoError(ErrDecode, "msg %v: %v", msg, err)
}
+
block := self.chainManager.GetBlock(hash)
if block != nil {
blocks = append(blocks, block)
@@ -259,10 +260,10 @@ func (self *ethProtocol) handle() error {
_, chainHead, _ := self.chainManager.Status()
jsonlogger.LogJson(&logger.EthChainReceivedNewBlock{
- BlockHash: common.Bytes2Hex(hash),
+ BlockHash: hash.Hex(),
BlockNumber: request.Block.Number(), // this surely must be zero
- ChainHeadHash: common.Bytes2Hex(chainHead),
- BlockPrevHash: common.Bytes2Hex(request.Block.ParentHash()),
+ ChainHeadHash: chainHead.Hex(),
+ BlockPrevHash: request.Block.ParentHash().Hex(),
RemoteId: self.peer.ID().String(),
})
// to simplify backend interface adding a new block
@@ -282,8 +283,8 @@ type statusMsgData struct {
ProtocolVersion uint32
NetworkId uint32
TD *big.Int
- CurrentBlock []byte
- GenesisBlock []byte
+ CurrentBlock common.Hash
+ GenesisBlock common.Hash
}
func (self *ethProtocol) statusMsg() p2p.Msg {
@@ -325,7 +326,7 @@ func (self *ethProtocol) handleStatus() error {
_, _, genesisBlock := self.chainManager.Status()
- if !bytes.Equal(status.GenesisBlock, genesisBlock) {
+ if status.GenesisBlock != genesisBlock {
return self.protoError(ErrGenesisBlockMismatch, "%x (!= %x)", status.GenesisBlock, genesisBlock)
}
@@ -344,14 +345,14 @@ func (self *ethProtocol) handleStatus() error {
return nil
}
-func (self *ethProtocol) requestBlockHashes(from []byte) error {
+func (self *ethProtocol) requestBlockHashes(from common.Hash) error {
self.peer.Debugf("fetching hashes (%d) %x...\n", maxHashes, from[0:4])
return p2p.EncodeMsg(self.rw, GetBlockHashesMsg, interface{}(from), uint64(maxHashes))
}
-func (self *ethProtocol) requestBlocks(hashes [][]byte) error {
+func (self *ethProtocol) requestBlocks(hashes []common.Hash) error {
self.peer.Debugf("fetching %v blocks", len(hashes))
- return p2p.EncodeMsg(self.rw, GetBlocksMsg, common.ByteSliceToInterface(hashes)...)
+ return p2p.EncodeMsg(self.rw, GetBlocksMsg, rlp.Flat(hashes))
}
func (self *ethProtocol) protoError(code int, format string, params ...interface{}) (err *errs.Error) {