unlock account binding, functionality

This commit is contained in:
Daniel Whitenack 2016-06-21 13:29:38 -05:00
parent 9cee10eb61
commit b7d2a7432a
5 changed files with 145 additions and 106 deletions

188
src/Godeps/Godeps.json generated
View File

@ -22,238 +22,238 @@
},
{
"ImportPath": "github.com/ethereum/go-ethereum/accounts",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/accounts/abi",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/accounts/abi/bind",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/cmd/utils",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common/compiler",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common/httpclient",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common/registrar",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/common/registrar/ethreg",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/core",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/core/state",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/core/types",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/core/vm",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto/ecies",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto/randentropy",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto/secp256k1",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/crypto/sha3",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth/downloader",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth/fetcher",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth/filters",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/eth/gasprice",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/ethapi",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/ethdb",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/event",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/event/filter",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/internal/debug",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/jsre",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/les",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/les/flowcontrol",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/light",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/logger",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/logger/glog",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/metrics",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/miner",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/node",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/p2p",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/p2p/discover",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/p2p/nat",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/params",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/pow",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/release",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/rlp",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/rpc",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/trie",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/ethereum/go-ethereum/whisper",
"Comment": "v1.0.1-894-gca8606b",
"Rev": "ca8606be4d90c0ec49581fe22c8ee4d251a31714"
"Comment": "v1.0.1-897-g3144839",
"Rev": "31448394c8ee75b73b5a5931ea9e2e8b3564a0de"
},
{
"ImportPath": "github.com/fatih/color",

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/node"
errextra "github.com/pkg/errors"
@ -27,7 +28,7 @@ func createAccount(password, keydir string) (string, string, error) {
return "", "", errextra.Wrap(err, "Account manager could not create the account")
}
address := fmt.Sprintf("{%x}", account.Address)
address := fmt.Sprintf("%x", account.Address)
key, err := crypto.LoadECDSA(account.File)
if err != nil {
return address, "", errextra.Wrap(err, "Could not load the key")
@ -38,6 +39,32 @@ func createAccount(password, keydir string) (string, string, error) {
}
// unlockAccount unlocks an existing account for a certain duration and
// inject the account as a whisper identity if the account was created as
// a whisper enabled account
func unlockAccount(address, password string) error {
if currentNode != nil {
accman := utils.MakeAccountManager(c, &accountSync)
account, err := utils.MakeAddress(accman, address)
if err != nil {
return errextra.Wrap(err, "Could not retrieve account from address")
}
err = accman.Unlock(account, password)
if err != nil {
return errextra.Wrap(err, "Could not decrypt account")
}
return nil
}
return errors.New("No running node detected for account unlock")
}
// createAndStartNode creates a node entity and starts the
// node running locally
func createAndStartNode(datadir string) error {

View File

@ -18,6 +18,18 @@ func doCreateAccount(password, keydir *C.char) (*C.char, *C.char, C.int) {
return C.CString(address), C.CString(pubKey), 0
}
//export doUnlockAccount
func doUnlockAccount(address, password *C.char) C.int {
// 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
if err := unlockAccount(C.GoString(address), C.GoString(password)); err != nil {
fmt.Fprintln(os.Stderr, err)
return -1
}
return 0
}
// export doStartNode
func doStartNode(datadir *C.char) C.int {
// This starts a geth node with the given datadir
@ -26,5 +38,4 @@ func doStartNode(datadir *C.char) C.int {
return -1
}
return 0
}

View File

@ -27,10 +27,11 @@ const (
)
var (
vString string // Combined textual representation of all the version components
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
)
func main() {
@ -59,15 +60,15 @@ func MakeNode(datadir string) *node.Node {
rConfig.Minor = uint32(versionMinor)
rConfig.Patch = uint32(versionPatch)
currentNode = utils.MakeSystemNode(clientIdentifier, vString, rConfig, makeDefaultExtra(), c)
currentNode, accountSync = utils.MakeSystemNode(clientIdentifier, vString, rConfig, makeDefaultExtra(), c)
return currentNode
}
// StartNode starts a geth node entity
func StartNode(currentNode *node.Node) {
utils.StartNode(currentNode)
currentNode.Wait()
func StartNode(nodeIn *node.Node) {
utils.StartNode(nodeIn)
nodeIn.Wait()
}
func makeDefaultExtra() []byte {

View File

@ -662,7 +662,7 @@ func MakePasswordList(ctx *cli.Context) []string {
// MakeSystemNode sets up a local node, configures the services to launch and
// assembles the P2P protocol stack.
func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) *node.Node {
func MakeSystemNode(name, version string, relconf release.Config, extra []byte, ctx *cli.Context) (*node.Node, []node.Service) {
// Avoid conflicting network flags
networks, netFlags := 0, []cli.BoolFlag{DevModeFlag, TestNetFlag, OlympicFlag}
for _, flag := range netFlags {
@ -695,8 +695,8 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
WSModules: MakeRPCModules(ctx.GlobalString(WSApiFlag.Name)),
}
// Configure the Ethereum service
var AccountSync []node.Service
accman := MakeAccountManager(ctx, &AccountSync)
var accountSync []node.Service
accman := MakeAccountManager(ctx, &accountSync)
// initialise new random number generator
rand := rand.New(rand.NewSource(time.Now().UnixNano()))
@ -797,7 +797,7 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
if shhEnable {
if err := stack.Register(func(*node.ServiceContext) (node.Service, error) {
whisperInstance := whisper.New()
AccountSync = append(AccountSync, whisperInstance)
accountSync = append(accountSync, whisperInstance)
return whisperInstance, nil
}); err != nil {
Fatalf("Failed to register the Whisper service: %v", err)
@ -837,7 +837,7 @@ func MakeSystemNode(name, version string, relconf release.Config, extra []byte,
}
}
return stack
return stack, accountSync
}
// SetupNetwork configures the system for either the main net or some test network.