Commit aa1eae67 authored by Jeffrey Wilcke's avatar Jeffrey Wilcke

Merge pull request #560 from tgerring/xethcleanup

XEth cleanup
parents 7f0c2545 2b93843d
......@@ -138,11 +138,12 @@ type Ethereum struct {
// logger logger.LogSystem
Mining bool
DataDir string
version string
protocolVersion int
networkId int
Mining bool
DataDir string
clientVersion string
ethVersionId int
netVersionId int
shhVersionId int
}
func New(config *Config) (*Ethereum, error) {
......@@ -177,16 +178,16 @@ func New(config *Config) (*Ethereum, error) {
servlogger.Infof("Protocol Version: %v, Network Id: %v", config.ProtocolVersion, config.NetworkId)
eth := &Ethereum{
shutdownChan: make(chan bool),
blockDb: blockDb,
stateDb: stateDb,
extraDb: extraDb,
eventMux: &event.TypeMux{},
accountManager: config.AccountManager,
DataDir: config.DataDir,
version: config.Name, // TODO should separate from Name
protocolVersion: config.ProtocolVersion,
networkId: config.NetworkId,
shutdownChan: make(chan bool),
blockDb: blockDb,
stateDb: stateDb,
extraDb: extraDb,
eventMux: &event.TypeMux{},
accountManager: config.AccountManager,
DataDir: config.DataDir,
clientVersion: config.Name, // TODO should separate from Name
ethVersionId: config.ProtocolVersion,
netVersionId: config.NetworkId,
}
eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux())
......@@ -195,6 +196,7 @@ func New(config *Config) (*Ethereum, error) {
eth.blockProcessor = core.NewBlockProcessor(stateDb, extraDb, eth.pow, eth.txPool, eth.chainManager, eth.EventMux())
eth.chainManager.SetProcessor(eth.blockProcessor)
eth.whisper = whisper.New()
eth.shhVersionId = int(eth.whisper.Version())
eth.miner = miner.New(eth, eth.pow, config.MinerThreads)
hasBlock := eth.chainManager.HasBlock
......@@ -324,9 +326,10 @@ func (s *Ethereum) IsListening() bool { return true } // Alwa
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() }
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers }
func (s *Ethereum) Version() string { return s.version }
func (s *Ethereum) ProtocolVersion() int { return s.protocolVersion }
func (s *Ethereum) NetworkId() int { return s.networkId }
func (s *Ethereum) ClientVersion() string { return s.clientVersion }
func (s *Ethereum) EthVersion() int { return s.ethVersionId }
func (s *Ethereum) NetVersion() int { return s.netVersionId }
func (s *Ethereum) ShhVersion() int { return s.shhVersionId }
// Start the ethereum
func (s *Ethereum) Start() error {
......
......@@ -49,7 +49,7 @@ func (api *EthereumApi) Close() {
}
func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error {
// Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC
// Spec at https://github.com/ethereum/wiki/wiki/JSON-RPC
rpclogger.Debugf("%s %s", req.Method, req.Params)
switch req.Method {
......@@ -60,14 +60,16 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
}
*reply = common.ToHex(crypto.Sha3(common.FromHex(args.Data)))
case "web3_clientVersion":
*reply = api.xeth().Backend().Version()
*reply = api.xeth().ClientVersion()
case "net_version":
*reply = string(api.xeth().Backend().ProtocolVersion())
*reply = api.xeth().NetworkVersion()
case "net_listening":
*reply = api.xeth().IsListening()
case "net_peerCount":
v := api.xeth().PeerCount()
*reply = common.ToHex(big.NewInt(int64(v)).Bytes())
case "eth_version":
*reply = api.xeth().EthVersion()
case "eth_coinbase":
// TODO handling of empty coinbase due to lack of accounts
res := api.xeth().Coinbase()
......@@ -84,7 +86,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
case "eth_accounts":
*reply = api.xeth().Accounts()
case "eth_blockNumber":
v := api.xeth().Backend().ChainManager().CurrentBlock().Number()
v := api.xeth().CurrentBlock().Number()
*reply = common.ToHex(v.Bytes())
case "eth_getBalance":
args := new(GetBalanceArgs)
......@@ -406,6 +408,8 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
res, _ := api.db.Get([]byte(args.Database + args.Key))
*reply = common.ToHex(res)
case "shh_version":
*reply = api.xeth().WhisperVersion()
case "shh_post":
args := new(WhisperMessageArgs)
if err := json.Unmarshal(req.Params, &args); err != nil {
......
......@@ -16,8 +16,9 @@ import (
)
const (
statusMsg = 0x0
envelopesMsg = 0x01
statusMsg = 0x0
envelopesMsg = 0x01
whisperVersion = 0x02
)
type MessageEvent struct {
......@@ -56,7 +57,7 @@ func New() *Whisper {
// p2p whisper sub protocol handler
whisper.protocol = p2p.Protocol{
Name: "shh",
Version: 2,
Version: uint(whisperVersion),
Length: 2,
Run: whisper.msgHandler,
}
......@@ -64,6 +65,10 @@ func New() *Whisper {
return whisper
}
func (self *Whisper) Version() uint {
return self.protocol.Version
}
func (self *Whisper) Start() {
wlogger.Infoln("Whisper started")
go self.update()
......
package xeth
import (
"github.com/ethereum/go-ethereum/core/types"
)
// Frontend should be implemented by users of XEth. Its methods are
// called whenever XEth makes a decision that requires user input.
type Frontend interface {
// UnlockAccount is called when a transaction needs to be signed
// but the key corresponding to the transaction's sender is
// locked.
//
// It should unlock the account with the given address and return
// true if unlocking succeeded.
UnlockAccount(address []byte) bool
// This is called for all transactions inititated through
// Transact. It should prompt the user to confirm the transaction
// and return true if the transaction was acknowledged.
//
// ConfirmTransaction is not used for Call transactions
// because they cannot change any state.
ConfirmTransaction(tx *types.Transaction) bool
}
// dummyFrontend is a non-interactive frontend that allows all
// transactions but cannot not unlock any keys.
type dummyFrontend struct{}
func (dummyFrontend) UnlockAccount([]byte) bool { return false }
func (dummyFrontend) ConfirmTransaction(*types.Transaction) bool { return true }
......@@ -29,7 +29,7 @@ func (self *State) SafeGet(addr string) *Object {
func (self *State) safeGet(addr string) *state.StateObject {
object := self.state.GetStateObject(common.HexToAddress(addr))
if object == nil {
object = state.NewStateObject(common.HexToAddress(addr), self.xeth.eth.StateDb())
object = state.NewStateObject(common.HexToAddress(addr), self.xeth.backend.StateDb())
}
return object
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment