2016-06-15 19:50:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-06-20 15:21:45 +00:00
|
|
|
"errors"
|
2016-06-15 19:50:35 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
2016-06-21 14:34:38 +00:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2016-06-15 19:50:35 +00:00
|
|
|
"github.com/ethereum/go-ethereum/node"
|
2016-06-21 14:34:38 +00:00
|
|
|
errextra "github.com/pkg/errors"
|
2016-06-15 19:50:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
scryptN = 262144
|
|
|
|
scryptP = 1
|
|
|
|
)
|
|
|
|
|
2016-06-21 14:07:24 +00:00
|
|
|
// createAccount creates an internal geth account
|
2016-06-21 14:34:38 +00:00
|
|
|
func createAccount(password, keydir string) (string, string, error) {
|
2016-06-15 19:50:35 +00:00
|
|
|
|
|
|
|
var sync *[]node.Service
|
|
|
|
w := true
|
2016-06-20 02:01:28 +00:00
|
|
|
accman := accounts.NewManager(keydir, scryptN, scryptP, sync)
|
2016-06-15 19:50:35 +00:00
|
|
|
|
2016-06-20 02:01:28 +00:00
|
|
|
account, err := accman.NewAccount(password, w)
|
2016-06-15 19:50:35 +00:00
|
|
|
if err != nil {
|
2016-06-21 14:34:38 +00:00
|
|
|
return "", "", errextra.Wrap(err, "Account manager could not create the account")
|
2016-06-15 19:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-15 19:50:35 +00:00
|
|
|
|
|
|
|
}
|
2016-06-20 15:21:45 +00:00
|
|
|
|
2016-06-21 14:07:24 +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")
|
|
|
|
|
|
|
|
}
|