chore: verify signalCallback can be used with a pointer to a function
This commit is contained in:
parent
18f9715995
commit
93f3c08e19
|
@ -8,4 +8,7 @@ nimcache
|
|||
.DS_Store
|
||||
TODO
|
||||
nim_status
|
||||
test/test
|
||||
test/test
|
||||
data/
|
||||
keystore/
|
||||
noBackup/
|
23
Makefile
23
Makefile
|
@ -109,21 +109,32 @@ $(STATUSGO): | deps
|
|||
+ cd vendor/status-go && \
|
||||
$(MAKE) statusgo-library $(HANDLE_OUTPUT)
|
||||
|
||||
clean: | clean-common
|
||||
rm -rf build/*
|
||||
clean: | clean-common clean-build-dir
|
||||
rm -rf $(STATUSGO)
|
||||
rm keystore
|
||||
rm data
|
||||
rm noBackup
|
||||
|
||||
clean-build-dir:
|
||||
rm -rf build/*
|
||||
|
||||
NIMSTATUS := build/nim_status.a
|
||||
|
||||
$(NIMSTATUS): | build $(STATUSGO) deps
|
||||
$(NIMSTATUS): | build deps
|
||||
echo -e $(BUILD_MSG) "$@" && \
|
||||
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --app:staticLib --header --noMain --nimcache:nimcache/nim_status --passL:$(STATUSGO) -o:$@ src/nim_status.nim
|
||||
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --app:staticLib --header --noMain --nimcache:nimcache/nim_status -o:$@ src/nim_status.nim
|
||||
cp nimcache/nim_status/nim_status.h build/.
|
||||
mv nim_status.a build/.
|
||||
|
||||
nim_status: $(NIMSTATUS)
|
||||
nim_status: | clean-build-dir $(NIMSTATUS)
|
||||
|
||||
tests: | $(NIMSTATUS)
|
||||
tests: | $(NIMSTATUS) $(STATUSGO)
|
||||
rm -Rf keystore
|
||||
rm -Rf data
|
||||
rm -Rf noBackup
|
||||
mkdir -p data
|
||||
mkdir -p noBackup
|
||||
mkdir -p keystore
|
||||
echo "Compiling 'test/test'"
|
||||
ifeq ($(detected_OS), Darwin)
|
||||
$(CC) -I"$(CURDIR)/build" -I"$(CURDIR)/vendor/nimbus-build-system/vendor/Nim/lib" test/test.c $(NIMSTATUS) $(STATUSGO) -framework CoreFoundation -framework CoreServices -framework IOKit -framework Security -lm -pthread -o test/test
|
||||
|
|
|
@ -6,7 +6,7 @@ description = "Nim implementation of the Status protocol"
|
|||
license = "MIT"
|
||||
srcDir = "src"
|
||||
bin = @[""]
|
||||
skipExt = @["nim"]
|
||||
skipDirs = @["test"]
|
||||
|
||||
# Deps
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ proc addPeer*(peer: cstring): cstring {.exportc.} =
|
|||
result = status_go.AddPeer(peer)
|
||||
|
||||
proc setSignalEventCallback*(callback: SignalCallback) {.exportc.} =
|
||||
# TODO: test callbacks
|
||||
status_go.SetSignalEventCallback(callback)
|
||||
|
||||
proc sendTransaction*(jsonArgs: cstring, password: cstring): cstring {.exportc.} =
|
||||
|
|
|
@ -3,4 +3,4 @@ type
|
|||
str*: cstring
|
||||
length*: cint
|
||||
|
||||
type SignalCallback* = proc(eventMessage: cstring): void {.cdecl.}
|
||||
type SignalCallback* {.exportc:"SignalCallback"} = proc(eventMessage: cstring): void {.cdecl.}
|
||||
|
|
|
@ -0,0 +1,387 @@
|
|||
/*
|
||||
* Copyright (c) 2013 Yaroslav Stavnichiy <yarosla@gmail.com>
|
||||
*
|
||||
* This file is part of NXJSON.
|
||||
*
|
||||
* NXJSON is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* NXJSON is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with NXJSON. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// this file can be #included in your code
|
||||
#ifndef NXJSON_C
|
||||
#define NXJSON_C
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nxjson.h"
|
||||
|
||||
// redefine NX_JSON_CALLOC & NX_JSON_FREE to use custom allocator
|
||||
#ifndef NX_JSON_CALLOC
|
||||
#define NX_JSON_CALLOC() calloc(1, sizeof(nx_json))
|
||||
#define NX_JSON_FREE(json) free((void*)(json))
|
||||
#endif
|
||||
|
||||
// redefine NX_JSON_REPORT_ERROR to use custom error reporting
|
||||
#ifndef NX_JSON_REPORT_ERROR
|
||||
#define NX_JSON_REPORT_ERROR(msg, p) fprintf(stderr, "NXJSON PARSE ERROR (%d): " msg " at %s\n", __LINE__, p)
|
||||
#endif
|
||||
|
||||
#define IS_WHITESPACE(c) ((unsigned char)(c)<=(unsigned char)' ')
|
||||
|
||||
static const nx_json dummy={ NX_JSON_NULL };
|
||||
|
||||
static nx_json* create_json(nx_json_type type, const char* key, nx_json* parent) {
|
||||
nx_json* js=NX_JSON_CALLOC();
|
||||
assert(js);
|
||||
js->type=type;
|
||||
js->key=key;
|
||||
if (!parent->last_child) {
|
||||
parent->child=parent->last_child=js;
|
||||
}
|
||||
else {
|
||||
parent->last_child->next=js;
|
||||
parent->last_child=js;
|
||||
}
|
||||
parent->length++;
|
||||
return js;
|
||||
}
|
||||
|
||||
void nx_json_free(const nx_json* js) {
|
||||
nx_json* p=js->child;
|
||||
nx_json* p1;
|
||||
while (p) {
|
||||
p1=p->next;
|
||||
nx_json_free(p);
|
||||
p=p1;
|
||||
}
|
||||
NX_JSON_FREE(js);
|
||||
}
|
||||
|
||||
static int unicode_to_utf8(unsigned int codepoint, char* p, char** endp) {
|
||||
// code from http://stackoverflow.com/a/4609989/697313
|
||||
if (codepoint<0x80) *p++=codepoint;
|
||||
else if (codepoint<0x800) *p++=192+codepoint/64, *p++=128+codepoint%64;
|
||||
else if (codepoint-0xd800u<0x800) return 0; // surrogate must have been treated earlier
|
||||
else if (codepoint<0x10000) *p++=224+codepoint/4096, *p++=128+codepoint/64%64, *p++=128+codepoint%64;
|
||||
else if (codepoint<0x110000) *p++=240+codepoint/262144, *p++=128+codepoint/4096%64, *p++=128+codepoint/64%64, *p++=128+codepoint%64;
|
||||
else return 0; // error
|
||||
*endp=p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
nx_json_unicode_encoder nx_json_unicode_to_utf8=unicode_to_utf8;
|
||||
|
||||
static inline int hex_val(char c) {
|
||||
if (c>='0' && c<='9') return c-'0';
|
||||
if (c>='a' && c<='f') return c-'a'+10;
|
||||
if (c>='A' && c<='F') return c-'A'+10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static char* unescape_string(char* s, char** end, nx_json_unicode_encoder encoder) {
|
||||
char* p=s;
|
||||
char* d=s;
|
||||
char c;
|
||||
while ((c=*p++)) {
|
||||
if (c=='"') {
|
||||
*d='\0';
|
||||
*end=p;
|
||||
return s;
|
||||
}
|
||||
else if (c=='\\') {
|
||||
switch (*p) {
|
||||
case '\\':
|
||||
case '/':
|
||||
case '"':
|
||||
*d++=*p++;
|
||||
break;
|
||||
case 'b':
|
||||
*d++='\b'; p++;
|
||||
break;
|
||||
case 'f':
|
||||
*d++='\f'; p++;
|
||||
break;
|
||||
case 'n':
|
||||
*d++='\n'; p++;
|
||||
break;
|
||||
case 'r':
|
||||
*d++='\r'; p++;
|
||||
break;
|
||||
case 't':
|
||||
*d++='\t'; p++;
|
||||
break;
|
||||
case 'u': // unicode
|
||||
if (!encoder) {
|
||||
// leave untouched
|
||||
*d++=c;
|
||||
break;
|
||||
}
|
||||
char* ps=p-1;
|
||||
int h1, h2, h3, h4;
|
||||
if ((h1=hex_val(p[1]))<0 || (h2=hex_val(p[2]))<0 || (h3=hex_val(p[3]))<0 || (h4=hex_val(p[4]))<0) {
|
||||
NX_JSON_REPORT_ERROR("invalid unicode escape", p-1);
|
||||
return 0;
|
||||
}
|
||||
unsigned int codepoint=h1<<12|h2<<8|h3<<4|h4;
|
||||
if ((codepoint & 0xfc00)==0xd800) { // high surrogate; need one more unicode to succeed
|
||||
p+=6;
|
||||
if (p[-1]!='\\' || *p!='u' || (h1=hex_val(p[1]))<0 || (h2=hex_val(p[2]))<0 || (h3=hex_val(p[3]))<0 || (h4=hex_val(p[4]))<0) {
|
||||
NX_JSON_REPORT_ERROR("invalid unicode surrogate", ps);
|
||||
return 0;
|
||||
}
|
||||
unsigned int codepoint2=h1<<12|h2<<8|h3<<4|h4;
|
||||
if ((codepoint2 & 0xfc00)!=0xdc00) {
|
||||
NX_JSON_REPORT_ERROR("invalid unicode surrogate", ps);
|
||||
return 0;
|
||||
}
|
||||
codepoint=0x10000+((codepoint-0xd800)<<10)+(codepoint2-0xdc00);
|
||||
}
|
||||
if (!encoder(codepoint, d, &d)) {
|
||||
NX_JSON_REPORT_ERROR("invalid codepoint", ps);
|
||||
return 0;
|
||||
}
|
||||
p+=5;
|
||||
break;
|
||||
default:
|
||||
// leave untouched
|
||||
*d++=c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*d++=c;
|
||||
}
|
||||
}
|
||||
NX_JSON_REPORT_ERROR("no closing quote for string", s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char* skip_block_comment(char* p) {
|
||||
// assume p[-2]=='/' && p[-1]=='*'
|
||||
char* ps=p-2;
|
||||
if (!*p) {
|
||||
NX_JSON_REPORT_ERROR("endless comment", ps);
|
||||
return 0;
|
||||
}
|
||||
REPEAT:
|
||||
p=strchr(p+1, '/');
|
||||
if (!p) {
|
||||
NX_JSON_REPORT_ERROR("endless comment", ps);
|
||||
return 0;
|
||||
}
|
||||
if (p[-1]!='*') goto REPEAT;
|
||||
return p+1;
|
||||
}
|
||||
|
||||
static char* parse_key(const char** key, char* p, nx_json_unicode_encoder encoder) {
|
||||
// on '}' return with *p=='}'
|
||||
char c;
|
||||
while ((c=*p++)) {
|
||||
if (c=='"') {
|
||||
*key=unescape_string(p, &p, encoder);
|
||||
if (!*key) return 0; // propagate error
|
||||
while (*p && IS_WHITESPACE(*p)) p++;
|
||||
if (*p==':') return p+1;
|
||||
NX_JSON_REPORT_ERROR("unexpected chars", p);
|
||||
return 0;
|
||||
}
|
||||
else if (IS_WHITESPACE(c) || c==',') {
|
||||
// continue
|
||||
}
|
||||
else if (c=='}') {
|
||||
return p-1;
|
||||
}
|
||||
else if (c=='/') {
|
||||
if (*p=='/') { // line comment
|
||||
char* ps=p-1;
|
||||
p=strchr(p+1, '\n');
|
||||
if (!p) {
|
||||
NX_JSON_REPORT_ERROR("endless comment", ps);
|
||||
return 0; // error
|
||||
}
|
||||
p++;
|
||||
}
|
||||
else if (*p=='*') { // block comment
|
||||
p=skip_block_comment(p+1);
|
||||
if (!p) return 0;
|
||||
}
|
||||
else {
|
||||
NX_JSON_REPORT_ERROR("unexpected chars", p-1);
|
||||
return 0; // error
|
||||
}
|
||||
}
|
||||
else {
|
||||
NX_JSON_REPORT_ERROR("unexpected chars", p-1);
|
||||
return 0; // error
|
||||
}
|
||||
}
|
||||
NX_JSON_REPORT_ERROR("unexpected chars", p-1);
|
||||
return 0; // error
|
||||
}
|
||||
|
||||
static char* parse_value(nx_json* parent, const char* key, char* p, nx_json_unicode_encoder encoder) {
|
||||
nx_json* js;
|
||||
while (1) {
|
||||
switch (*p) {
|
||||
case '\0':
|
||||
NX_JSON_REPORT_ERROR("unexpected end of text", p);
|
||||
return 0; // error
|
||||
case ' ': case '\t': case '\n': case '\r':
|
||||
case ',':
|
||||
// skip
|
||||
p++;
|
||||
break;
|
||||
case '{':
|
||||
js=create_json(NX_JSON_OBJECT, key, parent);
|
||||
p++;
|
||||
while (1) {
|
||||
const char* new_key;
|
||||
p=parse_key(&new_key, p, encoder);
|
||||
if (!p) return 0; // error
|
||||
if (*p=='}') return p+1; // end of object
|
||||
p=parse_value(js, new_key, p, encoder);
|
||||
if (!p) return 0; // error
|
||||
}
|
||||
case '[':
|
||||
js=create_json(NX_JSON_ARRAY, key, parent);
|
||||
p++;
|
||||
while (1) {
|
||||
p=parse_value(js, 0, p, encoder);
|
||||
if (!p) return 0; // error
|
||||
if (*p==']') return p+1; // end of array
|
||||
}
|
||||
case ']':
|
||||
return p;
|
||||
case '"':
|
||||
p++;
|
||||
js=create_json(NX_JSON_STRING, key, parent);
|
||||
js->text_value=unescape_string(p, &p, encoder);
|
||||
if (!js->text_value) return 0; // propagate error
|
||||
return p;
|
||||
case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
|
||||
{
|
||||
js=create_json(NX_JSON_INTEGER, key, parent);
|
||||
char* pe;
|
||||
js->int_value=strtoll(p, &pe, 0);
|
||||
if (pe==p || errno==ERANGE) {
|
||||
NX_JSON_REPORT_ERROR("invalid number", p);
|
||||
return 0; // error
|
||||
}
|
||||
if (*pe=='.' || *pe=='e' || *pe=='E') { // double value
|
||||
js->type=NX_JSON_DOUBLE;
|
||||
js->dbl_value=strtod(p, &pe);
|
||||
if (pe==p || errno==ERANGE) {
|
||||
NX_JSON_REPORT_ERROR("invalid number", p);
|
||||
return 0; // error
|
||||
}
|
||||
}
|
||||
else {
|
||||
js->dbl_value=js->int_value;
|
||||
}
|
||||
return pe;
|
||||
}
|
||||
case 't':
|
||||
if (!strncmp(p, "true", 4)) {
|
||||
js=create_json(NX_JSON_BOOL, key, parent);
|
||||
js->int_value=1;
|
||||
return p+4;
|
||||
}
|
||||
NX_JSON_REPORT_ERROR("unexpected chars", p);
|
||||
return 0; // error
|
||||
case 'f':
|
||||
if (!strncmp(p, "false", 5)) {
|
||||
js=create_json(NX_JSON_BOOL, key, parent);
|
||||
js->int_value=0;
|
||||
return p+5;
|
||||
}
|
||||
NX_JSON_REPORT_ERROR("unexpected chars", p);
|
||||
return 0; // error
|
||||
case 'n':
|
||||
if (!strncmp(p, "null", 4)) {
|
||||
create_json(NX_JSON_NULL, key, parent);
|
||||
return p+4;
|
||||
}
|
||||
NX_JSON_REPORT_ERROR("unexpected chars", p);
|
||||
return 0; // error
|
||||
case '/': // comment
|
||||
if (p[1]=='/') { // line comment
|
||||
char* ps=p;
|
||||
p=strchr(p+2, '\n');
|
||||
if (!p) {
|
||||
NX_JSON_REPORT_ERROR("endless comment", ps);
|
||||
return 0; // error
|
||||
}
|
||||
p++;
|
||||
}
|
||||
else if (p[1]=='*') { // block comment
|
||||
p=skip_block_comment(p+2);
|
||||
if (!p) return 0;
|
||||
}
|
||||
else {
|
||||
NX_JSON_REPORT_ERROR("unexpected chars", p);
|
||||
return 0; // error
|
||||
}
|
||||
break;
|
||||
default:
|
||||
NX_JSON_REPORT_ERROR("unexpected chars", p);
|
||||
return 0; // error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const nx_json* nx_json_parse_utf8(char* text) {
|
||||
return nx_json_parse(text, unicode_to_utf8);
|
||||
}
|
||||
|
||||
const nx_json* nx_json_parse(char* text, nx_json_unicode_encoder encoder) {
|
||||
nx_json js={0};
|
||||
if (!parse_value(&js, 0, text, encoder)) {
|
||||
if (js.child) nx_json_free(js.child);
|
||||
return 0;
|
||||
}
|
||||
return js.child;
|
||||
}
|
||||
|
||||
const nx_json* nx_json_get(const nx_json* json, const char* key) {
|
||||
if (!json || !key) return &dummy; // never return null
|
||||
nx_json* js;
|
||||
for (js=json->child; js; js=js->next) {
|
||||
if (js->key && !strcmp(js->key, key)) return js;
|
||||
}
|
||||
return &dummy; // never return null
|
||||
}
|
||||
|
||||
const nx_json* nx_json_item(const nx_json* json, int idx) {
|
||||
if (!json) return &dummy; // never return null
|
||||
nx_json* js;
|
||||
for (js=json->child; js; js=js->next) {
|
||||
if (!idx--) return js;
|
||||
}
|
||||
return &dummy; // never return null
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NXJSON_C */
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2013 Yaroslav Stavnichiy <yarosla@gmail.com>
|
||||
*
|
||||
* This file is part of NXJSON.
|
||||
*
|
||||
* NXJSON is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* NXJSON is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with NXJSON. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NXJSON_H
|
||||
#define NXJSON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum nx_json_type {
|
||||
NX_JSON_NULL, // this is null value
|
||||
NX_JSON_OBJECT, // this is an object; properties can be found in child nodes
|
||||
NX_JSON_ARRAY, // this is an array; items can be found in child nodes
|
||||
NX_JSON_STRING, // this is a string; value can be found in text_value field
|
||||
NX_JSON_INTEGER, // this is an integer; value can be found in int_value field
|
||||
NX_JSON_DOUBLE, // this is a double; value can be found in dbl_value field
|
||||
NX_JSON_BOOL // this is a boolean; value can be found in int_value field
|
||||
} nx_json_type;
|
||||
|
||||
typedef struct nx_json {
|
||||
nx_json_type type; // type of json node, see above
|
||||
const char* key; // key of the property; for object's children only
|
||||
const char* text_value; // text value of STRING node
|
||||
long long int_value; // the value of INTEGER or BOOL node
|
||||
double dbl_value; // the value of DOUBLE node
|
||||
int length; // number of children of OBJECT or ARRAY
|
||||
struct nx_json* child; // points to first child
|
||||
struct nx_json* next; // points to next child
|
||||
struct nx_json* last_child;
|
||||
} nx_json;
|
||||
|
||||
typedef int (*nx_json_unicode_encoder)(unsigned int codepoint, char* p, char** endp);
|
||||
|
||||
extern nx_json_unicode_encoder nx_json_unicode_to_utf8;
|
||||
|
||||
const nx_json* nx_json_parse(char* text, nx_json_unicode_encoder encoder);
|
||||
const nx_json* nx_json_parse_utf8(char* text);
|
||||
void nx_json_free(const nx_json* js);
|
||||
const nx_json* nx_json_get(const nx_json* json, const char* key); // get object's property by key
|
||||
const nx_json* nx_json_item(const nx_json* json, int idx); // get array element by index
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NXJSON_H */
|
79
test/test.c
79
test/test.c
|
@ -1,20 +1,91 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nim_status.h"
|
||||
#include "nxjson.c"
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
void eventCallback(const char *event) {
|
||||
printf("SIGNAL RECEIVED:\n%s\n", event);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
NimMain();
|
||||
const char* theMessage = hashMessage("Hello World!");
|
||||
printf("%s\n", theMessage);
|
||||
|
||||
printf("HashMessage: %s\n\n", theMessage);
|
||||
char* pubKey = "0x0441ccda1563d69ac6b2e53718973c4e7280b4a5d8b3a09bb8bce9ebc5f082778243f1a04ec1f7995660482ca4b966ab0044566141ca48d7cdef8b7375cd5b7af5";
|
||||
struct GoString p1 = {pubKey, strlen(pubKey)};
|
||||
const char* theIdenticon = identicon(p1);
|
||||
printf("%s\n", theIdenticon);
|
||||
printf("Identicon: %s\n\n", theIdenticon);
|
||||
|
||||
|
||||
// TODO: test signals
|
||||
printf("Creating an account, login and receive signals:\n");
|
||||
|
||||
char* initKeystoreResult = initKeystore("./data");
|
||||
printf("1. InitKeystore:\n%s\n\n", initKeystoreResult);
|
||||
|
||||
char* openAccountsResults = openAccounts("./noBackup");
|
||||
printf("2. OpenAccounts:\n%s\n\n", openAccountsResults);
|
||||
|
||||
char* multiAccountGenerateAndDeriveAddressesResult = multiAccountGenerateAndDeriveAddresses("{\"n\":5,\"mnemonicPhraseLength\":12,\"bip39Passphrase\":\"\",\"paths\":[\"m/43'/60'/1581'/0'/0\",\"m/44'/60'/0'/0/0\"]}");
|
||||
printf("3. MultiAccountGenerateAndDeriveAddresses:\n%s\n\n", multiAccountGenerateAndDeriveAddressesResult);
|
||||
|
||||
const nx_json* MultiAccountGenerateAndDeriveAddresses = nx_json_parse(multiAccountGenerateAndDeriveAddressesResult, 0);
|
||||
char* accountID = nx_json_get(nx_json_item(MultiAccountGenerateAndDeriveAddresses, 0), "id")->text_value;
|
||||
|
||||
char p2[300];
|
||||
char* password = "0x2cd9bf92c5e20b1b410f5ace94d963a96e89156fbe65b70365e8596b37f1f165"; // qwerty
|
||||
sprintf(p2, "{\"accountID\": \"%s\", \"paths\": [\"m/44'/60'/0'/0\", \"m/43'/60'/1581'\", \"m/43'/60'/1581'/0'/0\", \"m/44'/60'/0'/0/0\"], \"password\": \"%s\"}", accountID, password);
|
||||
char* multiAccountStoreDerivedAccountsResult = multiAccountStoreDerivedAccounts(p2);
|
||||
printf("4. MultiAccountStoreDerivedAccounts:\n%s\n\n", multiAccountStoreDerivedAccountsResult);
|
||||
|
||||
const nx_json* MultiAccountStoreDerivedAccounts = nx_json_parse(multiAccountStoreDerivedAccountsResult, 0);
|
||||
|
||||
char* m4460publicKey = nx_json_get(nx_json_get(MultiAccountStoreDerivedAccounts, "m/44'/60'/0'/0/0"), "publicKey")->text_value;
|
||||
char* m4460address = nx_json_get(nx_json_get(MultiAccountStoreDerivedAccounts, "m/44'/60'/0'/0/0"), "address")->text_value;
|
||||
char* m4360publicKey = nx_json_get(nx_json_get(MultiAccountStoreDerivedAccounts, "m/43'/60'/1581'/0'/0"), "publicKey")->text_value;
|
||||
char* m4360address = nx_json_get(nx_json_get(MultiAccountStoreDerivedAccounts, "m/43'/60'/1581'/0'/0"), "address")->text_value;
|
||||
|
||||
|
||||
char accountsData[2000];
|
||||
sprintf(accountsData, "[{\"public-key\":\"%s\",\"address\":\"%s\",\"color\":\"#4360df\",\"wallet\":true,\"path\":\"m/44'/60'/0'/0/0\",\"name\":\"Status account\"},{\"public-key\":\"%s\",\"address\":\"%s\",\"name\":\"Delectable Overjoyed Nauplius\",\"photo-path\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAmElEQVR4nOzX4QmAIBBA4Yp2aY52aox2ao6mqf+SoajwON73M0J4HBy6TEEYQmMIjSE0htCECVlbDziv+/n6fuzb3OP/UmEmYgiNITRNm+LPqO2UE2YihtAYQlN818ptoZzau1btOakwEzGExhCa5hdi7d2p1zZLhZmIITSG0PhCpDGExhANEmYihtAYQmMIjSE0bwAAAP//kHQdRIWYzToAAAAASUVORK5CYII=\",\"path\":\"m/43'/60'/1581'/0'/0\",\"chat\":true}]",
|
||||
m4460publicKey, m4460address, m4360publicKey, m4360address);
|
||||
|
||||
char* finalConfig = "{\"BrowsersConfig\":{\"Enabled\":true},\"ClusterConfig\":{\"BootNodes\":[\"enode://23d0740b11919358625d79d4cac7d50a34d79e9c69e16831c5c70573757a1f5d7d884510bc595d7ee4da3c1508adf87bbc9e9260d804ef03f8c1e37f2fb2fc69@47.52.106.107:443\",\"enode://5395aab7833f1ecb671b59bf0521cf20224fe8162fc3d2675de4ee4d5636a75ec32d13268fc184df8d1ddfa803943906882da62a4df42d4fccf6d17808156a87@178.128.140.188:443\",\"enode://6e6554fb3034b211398fcd0f0082cbb6bd13619e1a7e76ba66e1809aaa0c5f1ac53c9ae79cf2fd4a7bacb10d12010899b370c75fed19b991d9c0cdd02891abad@47.75.99.169:443\",\"enode://5405c509df683c962e7c9470b251bb679dd6978f82d5b469f1f6c64d11d50fbd5dd9f7801c6ad51f3b20a5f6c7ffe248cc9ab223f8bcbaeaf14bb1c0ef295fd0@35.223.215.156:443\"],\"Enabled\":true,\"Fleet\":\"eth.prod\",\"RendezvousNodes\":[\"/ip4/34.70.75.208/tcp/30703/ethv4/16Uiu2HAm6ZsERLx2BwVD2UM9SVPnnMU6NBycG8XPtu8qKys5awsU\",\"/ip4/178.128.140.188/tcp/30703/ethv4/16Uiu2HAmLqTXuY4Sb6G28HNooaFUXUKzpzKXCcgyJxgaEE2i5vnf\",\"/ip4/47.52.106.107/tcp/30703/ethv4/16Uiu2HAmEHiptiDDd9gqNY8oQqo8hHUWMHJzfwt5aLRdD6W2zcXR\"],\"StaticNodes\":[\"enode://887cbd92d95afc2c5f1e227356314a53d3d18855880ac0509e0c0870362aee03939d4074e6ad31365915af41d34320b5094bfcc12a67c381788cd7298d06c875@178.128.141.0:443\",\"enode://fbeddac99d396b91d59f2c63a3cb5fc7e0f8a9f7ce6fe5f2eed5e787a0154161b7173a6a73124a4275ef338b8966dc70a611e9ae2192f0f2340395661fad81c0@34.67.230.193:443\"],\"TrustedMailServers\":[\"enode://2c8de3cbb27a3d30cbb5b3e003bc722b126f5aef82e2052aaef032ca94e0c7ad219e533ba88c70585ebd802de206693255335b100307645ab5170e88620d2a81@47.244.221.14:443\",\"enode://ee2b53b0ace9692167a410514bca3024695dbf0e1a68e1dff9716da620efb195f04a4b9e873fb9b74ac84de801106c465b8e2b6c4f0d93b8749d1578bfcaf03e@104.197.238.144:443\",\"enode://8a64b3c349a2e0ef4a32ea49609ed6eb3364be1110253c20adc17a3cebbc39a219e5d3e13b151c0eee5d8e0f9a8ba2cd026014e67b41a4ab7d1d5dd67ca27427@178.128.142.94:443\",\"enode://7aa648d6e855950b2e3d3bf220c496e0cae4adfddef3e1e6062e6b177aec93bc6cdcf1282cb40d1656932ebfdd565729da440368d7c4da7dbd4d004b1ac02bf8@178.128.142.26:443\",\"enode://c42f368a23fa98ee546fd247220759062323249ef657d26d357a777443aec04db1b29a3a22ef3e7c548e18493ddaf51a31b0aed6079bd6ebe5ae838fcfaf3a49@178.128.142.54:443\",\"enode://30211cbd81c25f07b03a0196d56e6ce4604bb13db773ff1c0ea2253547fafd6c06eae6ad3533e2ba39d59564cfbdbb5e2ce7c137a5ebb85e99dcfc7a75f99f55@23.236.58.92:443\"]},\"DataDir\":\"./data\",\"EnableNTPSync\":true,\"KeyStoreDir\":\"./keystore\",\"ListenAddr\":\":30304\",\"LogEnabled\":true,\"LogFile\":\"./geth.log\",\"LogLevel\":\"INFO\",\"MailserversConfig\":{\"Enabled\":true},\"Name\":\"StatusIM\",\"NetworkId\":1,\"NoDiscovery\":false,\"PermissionsConfig\":{\"Enabled\":true},\"Rendezvous\":true,\"RequireTopics\":{\"whisper\":{\"Max\":2,\"Min\":2}},\"ShhExtConfig\":{\"BackupDisabledDataDir\":\"./\",\"DataSyncEnabled\":true,\"InstallationID\":\"aef27732-8d86-5039-a32e-bdbe094d8791\",\"MailServerConfirmations\":true,\"MaxMessageDeliveryAttempts\":6,\"PFSEnabled\":true,\"VerifyENSContractAddress\":\"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e\",\"VerifyENSURL\":\"https://mainnet.infura.io/v3/f315575765b14720b32382a61a89341a\",\"VerifyTransactionChainID\":1,\"VerifyTransactionURL\":\"https://mainnet.infura.io/v3/f315575765b14720b32382a61a89341a\"},\"ShhextConfig\":{\"BackupDisabledDataDir\":null,\"DataSyncEnabled\":true,\"InstallationID\":\"aef27732-8d86-5039-a32e-bdbe094d8791\",\"MailServerConfirmations\":true,\"MaxMessageDeliveryAttempts\":6,\"PFSEnabled\":true,\"VerifyENSContractAddress\":\"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e\",\"VerifyENSURL\":\"https://mainnet.infura.io/v3/f315575765b14720b32382a61a89341a\",\"VerifyTransactionChainID\":1,\"VerifyTransactionURL\":\"https://mainnet.infura.io/v3/f315575765b14720b32382a61a89341a\"},\"StatusAccountsConfig\":{\"Enabled\":true},\"UpstreamConfig\":{\"Enabled\":true,\"URL\":\"https://mainnet.infura.io/v3/f315575765b14720b32382a61a89341a\"},\"WakuConfig\":{\"BloomFilterMode\":null,\"Enabled\":true,\"LightClient\":true,\"MinimumPoW\":0.001},\"WalletConfig\":{\"Enabled\":true}}";
|
||||
|
||||
char* multiAccountGenerateAndDeriveAddresses0address = nx_json_get(nx_json_item(MultiAccountGenerateAndDeriveAddresses, 0), "address")->text_value;
|
||||
char* multiAccountGenerateAndDeriveAddresses0keyUid = nx_json_get(nx_json_item(MultiAccountGenerateAndDeriveAddresses, 0), "keyUid")->text_value;
|
||||
|
||||
char multiAccountData[2000];
|
||||
sprintf(multiAccountData, "{\"name\":\"Delectable Overjoyed Nauplius\",\"address\":\"%s\",\"photo-path\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAmElEQVR4nOzX4QmAIBBA4Yp2aY52aox2ao6mqf+SoajwON73M0J4HBy6TEEYQmMIjSE0htCECVlbDziv+/n6fuzb3OP/UmEmYgiNITRNm+LPqO2UE2YihtAYQlN818ptoZzau1btOakwEzGExhCa5hdi7d2p1zZLhZmIITSG0PhCpDGExhANEmYihtAYQmMIjSE0bwAAAP//kHQdRIWYzToAAAAASUVORK5CYII=\",\"key-uid\":\"%s\",\"keycard-pairing\":null}", multiAccountGenerateAndDeriveAddresses0address, multiAccountGenerateAndDeriveAddresses0keyUid);
|
||||
|
||||
|
||||
// multiAccountGenerateAndDeriveAddresses0keyUid
|
||||
char* multiAccountGenerateAndDeriveAddresses0mnemonic = nx_json_get(nx_json_item(MultiAccountGenerateAndDeriveAddresses, 0), "mnemonic")->text_value;
|
||||
// m4360publicKey
|
||||
// multiAccountGenerateAndDeriveAddresses0address
|
||||
char* eip1581Address = nx_json_get(nx_json_get(MultiAccountStoreDerivedAccounts, "m/43'/60'/1581'"), "address")->text_value;
|
||||
// m4460address
|
||||
char* walletRootAddress = nx_json_get(nx_json_get(MultiAccountStoreDerivedAccounts, "m/44'/60'/0'/0"), "address")->text_value;
|
||||
|
||||
|
||||
char settings[5000];
|
||||
sprintf(settings, "{\"key-uid\":\"%s\",\"mnemonic\":\"%s\",\"public-key\":\"%s\",\"name\":\"Delectable Overjoyed Nauplius\",\"address\":\"%s\",\"eip1581-address\":\"%s\",\"dapps-address\":\"%s\",\"wallet-root-address\":\"%s\",\"preview-privacy?\":true,\"signing-phrase\":\"dust gear boss\",\"log-level\":\"INFO\",\"latest-derived-path\":0,\"networks/networks\":[{\"id\":\"testnet_rpc\",\"etherscan-link\":\"https://ropsten.etherscan.io/address/\",\"name\":\"Ropsten with upstream RPC\",\"config\":{\"NetworkId\":3,\"DataDir\":\"/ethereum/testnet_rpc\",\"UpstreamConfig\":{\"Enabled\":true,\"URL\":\"https://ropsten.infura.io/v3/f315575765b14720b32382a61a89341a\"}}},{\"id\":\"rinkeby_rpc\",\"etherscan-link\":\"https://rinkeby.etherscan.io/address/\",\"name\":\"Rinkeby with upstream RPC\",\"config\":{\"NetworkId\":4,\"DataDir\":\"/ethereum/rinkeby_rpc\",\"UpstreamConfig\":{\"Enabled\":true,\"URL\":\"https://rinkeby.infura.io/v3/f315575765b14720b32382a61a89341a\"}}},{\"id\":\"goerli_rpc\",\"etherscan-link\":\"https://goerli.etherscan.io/address/\",\"name\":\"Goerli with upstream RPC\",\"config\":{\"NetworkId\":5,\"DataDir\":\"/ethereum/goerli_rpc\",\"UpstreamConfig\":{\"Enabled\":true,\"URL\":\"https://goerli.blockscout.com/\"}}},{\"id\":\"mainnet_rpc\",\"etherscan-link\":\"https://etherscan.io/address/\",\"name\":\"Mainnet with upstream RPC\",\"config\":{\"NetworkId\":1,\"DataDir\":\"/ethereum/mainnet_rpc\",\"UpstreamConfig\":{\"Enabled\":true,\"URL\":\"https://mainnet.infura.io/v3/f315575765b14720b32382a61a89341a\"}}},{\"id\":\"xdai_rpc\",\"name\":\"xDai Chain\",\"config\":{\"NetworkId\":100,\"DataDir\":\"/ethereum/xdai_rpc\",\"UpstreamConfig\":{\"Enabled\":true,\"URL\":\"https://dai.poa.network\"}}},{\"id\":\"poa_rpc\",\"name\":\"POA Network\",\"config\":{\"NetworkId\":99,\"DataDir\":\"/ethereum/poa_rpc\",\"UpstreamConfig\":{\"Enabled\":true,\"URL\":\"https://core.poa.network\"}}}],\"currency\":\"usd\",\"photo-path\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAmElEQVR4nOzX4QmAIBBA4Yp2aY52aox2ao6mqf+SoajwON73M0J4HBy6TEEYQmMIjSE0htCECVlbDziv+/n6fuzb3OP/UmEmYgiNITRNm+LPqO2UE2YihtAYQlN818ptoZzau1btOakwEzGExhCa5hdi7d2p1zZLhZmIITSG0PhCpDGExhANEmYihtAYQmMIjSE0bwAAAP//kHQdRIWYzToAAAAASUVORK5CYII=\",\"waku-enabled\":true,\"wallet/visible-tokens\":{\"mainnet\":[\"SNT\"]},\"appearance\":0,\"networks/current-network\":\"mainnet_rpc\",\"installation-id\":\"5d6bc316-a97e-5b89-9541-ad01f8eb7397\"}",
|
||||
multiAccountGenerateAndDeriveAddresses0keyUid, multiAccountGenerateAndDeriveAddresses0mnemonic, m4360publicKey, multiAccountGenerateAndDeriveAddresses0address,
|
||||
eip1581Address, m4460address, walletRootAddress);
|
||||
|
||||
char* loginResult = saveAccountAndLogin(multiAccountData, password, settings, finalConfig, accountsData);
|
||||
printf("5. saveAccountAndLogin:\n%s\n\n", loginResult);
|
||||
|
||||
|
||||
setSignalEventCallback(&eventCallback);
|
||||
|
||||
// TODO: tests GC strings
|
||||
|
||||
while(1) {
|
||||
printf("...\n");
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue