status-go/src/main.go

97 lines
3.1 KiB
Go
Raw Normal View History

package main
import (
2016-06-20 14:47:10 +00:00
"flag"
"fmt"
2016-06-20 14:47:10 +00:00
"runtime"
2016-06-20 14:47:10 +00:00
"github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/release"
"github.com/ethereum/go-ethereum/rlp"
)
2016-06-20 14:47:10 +00:00
const (
clientIdentifier = "Geth" // Client identifier to advertise over the network
versionMajor = 1 // Major version component of the current release
versionMinor = 5 // Minor version component of the current release
versionPatch = 0 // Patch version component of the current release
versionMeta = "unstable" // Version metadata to append to the version string
versionOracle = "0xfa7b9770ca4cb04296cac84f37736d4041251cdf" // Ethereum address of the Geth release oracle
)
var (
2016-06-29 11:57:21 +00:00
vString string // Combined textual representation of the version
rConfig release.Config // Structured version information and release oracle config
currentNode *node.Node // currently running geth node
c *cli.Context // the CLI context used to start the geth node
accountSync []node.Service // the object used to sync accounts between geth services
2016-06-20 14:47:10 +00:00
)
2016-06-20 15:21:45 +00:00
func main() {
// Placeholder for anything we want to run by default
fmt.Println("You are running statusgo!")
}
2016-06-21 14:35:43 +00:00
// MakeNode create a geth node entity
2016-06-20 15:21:45 +00:00
func MakeNode(datadir string) *node.Node {
2016-06-20 14:47:10 +00:00
set := flag.NewFlagSet("test", 0)
set.Bool("shh", true, "whisper")
set.Bool("noeth", true, "disable eth")
set.Bool("rpc", true, "enable rpc")
set.String("rpcapi", "db,eth,net,web3,shh,admin", "rpc api(s)")
2016-06-20 15:21:45 +00:00
set.String("datadir", datadir, "data directory for geth")
2016-06-29 22:48:21 +00:00
set.String("logdir", datadir, "log dir for glog")
2016-06-20 14:47:10 +00:00
c = cli.NewContext(nil, set, nil)
2016-06-20 14:47:10 +00:00
// Construct the textual version string from the individual components
vString = fmt.Sprintf("%d.%d.%d", versionMajor, versionMinor, versionPatch)
// Construct the version release oracle configuration
rConfig.Oracle = common.HexToAddress(versionOracle)
rConfig.Major = uint32(versionMajor)
rConfig.Minor = uint32(versionMinor)
rConfig.Patch = uint32(versionPatch)
2016-06-29 22:48:21 +00:00
utils.DebugSetup(c)
2016-06-21 18:29:38 +00:00
currentNode, accountSync = utils.MakeSystemNode(clientIdentifier, vString, rConfig, makeDefaultExtra(), c)
2016-06-20 15:21:45 +00:00
return currentNode
}
2016-06-21 14:35:43 +00:00
// StartNode starts a geth node entity
2016-06-29 11:32:04 +00:00
func RunNode(nodeIn *node.Node) {
2016-06-21 18:29:38 +00:00
utils.StartNode(nodeIn)
nodeIn.Wait()
2016-06-20 14:47:10 +00:00
}
func makeDefaultExtra() []byte {
var clientInfo = struct {
Version uint
Name string
GoVersion string
Os string
}{uint(versionMajor<<16 | versionMinor<<8 | versionPatch), clientIdentifier, runtime.Version(), runtime.GOOS}
extra, err := rlp.EncodeToBytes(clientInfo)
if err != nil {
glog.V(logger.Warn).Infoln("error setting canonical miner information:", err)
}
if uint64(len(extra)) > params.MaximumExtraDataSize.Uint64() {
glog.V(logger.Warn).Infoln("error setting canonical miner information: extra exceeds", params.MaximumExtraDataSize)
glog.V(logger.Debug).Infof("extra: %x\n", extra)
return nil
}
2016-06-20 14:47:10 +00:00
return extra
}