status-go/src/gethdep.go

54 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
2016-06-20 15:21:45 +00:00
"errors"
"fmt"
"github.com/ethereum/go-ethereum/accounts"
2016-06-21 14:34:38 +00:00
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/node"
2016-06-21 14:34:38 +00:00
errextra "github.com/pkg/errors"
)
var (
scryptN = 262144
scryptP = 1
)
// createAccount creates an internal geth account
2016-06-21 14:34:38 +00:00
func createAccount(password, keydir string) (string, string, error) {
var sync *[]node.Service
w := true
2016-06-20 02:01:28 +00:00
accman := accounts.NewManager(keydir, scryptN, scryptP, sync)
2016-06-20 02:01:28 +00:00
account, err := accman.NewAccount(password, w)
if err != nil {
2016-06-21 14:34:38 +00:00
return "", "", errextra.Wrap(err, "Account manager could not create the account")
}
address := fmt.Sprintf("{%x}", account.Address)
2016-06-21 14:34:38 +00:00
key, err := crypto.LoadECDSA(account.File)
if err != nil {
return address, "", errextra.Wrap(err, "Could not load the key")
}
pubKey := string(crypto.FromECDSAPub(&key.PublicKey))
return address, pubKey, nil
}
2016-06-20 15:21:45 +00:00
// createAndStartNode creates a node entity and starts the
// node running locally
2016-06-20 15:21:45 +00:00
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")
}