made mist in a compilable, workable state using the new refactored packages

This commit is contained in:
obscuren 2014-12-15 13:00:09 +01:00
parent c7bc684909
commit 56dac74f71
7 changed files with 63 additions and 29 deletions

View File

@ -36,10 +36,12 @@ var (
Identifier string Identifier string
KeyRing string KeyRing string
KeyStore string KeyStore string
PMPGateway string
StartRpc bool StartRpc bool
StartWebSockets bool StartWebSockets bool
RpcPort int RpcPort int
UseUPnP bool UseUPnP bool
NatType string
OutboundPort string OutboundPort string
ShowGenesis bool ShowGenesis bool
AddPeer string AddPeer string
@ -111,10 +113,12 @@ func Init() {
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
flag.BoolVar(&UseSeed, "seed", true, "seed peers") flag.BoolVar(&UseSeed, "seed", true, "seed peers")
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)")
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)") flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given") flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)") flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use") flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for PMP")
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)") flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)") flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")

View File

@ -30,14 +30,14 @@ import (
"strings" "strings"
"time" "time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/wire" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/xeth" "github.com/ethereum/go-ethereum/xeth"
"gopkg.in/qml.v1" "gopkg.in/qml.v1"
) )
@ -97,7 +97,7 @@ type Gui struct {
pipe *xeth.JSXEth pipe *xeth.JSXEth
Session string Session string
clientIdentity *wire.SimpleClientIdentity clientIdentity *p2p.SimpleClientIdentity
config *ethutil.ConfigManager config *ethutil.ConfigManager
plugins map[string]plugin plugins map[string]plugin
@ -107,7 +107,7 @@ type Gui struct {
} }
// Create GUI, but doesn't start it // Create GUI, but doesn't start it
func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIdentity *wire.SimpleClientIdentity, session string, logLevel int) *Gui { func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIdentity *p2p.SimpleClientIdentity, session string, logLevel int) *Gui {
db, err := ethdb.NewLDBDatabase("tx_database") db, err := ethdb.NewLDBDatabase("tx_database")
if err != nil { if err != nil {
panic(err) panic(err)
@ -409,8 +409,7 @@ func (gui *Gui) update() {
miningLabel := gui.getObjectByName("miningLabel") miningLabel := gui.getObjectByName("miningLabel")
events := gui.eth.EventMux().Subscribe( events := gui.eth.EventMux().Subscribe(
eth.ChainSyncEvent{}, //eth.PeerListEvent{},
eth.PeerListEvent{},
core.NewBlockEvent{}, core.NewBlockEvent{},
core.TxPreEvent{}, core.TxPreEvent{},
core.TxPostEvent{}, core.TxPostEvent{},
@ -460,9 +459,6 @@ func (gui *Gui) update() {
gui.setWalletValue(object.Balance(), nil) gui.setWalletValue(object.Balance(), nil)
state.UpdateStateObject(object) state.UpdateStateObject(object)
case eth.PeerListEvent:
gui.setPeerInfo()
} }
case <-peerUpdateTicker.C: case <-peerUpdateTicker.C:
@ -472,16 +468,18 @@ func (gui *Gui) update() {
lastBlockLabel.Set("text", statusText) lastBlockLabel.Set("text", statusText)
miningLabel.Set("text", "Mining @ "+strconv.FormatInt(gui.uiLib.miner.GetPow().GetHashrate(), 10)+"Khash") miningLabel.Set("text", "Mining @ "+strconv.FormatInt(gui.uiLib.miner.GetPow().GetHashrate(), 10)+"Khash")
blockLength := gui.eth.BlockPool().BlocksProcessed /*
chainLength := gui.eth.BlockPool().ChainLength blockLength := gui.eth.BlockPool().BlocksProcessed
chainLength := gui.eth.BlockPool().ChainLength
var ( var (
pct float64 = 1.0 / float64(chainLength) * float64(blockLength) pct float64 = 1.0 / float64(chainLength) * float64(blockLength)
dlWidget = gui.win.Root().ObjectByName("downloadIndicator") dlWidget = gui.win.Root().ObjectByName("downloadIndicator")
dlLabel = gui.win.Root().ObjectByName("downloadLabel") dlLabel = gui.win.Root().ObjectByName("downloadLabel")
) )
dlWidget.Set("value", pct) dlWidget.Set("value", pct)
dlLabel.Set("text", fmt.Sprintf("%d / %d", blockLength, chainLength)) dlLabel.Set("text", fmt.Sprintf("%d / %d", blockLength, chainLength))
*/
case <-statsUpdateTicker.C: case <-statsUpdateTicker.C:
gui.setStatsPane() gui.setStatsPane()
@ -509,7 +507,7 @@ Heap Alloc: %d
CGNext: %x CGNext: %x
NumGC: %d NumGC: %d
`, Version, runtime.Version(), `, Version, runtime.Version(),
eth.ProtocolVersion, eth.P2PVersion, eth.ProtocolVersion, 2,
runtime.NumCPU, runtime.NumGoroutine(), runtime.NumCgoCall(), runtime.NumCPU, runtime.NumGoroutine(), runtime.NumCgoCall(),
memStats.Alloc, memStats.HeapAlloc, memStats.Alloc, memStats.HeapAlloc,
memStats.NextGC, memStats.NumGC, memStats.NextGC, memStats.NumGC,

View File

@ -23,8 +23,8 @@ import (
"runtime" "runtime"
"time" "time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"gopkg.in/qml.v1" "gopkg.in/qml.v1"
) )
@ -58,8 +58,8 @@ func run() error {
// create, import, export keys // create, import, export keys
utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier) clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier, string(keyManager.PublicKey()))
ethereum = utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer) ethereum := utils.NewEthereum(db, clientIdentity, keyManager, utils.NatType(NatType, PMPGateway), OutboundPort, MaxPeer)
if ShowGenesis { if ShowGenesis {
utils.ShowGenesis(ethereum) utils.ShowGenesis(ethereum)

View File

@ -27,7 +27,9 @@ import (
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/javascript" "github.com/ethereum/go-ethereum/javascript"
"github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/state"
@ -56,6 +58,7 @@ type UiLib struct {
jsEngine *javascript.JSRE jsEngine *javascript.JSRE
filterCallbacks map[int][]int filterCallbacks map[int][]int
filterManager *filter.FilterManager
miner *miner.Miner miner *miner.Miner
} }
@ -63,7 +66,7 @@ type UiLib struct {
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
lib := &UiLib{JSXEth: xeth.NewJSXEth(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)} lib := &UiLib{JSXEth: xeth.NewJSXEth(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)}
lib.miner = miner.New(eth.KeyManager().Address(), eth) lib.miner = miner.New(eth.KeyManager().Address(), eth)
//eth.filterManager = filter.NewFilterManager(eth.EventMux()) lib.filterManager = filter.NewFilterManager(eth.EventMux())
return lib return lib
} }
@ -123,7 +126,8 @@ func (self *UiLib) LookupAddress(name string) string {
} }
func (self *UiLib) PastPeers() *ethutil.List { func (self *UiLib) PastPeers() *ethutil.List {
return ethutil.NewList(eth.PastPeers()) return ethutil.NewList([]string{})
//return ethutil.NewList(eth.PastPeers())
} }
func (self *UiLib) ImportTx(rlpTx string) { func (self *UiLib) ImportTx(rlpTx string) {
@ -191,7 +195,7 @@ func (ui *UiLib) Connect(button qml.Object) {
} }
func (ui *UiLib) ConnectToPeer(addr string) { func (ui *UiLib) ConnectToPeer(addr string) {
ui.eth.ConnectToPeer(addr) ui.eth.SuggestPeer(addr)
} }
func (ui *UiLib) AssetPath(p string) string { func (ui *UiLib) AssetPath(p string) string {
@ -226,7 +230,7 @@ func (self *UiLib) NewFilter(object map[string]interface{}) (id int) {
filter.MessageCallback = func(messages state.Messages) { filter.MessageCallback = func(messages state.Messages) {
self.win.Root().Call("invokeFilterCallback", xeth.ToJSMessages(messages), id) self.win.Root().Call("invokeFilterCallback", xeth.ToJSMessages(messages), id)
} }
id = self.eth.InstallFilter(filter) id = self.filterManager.InstallFilter(filter)
return id return id
} }
@ -239,12 +243,12 @@ func (self *UiLib) NewFilterString(typ string) (id int) {
fmt.Println("QML is lagging") fmt.Println("QML is lagging")
} }
} }
id = self.eth.InstallFilter(filter) id = self.filterManager.InstallFilter(filter)
return id return id
} }
func (self *UiLib) Messages(id int) *ethutil.List { func (self *UiLib) Messages(id int) *ethutil.List {
filter := self.eth.GetFilter(id) filter := self.filterManager.GetFilter(id)
if filter != nil { if filter != nil {
messages := xeth.ToJSMessages(filter.Find()) messages := xeth.ToJSMessages(filter.Find())
@ -255,7 +259,7 @@ func (self *UiLib) Messages(id int) *ethutil.List {
} }
func (self *UiLib) UninstallFilter(id int) { func (self *UiLib) UninstallFilter(id int) {
self.eth.UninstallFilter(id) self.filterManager.UninstallFilter(id)
} }
func mapToTxParams(object map[string]interface{}) map[string]string { func mapToTxParams(object map[string]interface{}) map[string]string {

View File

@ -147,6 +147,10 @@ func (s *Ethereum) Peers() []*p2p.Peer {
return s.server.Peers() return s.server.Peers()
} }
func (s *Ethereum) MaxPeers() int {
return s.server.MaxPeers
}
// Start the ethereum // Start the ethereum
func (s *Ethereum) Start(seed bool) error { func (s *Ethereum) Start(seed bool) error {
err := s.server.Start() err := s.server.Start()

23
eth/peer_util.go Normal file
View File

@ -0,0 +1,23 @@
package eth
import (
"encoding/json"
"github.com/ethereum/go-ethereum/ethutil"
)
func WritePeers(path string, addresses []string) {
if len(addresses) > 0 {
data, _ := json.MarshalIndent(addresses, "", " ")
ethutil.WriteFile(path, data)
}
}
func ReadPeers(path string) (ips []string, err error) {
var data string
data, err = ethutil.ReadAllFile(path)
if err != nil {
json.Unmarshal([]byte(data), &ips)
}
return
}

View File

@ -416,6 +416,7 @@ func (srv *Server) verifyPeer(addr *peerAddr) error {
return nil return nil
} }
// TODO replace with "Set"
type Blacklist interface { type Blacklist interface {
Get([]byte) (bool, error) Get([]byte) (bool, error)
Put([]byte) error Put([]byte) error