Merge pull request #12 from status-im/light-decrypt

Light decrypt
This commit is contained in:
Jarrad 2016-06-30 15:44:42 +02:00 committed by GitHub
commit 653e5fe406
8 changed files with 209 additions and 148 deletions

188
src/Godeps/Godeps.json generated
View File

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

View File

@ -15,36 +15,42 @@ import (
) )
var ( var (
scryptN = 262144 scryptN = 4096
scryptP = 1 scryptP = 6
) )
// 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
} }

View File

@ -11,13 +11,6 @@ import (
// unlock that account // unlock that account
func TestAccountBindings(t *testing.T) { func TestAccountBindings(t *testing.T) {
// create an account
address, _, err := createAccount("badpassword", ".ethereumtest/keystore")
if err != nil {
fmt.Println(err.Error())
t.Error("Test failed: could not create account")
}
// start geth node and wait for it to initialize // start geth node and wait for it to initialize
go createAndStartNode(".ethereumtest") go createAndStartNode(".ethereumtest")
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
@ -25,6 +18,13 @@ func TestAccountBindings(t *testing.T) {
t.Error("Test failed: could not start geth node") t.Error("Test failed: could not start geth node")
} }
// create an account
address, _, err := createAccount("badpassword", ".ethereumtest/keystore")
if err != nil {
fmt.Println(err.Error())
t.Error("Test failed: could not create account")
}
// unlock the created account // unlock the created account
err = unlockAccount(address, "badpassword", 10) err = unlockAccount(address, "badpassword", 10)
if err != nil { if err != nil {

View File

@ -7,50 +7,77 @@ import (
"os" "os"
) )
//export doCreateAccount var emptyError = ""
func doCreateAccount(password, keydir *C.char) *C.char {
//export CreateAccount
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))
errString := emptyError
if err != nil {
fmt.Fprintln(os.Stderr, err)
errString = err.Error()
}
out := AccountInfo{ out := AccountInfo{
Address: address, Address: address,
PubKey: pubKey, PubKey: pubKey,
Error: err.Error(), Error: errString,
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
} }
outBytes, _ := json.Marshal(&out) outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
return C.CString(string(outBytes))
} }
//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
err := unlockAccount(C.GoString(address), C.GoString(password), seconds) err := unlockAccount(C.GoString(address), C.GoString(password), seconds)
out := JSONError{
Error: err.Error(), errString := emptyError
}
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
errString = err.Error()
}
out := JSONError{
Error: errString,
} }
outBytes, _ := json.Marshal(&out) outBytes, _ := json.Marshal(&out)
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{
Error: err.Error(), errString := emptyError
}
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
errString = err.Error()
}
out := JSONError{
Error: errString,
} }
outBytes, _ := json.Marshal(&out) outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes)) return C.CString(string(outBytes))
} }

View File

@ -27,11 +27,11 @@ 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
) )
func main() { func main() {
@ -48,6 +48,7 @@ func MakeNode(datadir string) *node.Node {
set.Bool("shh", true, "whisper") set.Bool("shh", true, "whisper")
set.Bool("noeth", true, "disable eth") set.Bool("noeth", true, "disable eth")
set.String("datadir", datadir, "data directory for geth") set.String("datadir", datadir, "data directory for geth")
set.String("logdir", datadir, "log dir for glog")
c = cli.NewContext(nil, set, nil) c = cli.NewContext(nil, set, nil)
// Construct the textual version string from the individual components // Construct the textual version string from the individual components
@ -60,13 +61,14 @@ func MakeNode(datadir string) *node.Node {
rConfig.Minor = uint32(versionMinor) rConfig.Minor = uint32(versionMinor)
rConfig.Patch = uint32(versionPatch) rConfig.Patch = uint32(versionPatch)
utils.DebugSetup(c)
currentNode, accountSync = utils.MakeSystemNode(clientIdentifier, vString, rConfig, makeDefaultExtra(), c) currentNode, accountSync = utils.MakeSystemNode(clientIdentifier, vString, rConfig, makeDefaultExtra(), c)
return currentNode return currentNode
} }
// 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()
} }

View File

@ -40,6 +40,7 @@ import (
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/les" "github.com/ethereum/go-ethereum/les"
"github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
@ -414,6 +415,13 @@ var (
} }
) )
// DebugSetup sets up the debugging parameters such that logs can be retrieved when a
// node is started via importing go-ethereum packages, as opposed to starting via CLI
func DebugSetup(ctx *cli.Context) error {
err := debug.Setup(ctx)
return err
}
// MustMakeDataDir retrieves the currently requested data directory, terminating // MustMakeDataDir retrieves the currently requested data directory, terminating
// if none (or the empty string) is specified. If the node is starting a testnet, // if none (or the empty string) is specified. If the node is starting a testnet,
// the a subdirectory of the specified datadir will be used. // the a subdirectory of the specified datadir will be used.

View File

@ -84,6 +84,12 @@ func (*HandlerT) GcStats() *debug.GCStats {
return s return s
} }
// SetLogDir overwrites the default log file utilized by glog
func (h *HandlerT) SetLogDir(logDir string) error {
glog.SetLogDir(logDir)
return nil
}
// CpuProfile turns on CPU profiling for nsec seconds and writes // CpuProfile turns on CPU profiling for nsec seconds and writes
// profile data to file. // profile data to file.
func (h *HandlerT) CpuProfile(file string, nsec uint) error { func (h *HandlerT) CpuProfile(file string, nsec uint) error {

View File

@ -43,6 +43,10 @@ var (
Usage: "Request a stack trace at a specific logging statement (e.g. \"block.go:271\")", Usage: "Request a stack trace at a specific logging statement (e.g. \"block.go:271\")",
Value: glog.GetTraceLocation(), Value: glog.GetTraceLocation(),
} }
logdirFlag = cli.StringFlag{
Name: "logdir",
Usage: "Request that glog use the specified log dir location",
}
pprofFlag = cli.BoolFlag{ pprofFlag = cli.BoolFlag{
Name: "pprof", Name: "pprof",
Usage: "Enable the pprof HTTP server", Usage: "Enable the pprof HTTP server",
@ -73,7 +77,7 @@ var (
// Flags holds all command-line flags required for debugging. // Flags holds all command-line flags required for debugging.
var Flags = []cli.Flag{ var Flags = []cli.Flag{
verbosityFlag, vmoduleFlag, backtraceAtFlag, verbosityFlag, vmoduleFlag, logdirFlag, backtraceAtFlag,
pprofFlag, pprofPortFlag, pprofFlag, pprofPortFlag,
memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag, memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag,
} }
@ -81,9 +85,17 @@ var Flags = []cli.Flag{
// Setup initializes profiling and logging based on the CLI flags. // Setup initializes profiling and logging based on the CLI flags.
// It should be called as early as possible in the program. // It should be called as early as possible in the program.
func Setup(ctx *cli.Context) error { func Setup(ctx *cli.Context) error {
// logging // logging
if logDir := ctx.GlobalString(logdirFlag.Name); logDir != "" {
if err := Handler.SetLogDir(logDir); err != nil {
return err
}
glog.SetToStderr(false)
} else {
glog.SetToStderr(true)
}
glog.CopyStandardLogTo("INFO") glog.CopyStandardLogTo("INFO")
glog.SetToStderr(true)
// profiling, tracing // profiling, tracing
runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name) runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name)