feat: build nim_status.a static library and create simple test file in C
This commit is contained in:
parent
3dda55a8a3
commit
80d9d2c8b7
|
@ -7,4 +7,5 @@ tmp
|
|||
nimcache
|
||||
.DS_Store
|
||||
TODO
|
||||
nim_status
|
||||
nim_status
|
||||
test/test
|
30
Makefile
30
Makefile
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2019-2020 Status Research & Development GmbH. Licensed under
|
||||
# Copyright (c) 2020 Status Research & Development GmbH. Licensed under
|
||||
# either of:
|
||||
# - Apache License, version 2.0
|
||||
# - MIT license
|
||||
|
@ -21,7 +21,8 @@ BUILD_SYSTEM_DIR := vendor/nimbus-build-system
|
|||
clean \
|
||||
deps \
|
||||
nim_status \
|
||||
update
|
||||
update \
|
||||
tests
|
||||
|
||||
ifeq ($(NIM_PARAMS),)
|
||||
# "variables.mk" was not included, so we update the submodules.
|
||||
|
@ -95,7 +96,7 @@ endif
|
|||
|
||||
# TODO: control debug/release builds with a Make var
|
||||
# We need `-d:debug` to get Nim's default stack traces.
|
||||
NIM_PARAMS += --app:staticLib --noMain -d:debug
|
||||
NIM_PARAMS += -d:debug
|
||||
|
||||
deps: | deps-common
|
||||
|
||||
|
@ -108,15 +109,24 @@ $(STATUSGO): | deps
|
|||
+ cd vendor/status-go && \
|
||||
$(MAKE) statusgo-library $(HANDLE_OUTPUT)
|
||||
|
||||
nim_status: | $(STATUSGO) deps
|
||||
echo -e $(BUILD_MSG) "$@" && \
|
||||
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --passL:"$(STATUSGO)" --passL:"-lm" --header src/nim_status.nim && \
|
||||
mkdir -p build && \
|
||||
cp nimcache/debug/nim_status/nim_status.h build/.
|
||||
cp nim_status build/nim_status.o
|
||||
|
||||
clean: | clean-common
|
||||
rm -rf build/*
|
||||
rm -rf $(STATUSGO)
|
||||
|
||||
NIMSTATUS := build/nim_status.a
|
||||
|
||||
$(NIMSTATUS): | build $(STATUSGO) deps
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
$(ENV_SCRIPT) nim c $(NIM_PARAMS) --app:staticLib --header --noMain --nimcache:nimcache/nim_status --passL:$(STATUSGO) -o:$@ src/nim_status.nim
|
||||
cp nimcache/nim_status/nim_status.h build/.
|
||||
mv nim_status.a build/.
|
||||
|
||||
nim_status: $(NIMSTATUS)
|
||||
|
||||
tests: | $(NIMSTATUS)
|
||||
echo "Compiling 'test/test'" && \
|
||||
$(CC) -I"$(CURDIR)/build" -I"$(CURDIR)/vendor/nimbus-build-system/vendor/Nim/lib" test/test.c $(NIMSTATUS) $(STATUSGO) -lm -pthread -o test/test && \
|
||||
echo "Executing 'test/test'" && \
|
||||
./test/test
|
||||
|
||||
endif # "variables.mk" was not included
|
||||
|
|
|
@ -1,7 +1,117 @@
|
|||
from status_go import nil
|
||||
import status_go
|
||||
import types
|
||||
|
||||
# TODO: test this in node-ffi?
|
||||
# TODO: Create a nim proc for each status_go function
|
||||
# All procs start with lowercase because the compiler will also need to import status-go,
|
||||
# and it will complain of duplication of function names
|
||||
|
||||
proc hashMessage*(message: cstring): cstring {.exportc.} =
|
||||
result = status_go.hashMessage(message)
|
||||
result = status_go.HashMessage(message)
|
||||
|
||||
proc initKeystore*(keydir: cstring): cstring {.exportc.} =
|
||||
result = status_go.InitKeystore(keydir)
|
||||
|
||||
proc openAccounts*(datadir: cstring): cstring {.exportc.} =
|
||||
result = status_go.OpenAccounts(datadir)
|
||||
|
||||
proc multiAccountGenerateAndDeriveAddresses*(paramsJSON: cstring): cstring {.exportc.} =
|
||||
result = status_go.MultiAccountGenerateAndDeriveAddresses(paramsJSON)
|
||||
|
||||
proc multiAccountStoreDerivedAccounts*(paramsJSON: cstring): cstring {.exportc.} =
|
||||
result = status_go.MultiAccountStoreDerivedAccounts(paramsJSON)
|
||||
|
||||
proc multiAccountImportMnemonic*(paramsJSON: cstring): cstring {.exportc.} =
|
||||
result = status_go.MultiAccountImportMnemonic(paramsJSON)
|
||||
|
||||
proc multiAccountImportPrivateKey*(paramsJSON: cstring): cstring {.exportc.} =
|
||||
result = status_go.MultiAccountImportPrivateKey(paramsJSON)
|
||||
|
||||
proc multiAccountDeriveAddresses*(paramsJSON: cstring): cstring {.exportc.} =
|
||||
result = status_go.MultiAccountDeriveAddresses(paramsJSON)
|
||||
|
||||
proc saveAccountAndLogin*(accountData: cstring, password: cstring, settingsJSON: cstring, configJSON: cstring, subaccountData: cstring): cstring {.exportc.} =
|
||||
result = status_go.SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subaccountData)
|
||||
|
||||
proc callRPC*(inputJSON: cstring): cstring {.exportc.} =
|
||||
result = status_go.CallRPC(inputJSON)
|
||||
|
||||
proc callPrivateRPC*(inputJSON: cstring): cstring {.exportc.} =
|
||||
result = status_go.CallPrivateRPC(inputJSON)
|
||||
|
||||
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.} =
|
||||
result = status_go.SendTransaction(jsonArgs, password)
|
||||
|
||||
proc generateAlias*(pk: GoString): cstring {.exportc.} =
|
||||
result = status_go.GenerateAlias(pk)
|
||||
|
||||
proc identicon*(pk: GoString): cstring {.exportc.} =
|
||||
result = status_go.Identicon(pk)
|
||||
|
||||
proc login*(accountData: cstring, password: cstring): cstring {.exportc.} =
|
||||
result = status_go.Login(accountData, password)
|
||||
|
||||
proc logout*(): cstring {.exportc.} =
|
||||
result = status_go.Logout()
|
||||
|
||||
proc verifyAccountPassword*(keyStoreDir: cstring, address: cstring, password: cstring): cstring {.exportc.} =
|
||||
result = status_go.VerifyAccountPassword(keyStoreDir, address, password)
|
||||
|
||||
proc validateMnemonic*(mnemonic: cstring): cstring {.exportc.} =
|
||||
result = status_go.ValidateMnemonic(mnemonic)
|
||||
|
||||
proc recoverAccount(password: cstring, mnemonic: cstring): cstring {.exportc.} =
|
||||
result = status_go.RecoverAccount(password, mnemonic)
|
||||
|
||||
proc startOnboarding(n: cint, mnemonicPhraseLength: cint): cstring {.exportc.} =
|
||||
result = status_go.StartOnboarding(n, mnemonicPhraseLength)
|
||||
|
||||
proc saveAccountAndLoginWithKeycard(accountData: cstring, password: cstring, settingsJSON: cstring, configJSON: cstring, subaccountData: cstring, keyHex: cstring): cstring {.exportc.} =
|
||||
result = status_go.SaveAccountAndLoginWithKeycard(accountData, password, settingsJSON, configJSON, subaccountData, keyHex)
|
||||
|
||||
proc hashTransaction(txArgsJSON: cstring): cstring {.exportc.} =
|
||||
result = status_go.HashTransaction(txArgsJSON)
|
||||
|
||||
proc extractGroupMembershipSignatures(signaturePairsStr: cstring): cstring {.exportc.} =
|
||||
result = status_go.ExtractGroupMembershipSignatures(signaturePairsStr)
|
||||
|
||||
proc connectionChange(typ: cstring, expensive: cstring) {.exportc.} =
|
||||
status_go.ConnectionChange(typ, expensive)
|
||||
|
||||
proc multiformatSerializePublicKey(key: cstring, outBase: cstring): cstring {.exportc.} =
|
||||
result = status_go.MultiformatSerializePublicKey(key, outBase)
|
||||
|
||||
|
||||
# TODO: Create a nim proc for each of these status_go functions
|
||||
#[
|
||||
extern char* MultiformatDeserializePublicKey(char* key, char* outBase);
|
||||
extern char* ValidateNodeConfig(char* configJSON);
|
||||
extern char* LoginWithKeycard(char* accountData, char* password, char* keyHex);
|
||||
extern char* Recover(char* rpcParams);
|
||||
extern char* WriteHeapProfile(char* dataDir);
|
||||
extern char* ImportOnboardingAccount(char* id, char* password);
|
||||
extern void RemoveOnboarding();
|
||||
extern char* HashTypedData(char* data);
|
||||
extern char* ResetChainData();
|
||||
extern char* SignMessage(char* rpcParams);
|
||||
extern char* SignTypedData(char* data, char* address, char* password);
|
||||
extern char* StopCPUProfiling();
|
||||
extern char* GetNodesFromContract(char* rpcEndpoint, char* contractAddress);
|
||||
extern char* ExportNodeLogs();
|
||||
extern char* ChaosModeUpdate(int on);
|
||||
extern char* SignHash(char* hexEncodedHash);
|
||||
extern char* CreateAccount(char* password);
|
||||
extern char* SendTransactionWithSignature(char* txtArgsJSON, char* sigString);
|
||||
extern char* StartCPUProfile(char* dataDir);
|
||||
extern void AppStateChange(char* state);
|
||||
extern char* SignGroupMembership(char* content);
|
||||
extern char* MultiAccountStoreAccount(char* paramsJSON);
|
||||
extern char* MultiAccountLoadAccount(char* paramsJSON);
|
||||
extern char* MultiAccountGenerate(char* paramsJSON);
|
||||
extern char* MultiAccountReset();
|
||||
]#
|
|
@ -1,41 +1,84 @@
|
|||
import types
|
||||
|
||||
proc hashMessage*(p0: cstring): cstring {.importc: "HashMessage".}
|
||||
#[
|
||||
TODO: create procs for these:
|
||||
extern char* MultiformatDeserializePublicKey(char* key, char* outBase);
|
||||
extern char* ValidateNodeConfig(char* configJSON);
|
||||
extern char* LoginWithKeycard(char* accountData, char* password, char* keyHex);
|
||||
extern char* Recover(char* rpcParams);
|
||||
extern char* WriteHeapProfile(char* dataDir);
|
||||
extern char* ImportOnboardingAccount(char* id, char* password);
|
||||
extern void RemoveOnboarding();
|
||||
extern char* HashTypedData(char* data);
|
||||
extern char* ResetChainData();
|
||||
extern char* SignMessage(char* rpcParams);
|
||||
extern char* SignTypedData(char* data, char* address, char* password);
|
||||
extern char* StopCPUProfiling();
|
||||
extern char* GetNodesFromContract(char* rpcEndpoint, char* contractAddress);
|
||||
extern char* ExportNodeLogs();
|
||||
extern char* ChaosModeUpdate(int on);
|
||||
extern char* SignHash(char* hexEncodedHash);
|
||||
extern char* CreateAccount(char* password);
|
||||
extern char* SendTransactionWithSignature(char* txtArgsJSON, char* sigString);
|
||||
extern char* StartCPUProfile(char* dataDir);
|
||||
extern void AppStateChange(char* state);
|
||||
extern char* SignGroupMembership(char* content);
|
||||
extern char* MultiAccountStoreAccount(char* paramsJSON);
|
||||
extern char* MultiAccountLoadAccount(char* paramsJSON);
|
||||
extern char* MultiAccountGenerate(char* paramsJSON);
|
||||
extern char* MultiAccountReset();
|
||||
]#
|
||||
|
||||
proc initKeystore*(keydir: cstring): cstring {.importc: "InitKeystore".}
|
||||
proc HashMessage*(message: cstring): cstring {.importc: "HashMessage".}
|
||||
|
||||
proc openAccounts*(datadir: cstring): cstring {.importc: "OpenAccounts".}
|
||||
proc InitKeystore*(keydir: cstring): cstring {.importc: "InitKeystore".}
|
||||
|
||||
proc multiAccountGenerateAndDeriveAddresses*(paramsJSON: cstring): cstring {.importc: "MultiAccountGenerateAndDeriveAddresses".}
|
||||
proc OpenAccounts*(datadir: cstring): cstring {.importc: "OpenAccounts".}
|
||||
|
||||
proc multiAccountStoreDerivedAccounts*(paramsJSON: cstring): cstring {.importc: "MultiAccountStoreDerivedAccounts".}
|
||||
proc MultiAccountGenerateAndDeriveAddresses*(paramsJSON: cstring): cstring {.importc: "MultiAccountGenerateAndDeriveAddresses".}
|
||||
|
||||
proc multiAccountImportMnemonic*(paramsJSON: cstring): cstring {.importc: "MultiAccountImportMnemonic".}
|
||||
proc MultiAccountStoreDerivedAccounts*(paramsJSON: cstring): cstring {.importc: "MultiAccountStoreDerivedAccounts".}
|
||||
|
||||
proc MultiAccountImportMnemonic*(paramsJSON: cstring): cstring {.importc: "MultiAccountImportMnemonic".}
|
||||
|
||||
proc MultiAccountImportPrivateKey*(paramsJSON: cstring): cstring {.importc: "MultiAccountImportPrivateKey".}
|
||||
|
||||
proc multiAccountDeriveAddresses*(paramsJSON: cstring): cstring {.importc: "MultiAccountDeriveAddresses".}
|
||||
proc MultiAccountDeriveAddresses*(paramsJSON: cstring): cstring {.importc: "MultiAccountDeriveAddresses".}
|
||||
|
||||
proc saveAccountAndLogin*(accountData: cstring, password: cstring, settingsJSON: cstring, configJSON: cstring, subaccountData: cstring): cstring {.importc: "SaveAccountAndLogin".}
|
||||
proc SaveAccountAndLogin*(accountData: cstring, password: cstring, settingsJSON: cstring, configJSON: cstring, subaccountData: cstring): cstring {.importc: "SaveAccountAndLogin".}
|
||||
|
||||
proc callRPC*(inputJSON: cstring): cstring {.importc: "CallRPC".}
|
||||
proc CallRPC*(inputJSON: cstring): cstring {.importc: "CallRPC".}
|
||||
|
||||
proc callPrivateRPC*(inputJSON: cstring): cstring {.importc: "CallPrivateRPC".}
|
||||
proc CallPrivateRPC*(inputJSON: cstring): cstring {.importc: "CallPrivateRPC".}
|
||||
|
||||
proc addPeer*(peer: cstring): cstring {.importc: "AddPeer".}
|
||||
proc AddPeer*(peer: cstring): cstring {.importc: "AddPeer".}
|
||||
|
||||
proc setSignalEventCallback*(callback: SignalCallback) {.importc: "SetSignalEventCallback".}
|
||||
proc SetSignalEventCallback*(callback: SignalCallback) {.importc: "SetSignalEventCallback".}
|
||||
|
||||
proc sendTransaction*(jsonArgs: cstring, password: cstring): cstring {.importc: "SendTransaction".}
|
||||
proc SendTransaction*(jsonArgs: cstring, password: cstring): cstring {.importc: "SendTransaction".}
|
||||
|
||||
proc generateAlias*(p0: GoString): cstring {.importc: "GenerateAlias".}
|
||||
proc GenerateAlias*(pk: GoString): cstring {.importc: "GenerateAlias".}
|
||||
|
||||
proc identicon*(p0: GoString): cstring {.importc: "Identicon".}
|
||||
proc Identicon*(pk: GoString): cstring {.importc: "Identicon".}
|
||||
|
||||
proc login*(acctData: cstring, password: cstring): cstring {.importc: "Login".}
|
||||
proc Login*(accountData: cstring, password: cstring): cstring {.importc: "Login".}
|
||||
|
||||
proc logout*(): cstring {.importc: "Logout".}
|
||||
proc Logout*(): cstring {.importc: "Logout".}
|
||||
|
||||
proc verifyAccountPassword*(keyStoreDir: cstring, address: cstring, password: cstring): cstring {.importc: "VerifyAccountPassword".}
|
||||
proc VerifyAccountPassword*(keyStoreDir: cstring, address: cstring, password: cstring): cstring {.importc: "VerifyAccountPassword".}
|
||||
|
||||
proc validateMnemonic*(mnemonic: cstring): cstring {.importc: "ValidateMnemonic".}
|
||||
proc ValidateMnemonic*(mnemonic: cstring): cstring {.importc: "ValidateMnemonic".}
|
||||
|
||||
proc RecoverAccount*(password: cstring, mnemonic: cstring): cstring {.importc: "RecoverAccount".}
|
||||
|
||||
proc StartOnboarding*(n: cint, mnemonicPhraseLength: cint): cstring {.importc: "StartOnboarding".}
|
||||
|
||||
proc SaveAccountAndLoginWithKeycard*(accountData: cstring, password: cstring, settingsJSON: cstring, configJSON: cstring, subaccountData: cstring, keyHex: cstring): cstring {.importc: "SaveAccountAndLoginWithKeycard".}
|
||||
|
||||
proc HashTransaction*(txArgsJSON: cstring): cstring {.importc: "HashTransaction".}
|
||||
|
||||
proc ExtractGroupMembershipSignatures*(signaturePairsStr: cstring): cstring {.importc: "ExtractGroupMembershipSignatures".}
|
||||
|
||||
proc ConnectionChange*(typ: cstring, expensive: cstring) {.importc: "ConnectionChange".}
|
||||
|
||||
proc MultiformatSerializePublicKey*(key: cstring, outBase: cstring): cstring {.importc: "MultiformatSerializePublicKey".}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nim_status.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
NimMain();
|
||||
const char* message = hashMessage("Hello World!");
|
||||
printf("%s\n", message);
|
||||
|
||||
// TODO: test signals
|
||||
// TODO: tests GC strings
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue