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-07-12 18:10:37 +00:00
|
|
|
"github.com/ethereum/go-ethereum/whisper"
|
2016-07-27 11:47:41 +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
|
2016-07-01 13:23:39 +00:00
|
|
|
func CreateAccount(password *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-08-18 00:15:58 +00:00
|
|
|
address, pubKey, mnemonic, err := createAccount(C.GoString(password))
|
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{
|
2016-08-18 00:15:58 +00:00
|
|
|
Address: address,
|
|
|
|
PubKey: pubKey,
|
|
|
|
Mnemonic: mnemonic,
|
|
|
|
Error: errString,
|
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
|
|
|
}
|
|
|
|
|
|
|
|
//export RemindAccountDetails
|
|
|
|
func RemindAccountDetails(password, mnemonic *C.char) *C.char {
|
|
|
|
|
|
|
|
address, pubKey, err := remindAccountDetails(C.GoString(password), C.GoString(mnemonic))
|
|
|
|
|
|
|
|
errString := emptyError
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
out := AccountInfo{
|
|
|
|
Address: address,
|
|
|
|
PubKey: pubKey,
|
|
|
|
Mnemonic: C.GoString(mnemonic),
|
|
|
|
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
|
2016-07-04 16:00:29 +00:00
|
|
|
out := UnlockAccount(address, password, 1)
|
2016-06-29 11:32:04 +00:00
|
|
|
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-07-27 11:47:41 +00:00
|
|
|
//export CompleteTransaction
|
|
|
|
func CompleteTransaction(hash *C.char) *C.char {
|
2016-08-09 16:41:42 +00:00
|
|
|
txHash, err := completeTransaction(C.GoString(hash))
|
2016-07-27 11:47:41 +00:00
|
|
|
|
|
|
|
errString := emptyError
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
2016-08-09 16:41:42 +00:00
|
|
|
out := CompleteTransactionResult{
|
|
|
|
Hash: txHash.Hex(),
|
2016-07-27 11:47:41 +00:00
|
|
|
Error: errString,
|
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2016-06-22 09:17:51 +00:00
|
|
|
|
|
|
|
//export parse
|
|
|
|
func parse(chatId *C.char, js *C.char) *C.char {
|
|
|
|
res := Parse(C.GoString(chatId), C.GoString(js))
|
|
|
|
return C.CString(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export call
|
|
|
|
func call(chatId *C.char, path *C.char, params *C.char) *C.char {
|
|
|
|
res := Call(C.GoString(chatId), C.GoString(path), C.GoString(params))
|
|
|
|
return C.CString(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export initJail
|
|
|
|
func initJail(js *C.char) {
|
|
|
|
Init(C.GoString(js))
|
2016-07-04 16:16:18 +00:00
|
|
|
}
|
2016-07-04 16:00:29 +00:00
|
|
|
|
|
|
|
//export addPeer
|
|
|
|
func addPeer(url *C.char) *C.char {
|
|
|
|
success, err := doAddPeer(C.GoString(url))
|
|
|
|
errString := emptyError
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
out := AddPeerResult{
|
|
|
|
Success: success,
|
|
|
|
Error: errString,
|
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
2016-06-22 09:17:51 +00:00
|
|
|
}
|
2016-07-12 18:10:37 +00:00
|
|
|
|
|
|
|
//export addWhisperFilter
|
|
|
|
func addWhisperFilter(filterJson *C.char) *C.char {
|
|
|
|
|
2016-07-27 11:47:41 +00:00
|
|
|
var id int
|
|
|
|
var filter whisper.NewFilterArgs
|
2016-07-12 18:10:37 +00:00
|
|
|
|
2016-07-27 11:47:41 +00:00
|
|
|
err := json.Unmarshal([]byte(C.GoString(filterJson)), &filter)
|
|
|
|
if err == nil {
|
2016-07-12 18:10:37 +00:00
|
|
|
id = doAddWhisperFilter(filter)
|
|
|
|
}
|
|
|
|
|
|
|
|
errString := emptyError
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
out := AddWhisperFilterResult{
|
2016-07-27 11:47:41 +00:00
|
|
|
Id: id,
|
2016-07-12 18:10:37 +00:00
|
|
|
Error: errString,
|
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
2016-07-27 11:47:41 +00:00
|
|
|
|
2016-07-12 18:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//export removeWhisperFilter
|
|
|
|
func removeWhisperFilter(idFilter int) {
|
|
|
|
|
|
|
|
doRemoveWhisperFilter(idFilter)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export clearWhisperFilters
|
|
|
|
func clearWhisperFilters() {
|
|
|
|
|
2016-07-27 11:47:41 +00:00
|
|
|
doClearWhisperFilters()
|
|
|
|
}
|