From b7d2a7432af8c33918f501f3b585439b7e8705b9 Mon Sep 17 00:00:00 2001 From: Daniel Whitenack Date: Tue, 21 Jun 2016 13:29:38 -0500 Subject: [PATCH] unlock account binding, functionality --- src/Godeps/Godeps.json | 188 +++++++++--------- src/gethdep.go | 29 ++- src/library.go | 13 +- src/main.go | 11 +- .../ethereum/go-ethereum/cmd/utils/flags.go | 10 +- 5 files changed, 145 insertions(+), 106 deletions(-) diff --git a/src/Godeps/Godeps.json b/src/Godeps/Godeps.json index f9465e2ee..7bac3cec7 100644 --- a/src/Godeps/Godeps.json +++ b/src/Godeps/Godeps.json @@ -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", diff --git a/src/gethdep.go b/src/gethdep.go index 01d4fae8d..056f33a13 100644 --- a/src/gethdep.go +++ b/src/gethdep.go @@ -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 { diff --git a/src/library.go b/src/library.go index 5b24300a8..33c8b554a 100644 --- a/src/library.go +++ b/src/library.go @@ -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 - } diff --git a/src/main.go b/src/main.go index 6eb3f4eec..00e118e74 100644 --- a/src/main.go +++ b/src/main.go @@ -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 { diff --git a/src/vendor/github.com/ethereum/go-ethereum/cmd/utils/flags.go b/src/vendor/github.com/ethereum/go-ethereum/cmd/utils/flags.go index 1ba45bc8e..534d9bf92 100644 --- a/src/vendor/github.com/ethereum/go-ethereum/cmd/utils/flags.go +++ b/src/vendor/github.com/ethereum/go-ethereum/cmd/utils/flags.go @@ -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.