re-name functions, modify inputs
This commit is contained in:
parent
9272538432
commit
f20608eaa7
|
@ -22,29 +22,35 @@ var (
|
|||
// createAccount creates an internal geth account
|
||||
func createAccount(password, keydir string) (string, string, error) {
|
||||
|
||||
var sync *[]node.Service
|
||||
w := true
|
||||
accman := accounts.NewManager(keydir, scryptN, scryptP, sync)
|
||||
if currentNode != nil {
|
||||
|
||||
// generate the account
|
||||
account, err := accman.NewAccount(password, w)
|
||||
if err != nil {
|
||||
return "", "", errextra.Wrap(err, "Account manager could not create the account")
|
||||
}
|
||||
address := fmt.Sprintf("%x", account.Address)
|
||||
var sync *[]node.Service
|
||||
w := true
|
||||
accman := accounts.NewManager(keydir, scryptN, scryptP, sync)
|
||||
|
||||
// recover the public key to return
|
||||
keyContents, err := ioutil.ReadFile(account.File)
|
||||
if err != nil {
|
||||
return address, "", errextra.Wrap(err, "Could not load the key contents")
|
||||
}
|
||||
key, err := accounts.DecryptKey(keyContents, password)
|
||||
if err != nil {
|
||||
return address, "", errextra.Wrap(err, "Could not recover the key")
|
||||
}
|
||||
pubKey := common.ToHex(crypto.FromECDSAPub(&key.PrivateKey.PublicKey))
|
||||
// generate the account
|
||||
account, err := accman.NewAccount(password, w)
|
||||
if err != nil {
|
||||
return "", "", errextra.Wrap(err, "Account manager could not create the account")
|
||||
}
|
||||
address := fmt.Sprintf("%x", account.Address)
|
||||
|
||||
return address, pubKey, nil
|
||||
// recover the public key to return
|
||||
keyContents, err := ioutil.ReadFile(account.File)
|
||||
if err != nil {
|
||||
return address, "", errextra.Wrap(err, "Could not load the key contents")
|
||||
}
|
||||
key, err := accounts.DecryptKey(keyContents, password)
|
||||
if err != nil {
|
||||
return address, "", errextra.Wrap(err, "Could not recover the key")
|
||||
}
|
||||
pubKey := common.ToHex(crypto.FromECDSAPub(&key.PrivateKey.PublicKey))
|
||||
|
||||
return address, pubKey, nil
|
||||
|
||||
}
|
||||
|
||||
return "", "", errors.New("No running node detected for account creation")
|
||||
|
||||
}
|
||||
|
||||
|
@ -80,7 +86,7 @@ func createAndStartNode(datadir string) error {
|
|||
|
||||
currentNode = MakeNode(datadir)
|
||||
if currentNode != nil {
|
||||
StartNode(currentNode)
|
||||
RunNode(currentNode)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
//export doCreateAccount
|
||||
func doCreateAccount(password, keydir *C.char) *C.char {
|
||||
//export CreateAccount
|
||||
func CreateAccount(password, keydir *C.char) *C.char {
|
||||
// This is equivalent to creating an account from the command line,
|
||||
// just modified to handle the function arg passing
|
||||
address, pubKey, err := createAccount(C.GoString(password), C.GoString(keydir))
|
||||
|
@ -25,8 +25,16 @@ func doCreateAccount(password, keydir *C.char) *C.char {
|
|||
|
||||
}
|
||||
|
||||
//export doUnlockAccount
|
||||
func doUnlockAccount(address, password *C.char, seconds int) *C.char {
|
||||
//export Login
|
||||
func Login(address, password *C.char) *C.char {
|
||||
// Equivalent to unlocking an account briefly, to inject a whisper identity,
|
||||
// then locking the account again
|
||||
out := UnlockAccount(address, password, 5)
|
||||
return out
|
||||
}
|
||||
|
||||
//export UnlockAccount
|
||||
func UnlockAccount(address, password *C.char, seconds int) *C.char {
|
||||
// This is equivalent to unlocking an account from the command line,
|
||||
// just modified to unlock the account for the currently running geth node
|
||||
// based on the provided arguments
|
||||
|
@ -41,8 +49,8 @@ func doUnlockAccount(address, password *C.char, seconds int) *C.char {
|
|||
return C.CString(string(outBytes))
|
||||
}
|
||||
|
||||
//export doStartNode
|
||||
func doStartNode(datadir *C.char) *C.char {
|
||||
//export StartNode
|
||||
func StartNode(datadir *C.char) *C.char {
|
||||
// This starts a geth node with the given datadir
|
||||
err := createAndStartNode(C.GoString(datadir))
|
||||
out := JSONError{
|
||||
|
|
14
src/main.go
14
src/main.go
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
|
@ -27,11 +28,12 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
vString string // Combined textual representation of the version components
|
||||
rConfig release.Config // Structured version information and release oracle config
|
||||
currentNode *node.Node
|
||||
c *cli.Context
|
||||
accountSync []node.Service
|
||||
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
|
||||
MyTransactions chan TxRequest
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -66,7 +68,7 @@ func MakeNode(datadir string) *node.Node {
|
|||
}
|
||||
|
||||
// StartNode starts a geth node entity
|
||||
func StartNode(nodeIn *node.Node) {
|
||||
func RunNode(nodeIn *node.Node) {
|
||||
utils.StartNode(nodeIn)
|
||||
nodeIn.Wait()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue