JSON output for bindings

This commit is contained in:
Daniel Whitenack 2016-06-22 06:29:35 -05:00
parent b7d2a7432a
commit e47d7a024f
1 changed files with 21 additions and 12 deletions

View File

@ -7,35 +7,44 @@ import (
)
//export doCreateAccount
func doCreateAccount(password, keydir *C.char) (*C.char, *C.char, C.int) {
func doCreateAccount(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))
out := fmt.Sprintf(`{
"address": %s,
"pubkey": %s,
"error": %s
}`, address, pubKey, err.Error())
if err != nil {
fmt.Fprintln(os.Stderr, err)
return C.CString(""), C.CString(""), -1
return C.CString(out)
}
return C.CString(address), C.CString(pubKey), 0
return C.CString(out)
}
//export doUnlockAccount
func doUnlockAccount(address, password *C.char) C.int {
func doUnlockAccount(address, password *C.char) *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
if err := unlockAccount(C.GoString(address), C.GoString(password)); err != nil {
err := unlockAccount(C.GoString(address), C.GoString(password))
out := fmt.Sprintf("{\"error\": %s}", err.Error())
if err != nil {
fmt.Fprintln(os.Stderr, err)
return -1
return C.CString(out)
}
return 0
return C.CString(out)
}
//export doStartNode
func doStartNode(datadir *C.char) C.int {
func doStartNode(datadir *C.char) *C.char {
// This starts a geth node with the given datadir
if err := createAndStartNode(C.GoString(datadir)); err != nil {
err := createAndStartNode(C.GoString(datadir))
out := fmt.Sprintf("{\"error\": %s}", err.Error())
if err != nil {
fmt.Fprintln(os.Stderr, err)
return -1
return C.CString(out)
}
return 0
return C.CString(out)
}