error handling to C

This commit is contained in:
Daniel Whitenack 2016-06-30 08:23:07 -05:00
parent 8dcb47d97f
commit e95e22f067
2 changed files with 41 additions and 18 deletions

View File

@ -11,13 +11,6 @@ import (
// unlock that account
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
go createAndStartNode(".ethereumtest")
time.Sleep(5 * time.Second)
@ -25,6 +18,13 @@ func TestAccountBindings(t *testing.T) {
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
err = unlockAccount(address, "badpassword", 10)
if err != nil {

View File

@ -9,20 +9,27 @@ import (
//export CreateAccount
func CreateAccount(password, keydir *C.char) *C.char {
// This is equivalent to creating an account from the command line,
// just modified to handle the function arg passing
address, pubKey, err := createAccount(C.GoString(password), C.GoString(keydir))
var errString string
if err != nil {
fmt.Fprintln(os.Stderr, err)
errString = err.Error()
} else {
errString = ""
}
out := AccountInfo{
Address: address,
PubKey: pubKey,
Error: err.Error(),
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
Error: errString,
}
outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
return C.CString(string(outBytes))
}
//export Login
@ -35,30 +42,46 @@ func Login(address, password *C.char) *C.char {
//export UnlockAccount
func UnlockAccount(address, password *C.char, seconds int) *C.char {
// 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
err := unlockAccount(C.GoString(address), C.GoString(password), seconds)
out := JSONError{
Error: err.Error(),
}
var errString string
if err != nil {
fmt.Fprintln(os.Stderr, err)
errString = err.Error()
} else {
errString = ""
}
out := JSONError{
Error: errString,
}
outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
}
//export StartNode
func StartNode(datadir *C.char) *C.char {
// This starts a geth node with the given datadir
err := createAndStartNode(C.GoString(datadir))
out := JSONError{
Error: err.Error(),
}
var errString string
if err != nil {
fmt.Fprintln(os.Stderr, err)
errString = err.Error()
} else {
errString = ""
}
out := JSONError{
Error: errString,
}
outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
}