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-27 11:47:41 +00:00
|
|
|
"os"
|
2016-09-11 11:44:14 +00:00
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
"github.com/status-im/status-go/geth/common"
|
2017-03-15 21:03:01 +00:00
|
|
|
"github.com/status-im/status-go/geth/params"
|
2016-06-15 13:54:07 +00:00
|
|
|
)
|
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
//export GenerateConfig
|
|
|
|
func GenerateConfig(datadir *C.char, networkID C.int, devMode C.int) *C.char {
|
|
|
|
config, err := params.NewNodeConfig(C.GoString(datadir), uint64(networkID), devMode == 1)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
outBytes, err := json.Marshal(&config)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
|
|
|
}
|
|
|
|
|
|
|
|
//export StartNode
|
|
|
|
func StartNode(configJSON *C.char) *C.char {
|
|
|
|
config, err := params.LoadNodeConfig(C.GoString(configJSON))
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = statusAPI.StartNodeNonBlocking(config)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export StopNode
|
|
|
|
func StopNode() *C.char {
|
|
|
|
return makeJSONResponse(statusAPI.StopNode())
|
|
|
|
}
|
|
|
|
|
|
|
|
//export ResumeNode
|
|
|
|
func ResumeNode() *C.char {
|
|
|
|
err := fmt.Errorf("%v: %v", common.ErrDeprecatedMethod.Error(), "ResumeNode")
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export ResetChainData
|
|
|
|
func ResetChainData() *C.char {
|
|
|
|
return makeJSONResponse(statusAPI.ResetChainData())
|
|
|
|
}
|
|
|
|
|
|
|
|
//export StopNodeRPCServer
|
|
|
|
func StopNodeRPCServer() *C.char {
|
|
|
|
err := fmt.Errorf("%v: %v", common.ErrDeprecatedMethod.Error(), "StopNodeRPCServer")
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export StartNodeRPCServer
|
|
|
|
func StartNodeRPCServer() *C.char {
|
|
|
|
err := fmt.Errorf("%v: %v", common.ErrDeprecatedMethod.Error(), "StartNodeRPCServer")
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export PopulateStaticPeers
|
|
|
|
func PopulateStaticPeers() *C.char {
|
|
|
|
err := fmt.Errorf("%v: %v", common.ErrDeprecatedMethod.Error(), "PopulateStaticPeers")
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export AddPeer
|
|
|
|
func AddPeer(url *C.char) *C.char {
|
|
|
|
err := fmt.Errorf("%v: %v", common.ErrDeprecatedMethod.Error(), "AddPeer")
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
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-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
|
2017-05-16 12:09:52 +00:00
|
|
|
address, pubKey, mnemonic, err := statusAPI.CreateAccount(C.GoString(password))
|
2016-06-30 13:23:07 +00:00
|
|
|
|
2016-09-11 11:44:14 +00:00
|
|
|
errString := ""
|
2016-06-30 13:23:07 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
out := common.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))
|
|
|
|
}
|
|
|
|
|
2016-08-23 21:32:04 +00:00
|
|
|
//export CreateChildAccount
|
|
|
|
func CreateChildAccount(parentAddress, password *C.char) *C.char {
|
2017-05-16 12:09:52 +00:00
|
|
|
address, pubKey, err := statusAPI.CreateChildAccount(C.GoString(parentAddress), C.GoString(password))
|
2016-08-23 21:32:04 +00:00
|
|
|
|
2016-09-11 11:44:14 +00:00
|
|
|
errString := ""
|
2016-08-23 21:32:04 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
out := common.AccountInfo{
|
2016-08-23 21:32:04 +00:00
|
|
|
Address: address,
|
|
|
|
PubKey: pubKey,
|
|
|
|
Error: errString,
|
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
return C.CString(string(outBytes))
|
|
|
|
}
|
|
|
|
|
2016-08-24 15:10:42 +00:00
|
|
|
//export RecoverAccount
|
|
|
|
func RecoverAccount(password, mnemonic *C.char) *C.char {
|
2017-05-16 12:09:52 +00:00
|
|
|
address, pubKey, err := statusAPI.RecoverAccount(C.GoString(password), C.GoString(mnemonic))
|
2016-08-18 00:15:58 +00:00
|
|
|
|
2016-09-11 11:44:14 +00:00
|
|
|
errString := ""
|
2016-08-18 00:15:58 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
out := common.AccountInfo{
|
2016-08-18 00:15:58 +00:00
|
|
|
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
|
|
|
|
2017-05-06 21:53:18 +00:00
|
|
|
//export VerifyAccountPassword
|
2017-05-15 21:49:22 +00:00
|
|
|
func VerifyAccountPassword(keyStoreDir, address, password *C.char) *C.char {
|
2017-05-16 12:09:52 +00:00
|
|
|
_, err := statusAPI.VerifyAccountPassword(C.GoString(keyStoreDir), C.GoString(address), C.GoString(password))
|
|
|
|
return makeJSONResponse(err)
|
2017-05-06 21:53:18 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 11:32:04 +00:00
|
|
|
//export Login
|
|
|
|
func Login(address, password *C.char) *C.char {
|
2016-08-21 06:45:59 +00:00
|
|
|
// loads a key file (for a given address), tries to decrypt it using the password, to verify ownership
|
|
|
|
// if verified, purges all the previous identities from Whisper, and injects verified key as shh identity
|
2017-05-16 12:09:52 +00:00
|
|
|
err := statusAPI.SelectAccount(C.GoString(address), C.GoString(password))
|
|
|
|
return makeJSONResponse(err)
|
2016-06-29 11:32:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 00:31:16 +00:00
|
|
|
//export Logout
|
|
|
|
func Logout() *C.char {
|
|
|
|
// This is equivalent to clearing whisper identities
|
2017-05-16 12:09:52 +00:00
|
|
|
err := statusAPI.Logout()
|
|
|
|
return makeJSONResponse(err)
|
2016-08-29 00:31:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 11:47:41 +00:00
|
|
|
//export CompleteTransaction
|
2016-08-31 18:02:06 +00:00
|
|
|
func CompleteTransaction(id, password *C.char) *C.char {
|
2017-05-16 12:09:52 +00:00
|
|
|
txHash, err := statusAPI.CompleteTransaction(C.GoString(id), C.GoString(password))
|
2016-07-27 11:47:41 +00:00
|
|
|
|
2016-09-11 11:44:14 +00:00
|
|
|
errString := ""
|
2016-07-27 11:47:41 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
out := common.CompleteTransactionResult{
|
2017-05-03 14:24:48 +00:00
|
|
|
ID: C.GoString(id),
|
2016-08-09 16:41:42 +00:00
|
|
|
Hash: txHash.Hex(),
|
2016-07-27 11:47:41 +00:00
|
|
|
Error: errString,
|
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
|
|
|
}
|
|
|
|
|
2016-11-05 17:12:24 +00:00
|
|
|
//export CompleteTransactions
|
|
|
|
func CompleteTransactions(ids, password *C.char) *C.char {
|
2017-05-16 12:09:52 +00:00
|
|
|
out := common.CompleteTransactionsResult{}
|
|
|
|
out.Results = make(map[string]common.CompleteTransactionResult)
|
2016-11-05 17:12:24 +00:00
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
results := statusAPI.CompleteTransactions(C.GoString(ids), C.GoString(password))
|
2017-05-03 14:24:48 +00:00
|
|
|
for txID, result := range results {
|
2017-05-16 12:09:52 +00:00
|
|
|
txResult := common.CompleteTransactionResult{
|
2017-05-03 14:24:48 +00:00
|
|
|
ID: txID,
|
2016-11-05 17:12:24 +00:00
|
|
|
Hash: result.Hash.Hex(),
|
|
|
|
}
|
|
|
|
if result.Error != nil {
|
|
|
|
txResult.Error = result.Error.Error()
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
out.Results[txID] = txResult
|
2016-11-05 17:12:24 +00:00
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
|
|
|
}
|
|
|
|
|
2016-10-30 22:35:10 +00:00
|
|
|
//export DiscardTransaction
|
|
|
|
func DiscardTransaction(id *C.char) *C.char {
|
2017-05-16 12:09:52 +00:00
|
|
|
err := statusAPI.DiscardTransaction(C.GoString(id))
|
2016-10-30 22:35:10 +00:00
|
|
|
|
|
|
|
errString := ""
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
out := common.DiscardTransactionResult{
|
2017-05-03 14:24:48 +00:00
|
|
|
ID: C.GoString(id),
|
2016-10-30 22:35:10 +00:00
|
|
|
Error: errString,
|
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
|
|
|
}
|
|
|
|
|
2016-11-05 17:12:24 +00:00
|
|
|
//export DiscardTransactions
|
|
|
|
func DiscardTransactions(ids *C.char) *C.char {
|
2017-05-16 12:09:52 +00:00
|
|
|
out := common.DiscardTransactionsResult{}
|
|
|
|
out.Results = make(map[string]common.DiscardTransactionResult)
|
2016-11-05 17:12:24 +00:00
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
results := statusAPI.DiscardTransactions(C.GoString(ids))
|
2017-05-03 14:24:48 +00:00
|
|
|
for txID, result := range results {
|
2017-05-16 12:09:52 +00:00
|
|
|
txResult := common.DiscardTransactionResult{
|
2017-05-03 14:24:48 +00:00
|
|
|
ID: txID,
|
2016-11-05 17:12:24 +00:00
|
|
|
}
|
|
|
|
if result.Error != nil {
|
|
|
|
txResult.Error = result.Error.Error()
|
|
|
|
}
|
2017-05-03 14:24:48 +00:00
|
|
|
out.Results[txID] = txResult
|
2016-11-05 17:12:24 +00:00
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
|
|
|
}
|
|
|
|
|
2016-09-11 11:44:14 +00:00
|
|
|
//export InitJail
|
|
|
|
func InitJail(js *C.char) {
|
2017-05-16 12:09:52 +00:00
|
|
|
statusAPI.JailBaseJS(C.GoString(js))
|
2016-06-22 09:17:51 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 11:44:14 +00:00
|
|
|
//export Parse
|
2017-05-03 14:24:48 +00:00
|
|
|
func Parse(chatID *C.char, js *C.char) *C.char {
|
2017-05-16 12:09:52 +00:00
|
|
|
res := statusAPI.JailParse(C.GoString(chatID), C.GoString(js))
|
2016-06-22 09:17:51 +00:00
|
|
|
return C.CString(res)
|
|
|
|
}
|
|
|
|
|
2016-09-11 11:44:14 +00:00
|
|
|
//export Call
|
2017-05-03 14:24:48 +00:00
|
|
|
func Call(chatID *C.char, path *C.char, params *C.char) *C.char {
|
2017-05-16 12:09:52 +00:00
|
|
|
res := statusAPI.JailCall(C.GoString(chatID), C.GoString(path), C.GoString(params))
|
2016-09-11 11:44:14 +00:00
|
|
|
return C.CString(res)
|
2016-07-04 16:16:18 +00:00
|
|
|
}
|
2016-07-04 16:00:29 +00:00
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
func makeJSONResponse(err error) *C.char {
|
2016-12-11 12:19:20 +00:00
|
|
|
errString := ""
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:09:52 +00:00
|
|
|
out := common.APIResponse{
|
2016-12-11 12:19:20 +00:00
|
|
|
Error: errString,
|
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(&out)
|
|
|
|
|
|
|
|
return C.CString(string(outBytes))
|
|
|
|
}
|