From 7399ea5b8382c9a83462466c32d2c8935b4f77e4 Mon Sep 17 00:00:00 2001 From: Daniel Whitenack Date: Mon, 20 Jun 2016 10:21:45 -0500 Subject: [PATCH] node object with start function --- src/gethdep.go | 13 +++++++++++++ src/library.go | 11 +++++++++++ src/main.go | 23 ++++++++++++++++------- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/gethdep.go b/src/gethdep.go index c67bc4a58..0bdcb4ff7 100644 --- a/src/gethdep.go +++ b/src/gethdep.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/ethereum/go-ethereum/accounts" @@ -28,3 +29,15 @@ func createAccount(password, keydir string) error { return nil } + +func createAndStartNode(datadir string) error { + + currentNode := MakeNode(datadir) + if currentNode != nil { + StartNode(currentNode) + return nil + } + + return errors.New("Could not create the in-memory node object") + +} diff --git a/src/library.go b/src/library.go index c10eb93fb..d5c7df18f 100644 --- a/src/library.go +++ b/src/library.go @@ -16,3 +16,14 @@ func doCreateAccount(password, keydir *C.char) C.int { } return 0 } + +// export doStartNode +func doStartNode(datadir *C.char) C.int { + // This starts a geth node with the given datadir + if err := createAndStartNode(C.GoString(datadir)); err != nil { + fmt.Fprintln(os.Stderr, err) + return -1 + } + return 0 + +} diff --git a/src/main.go b/src/main.go index 35c868e56..46c36a66b 100644 --- a/src/main.go +++ b/src/main.go @@ -33,18 +33,21 @@ var ( c *cli.Context ) -func init() { +func main() { + + // Placeholder for anything we want to run by default + fmt.Println("You are running statusgo!") + +} + +func MakeNode(datadir string) *node.Node { set := flag.NewFlagSet("test", 0) set.Bool("shh", true, "whisper") set.Bool("noeth", true, "disable eth") - set.String("datadir", ".ethereum", "data directory for geth") + set.String("datadir", datadir, "data directory for geth") c = cli.NewContext(nil, set, nil) -} - -func main() { - // Construct the textual version string from the individual components vString = fmt.Sprintf("%d.%d.%d", versionMajor, versionMinor, versionPatch) @@ -56,7 +59,13 @@ func main() { rConfig.Patch = uint32(versionPatch) currentNode = utils.MakeSystemNode(clientIdentifier, vString, rConfig, makeDefaultExtra(), c) - fmt.Println(currentNode) + return currentNode + +} + +func StartNode(currentNode *node.Node) { + utils.StartNode(currentNode) + currentNode.Wait() } func makeDefaultExtra() []byte {