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 (
|
2016-06-22 18:56:27 +00:00
|
|
|
"encoding/json"
|
2016-06-15 13:54:07 +00:00
|
|
|
"fmt"
|
2016-06-15 19:50:35 +00:00
|
|
|
"os"
|
2016-06-15 13:54:07 +00:00
|
|
|
)
|
|
|
|
|
2016-06-30 13:43:51 +00:00
|
|
|
var emptyError = ""
|
|
|
|
|
2016-06-29 11:32:04 +00:00
|
|
|
//export CreateAccount
|
|
|
|
func CreateAccount(password, keydir *C.char) *C.char {
|
2016-06-30 13:23:07 +00:00
|
|
|
|
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-30 13:23:07 +00:00
|
|
|
|
2016-06-30 13:43:51 +00:00
|
|
|
errString := emptyError
|
2016-06-30 13:23:07 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
2016-06-22 18:56:27 +00:00
|
|
|
out := AccountInfo{
|
|
|
|
Address: address,
|
|
|
|
PubKey: pubKey,
|
2016-06-30 13:23:07 +00:00
|
|
|
Error: errString,
|
2016-06-15 13:54:07 +00:00
|
|
|
}
|
2016-06-22 18:56:27 +00:00
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
2016-06-30 13:23:07 +00:00
|
|
|
return C.CString(string(outBytes))
|
2016-06-15 13:54:07 +00:00
|
|
|
}
|
2016-06-20 15:21:45 +00:00
|
|
|
|
2016-06-29 11:32:04 +00:00
|
|
|
//export Login
|
|
|
|
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 {
|
2016-06-30 13:23:07 +00:00
|
|
|
|
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 18:56:27 +00:00
|
|
|
err := unlockAccount(C.GoString(address), C.GoString(password), seconds)
|
2016-06-30 13:23:07 +00:00
|
|
|
|
2016-06-30 13:43:51 +00:00
|
|
|
errString := emptyError
|
2016-06-22 11:29:35 +00:00
|
|
|
if err != nil {
|
2016-06-21 18:29:38 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2016-06-30 13:23:07 +00:00
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
out := JSONError{
|
|
|
|
Error: errString,
|
2016-06-21 18:29:38 +00:00
|
|
|
}
|
2016-06-22 18:56:27 +00:00
|
|
|
outBytes, _ := json.Marshal(&out)
|
2016-06-30 13:23:07 +00:00
|
|
|
|
2016-06-22 18:56:27 +00:00
|
|
|
return C.CString(string(outBytes))
|
2016-06-21 18:29:38 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 11:32:04 +00:00
|
|
|
//export StartNode
|
|
|
|
func StartNode(datadir *C.char) *C.char {
|
2016-06-30 13:23:07 +00:00
|
|
|
|
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))
|
2016-06-30 13:23:07 +00:00
|
|
|
|
2016-06-30 13:43:51 +00:00
|
|
|
errString := emptyError
|
2016-06-22 11:29:35 +00:00
|
|
|
if err != nil {
|
2016-06-20 15:21:45 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2016-06-30 13:23:07 +00:00
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
out := JSONError{
|
|
|
|
Error: errString,
|
2016-06-20 15:21:45 +00:00
|
|
|
}
|
2016-06-22 18:56:27 +00:00
|
|
|
outBytes, _ := json.Marshal(&out)
|
2016-06-30 13:23:07 +00:00
|
|
|
|
2016-06-22 18:56:27 +00:00
|
|
|
return C.CString(string(outBytes))
|
2016-06-20 15:21:45 +00:00
|
|
|
}
|