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