Skip to content

Commit 917f68a

Browse files
committed
init, fix conflicts
1 parent 008e488 commit 917f68a

File tree

5 files changed

+376
-174
lines changed

5 files changed

+376
-174
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@ PORTAL_TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(FLUFFY_TOOLS))
8787
OS_PLATFORM = $(shell $(CC) -dumpmachine)
8888
ifneq (, $(findstring darwin, $(OS_PLATFORM)))
8989
SHAREDLIBEXT = dylib
90+
STATICLIBEXT = a
9091
else
9192
ifneq (, $(findstring mingw, $(OS_PLATFORM))$(findstring cygwin, $(OS_PLATFORM))$(findstring msys, $(OS_PLATFORM)))
9293
SHAREDLIBEXT = dll
94+
STATICLIBEXT = lib
9395
else
9496
SHAREDLIBEXT = so
97+
STATICLIBEXT = a
9598
endif
9699
endif
97100

@@ -168,7 +171,7 @@ all: | $(TOOLS) nimbus_execution_client
168171

169172
# "-d:release" cannot be added to config.nims
170173

171-
NIM_PARAMS += -d:release
174+
NIM_PARAMS += -d:debug
172175
ifneq ($(if $(ENABLE_LINE_NUMBERS),$(ENABLE_LINE_NUMBERS),0),0)
173176
NIM_PARAMS += -d:chronicles_line_numbers:1
174177
endif
@@ -350,7 +353,8 @@ nimbus-verified-proxy-test: | build deps
350353
libverifproxy: | build deps
351354
+ echo -e $(BUILD_MSG) "build/$@" && \
352355
$(ENV_SCRIPT) nim --version && \
353-
$(ENV_SCRIPT) nim c --app:lib -d:"libp2p_pki_schemes=secp256k1" --noMain:on --threads:on --nimcache:nimcache/libverifproxy -o:$(VERIF_PROXY_OUT_PATH)/$@.$(SHAREDLIBEXT) $(NIM_PARAMS) nimbus_verified_proxy/libverifproxy/verifproxy.nim
356+
echo $(NIM_PARAMS) && \
357+
$(ENV_SCRIPT) nim c --app:staticlib -d:"libp2p_pki_schemes=secp256k1" --noMain:on --out:$(VERIF_PROXY_OUT_PATH)/$@.$(STATICLIBEXT) $(NIM_PARAMS) nimbus_verified_proxy/libverifproxy/verifproxy.nim
354358
cp nimbus_verified_proxy/libverifproxy/verifproxy.h $(VERIF_PROXY_OUT_PATH)/
355359
echo -e $(BUILD_END_MSG) "build/$@"
356360

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include "./verifproxy.h"
2+
#include <stdio.h>
3+
#include <unistd.h>
4+
#include <stdbool.h>
5+
6+
static bool wait = false;
7+
8+
void onBlockNumber(int status, char *res) {
9+
printf("response: %s\n", res);
10+
freeResponse(res);
11+
}
12+
13+
void onStart(int status, char *res) {
14+
printf("Verified Proxy started successfully\n");
15+
freeResponse(res);
16+
}
17+
18+
void waitIsOver(int status, char *res) {
19+
printf("waiting finished successfully\n");
20+
printf("status: %d\n", status);
21+
22+
wait = false;
23+
24+
// printf("response: %s\n", res);
25+
freeResponse(res);
26+
}
27+
28+
void doMultipleAsyncTasks(Context *ctx) {
29+
eth_blockNumber(ctx, onBlockNumber);
30+
nonBusySleep(ctx, 4, waitIsOver);
31+
}
32+
33+
int main() {
34+
NimMain();
35+
Context *ctx = createAsyncTaskContext();
36+
37+
const char* jsonConfig =
38+
"{"
39+
"\"Eth2Network\": \"mainnet\","
40+
"\"TrustedBlockRoot\": \"0x6e2b0d0725949a5ce977b61646cc4353a8c789f6c2b8fc8bfc98fcfdb99b3d0\","
41+
"\"BackendUrl\": \"https://eth.llamarpc.com\","
42+
"\"LogLevel\": \"info\""
43+
"}";
44+
startVerifProxy(ctx, jsonConfig, onStart);
45+
while(true) {
46+
if (!wait) {
47+
wait = true;
48+
doMultipleAsyncTasks(ctx);
49+
}
50+
pollAsyncTaskEngine(ctx);
51+
}
52+
freeContext(ctx);
53+
}

nimbus_verified_proxy/libverifproxy/verifproxy.h

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,42 @@
1010
#ifndef __verifproxy__
1111
#define __verifproxy__
1212

13-
typedef struct VerifProxyContext VerifProxyContext;
14-
typedef void (*onHeaderCallback)(const char* s, int t);
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
1516

16-
void quit(void);
17+
#ifndef __has_attribute
18+
#define __has_attribute(x) 0
19+
#endif
1720

18-
VerifProxyContext* startVerifProxy(const char* configJson, onHeaderCallback onHeader);
19-
void stopVerifProxy(VerifProxyContext*);
21+
#ifndef __has_feature
22+
#define __has_feature(x) 0
23+
#endif
24+
25+
#if __has_attribute(warn_unused_result)
26+
#define ETH_RESULT_USE_CHECK __attribute__((warn_unused_result))
27+
#else
28+
#define ETH_RESULT_USE_CHECK
29+
#endif
30+
31+
void NimMain(void);
32+
33+
typedef struct Context Context;
34+
35+
ETH_RESULT_USE_CHECK Context *createAsyncTaskContext();
36+
37+
typedef void (*CallBackProc) (int status, char *res);
38+
39+
void eth_blockNumber(Context *ctx, CallBackProc cb);
40+
void freeResponse(char *res);
41+
void freeContext(Context *ctx);
42+
void nonBusySleep(Context *ctx, int secs, CallBackProc cb);
43+
void startVerifProxy(Context *ctx, char* configJson, CallBackProc onstart);
44+
void stopVerifProxy(Context *ctx);
45+
void pollAsyncTaskEngine(Context *ctx);
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
2050

2151
#endif /* __verifproxy__ */

0 commit comments

Comments
 (0)