2016-06-15 13:54:07 +00:00
|
|
|
package main
|
|
|
|
|
2016-06-15 19:50:35 +00:00
|
|
|
import "C"
|
2016-06-15 13:54:07 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2016-06-15 19:50:35 +00:00
|
|
|
"os"
|
2016-06-15 13:54:07 +00:00
|
|
|
)
|
|
|
|
|
2016-06-20 02:01:28 +00:00
|
|
|
//export doCreateAccount
|
2016-06-22 11:29:35 +00:00
|
|
|
func doCreateAccount(password, keydir *C.char) *C.char {
|
2016-06-20 01:46:13 +00:00
|
|
|
// This is equivalent to creating an account from the command line,
|
|
|
|
// just modified to handle the function arg passing
|
2016-06-21 14:34:38 +00:00
|
|
|
address, pubKey, err := createAccount(C.GoString(password), C.GoString(keydir))
|
2016-06-22 11:29:35 +00:00
|
|
|
out := fmt.Sprintf(`{
|
|
|
|
"address": %s,
|
|
|
|
"pubkey": %s,
|
|
|
|
"error": %s
|
|
|
|
}`, address, pubKey, err.Error())
|
2016-06-21 14:07:24 +00:00
|
|
|
if err != nil {
|
2016-06-15 19:50:35 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2016-06-15 13:54:07 +00:00
|
|
|
}
|
2016-06-22 11:29:35 +00:00
|
|
|
return C.CString(out)
|
2016-06-15 13:54:07 +00:00
|
|
|
}
|
2016-06-20 15:21:45 +00:00
|
|
|
|
2016-06-21 18:29:38 +00:00
|
|
|
//export doUnlockAccount
|
2016-06-22 11:29:35 +00:00
|
|
|
func doUnlockAccount(address, password *C.char) *C.char {
|
2016-06-21 18:29:38 +00:00
|
|
|
// 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
|
2016-06-22 11:29:35 +00:00
|
|
|
err := unlockAccount(C.GoString(address), C.GoString(password))
|
|
|
|
out := fmt.Sprintf("{\"error\": %s}", err.Error())
|
|
|
|
if err != nil {
|
2016-06-21 18:29:38 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
}
|
2016-06-22 11:29:35 +00:00
|
|
|
return C.CString(out)
|
2016-06-21 18:29:38 +00:00
|
|
|
}
|
|
|
|
|
2016-06-22 11:29:35 +00:00
|
|
|
//export doStartNode
|
|
|
|
func doStartNode(datadir *C.char) *C.char {
|
2016-06-20 15:21:45 +00:00
|
|
|
// This starts a geth node with the given datadir
|
2016-06-22 11:29:35 +00:00
|
|
|
err := createAndStartNode(C.GoString(datadir))
|
|
|
|
out := fmt.Sprintf("{\"error\": %s}", err.Error())
|
|
|
|
if err != nil {
|
2016-06-20 15:21:45 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
}
|
2016-06-22 11:29:35 +00:00
|
|
|
return C.CString(out)
|
2016-06-20 15:21:45 +00:00
|
|
|
}
|