status-go/src/library.go

57 lines
1.4 KiB
Go
Raw Normal View History

package main
import "C"
import (
"encoding/json"
"fmt"
"os"
)
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))
out := AccountInfo{
Address: address,
PubKey: pubKey,
Error: err.Error(),
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
}
2016-06-20 15:21:45 +00:00
2016-06-21 18:29:38 +00:00
//export doUnlockAccount
func doUnlockAccount(address, password *C.char, seconds int) *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
err := unlockAccount(C.GoString(address), C.GoString(password), seconds)
out := JSONError{
Error: err.Error(),
}
2016-06-22 11:29:35 +00:00
if err != nil {
2016-06-21 18:29:38 +00:00
fmt.Fprintln(os.Stderr, err)
}
outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
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 := JSONError{
Error: err.Error(),
}
2016-06-22 11:29:35 +00:00
if err != nil {
2016-06-20 15:21:45 +00:00
fmt.Fprintln(os.Stderr, err)
}
outBytes, _ := json.Marshal(&out)
return C.CString(string(outBytes))
2016-06-20 15:21:45 +00:00
}