-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamrproxyclient.h
More file actions
162 lines (137 loc) · 5.34 KB
/
Copy pathstreamrproxyclient.h
File metadata and controls
162 lines (137 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef LIBSTREAMRPROXYCLIENT_H
#define LIBSTREAMRPROXYCLIENT_H
// NOLINTNEXTLINE
#include <stdint.h>
#if defined(__clang__) || defined(__GNUC__)
#define SHARED_EXPORT __attribute__((visibility("default")))
#define SHARED_LOCAL __attribute__((visibility("hidden")))
#else
#define SHARED_EXPORT
#define SHARED_LOCAL
#endif
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif
#define ERROR_INVALID_ETHEREUM_ADDRESS "INVALID_ETHEREUM_ADDRESS"
#define ERROR_INVALID_STREAM_PART_ID "INVALID_STREAM_PART_ID"
#define ERROR_PROXY_CLIENT_NOT_FOUND "PROXY_CLIENT_NOT_FOUND"
#define ERROR_INVALID_PROXY_URL "INVALID_PROXY_URL"
#define ERROR_NO_PROXIES_DEFINED "NO_PROXIES_DEFINED"
#define ERROR_PROXY_CONNECTION_FAILED "PROXY_CONNECTION_FAILED"
#define ERROR_PROXY_BROADCAST_FAILED "PROXY_BROADCAST_FAILED"
EXTERN_C SHARED_EXPORT const char* testRpc(void);
// NOLINTNEXTLINE
SHARED_EXPORT static void __attribute__((constructor)) initialize(void);
/**
* @brief Initialize the library. This function is called automatically when the library is loaded,
* but can be called explicitly to force a re-initialization (e.g. after proxyClientCleanupLibrary() has been called).
*/
// NOLINTNEXTLINE
EXTERN_C SHARED_EXPORT void proxyClientInitLibrary(void);
/**
* @brief Cleanup the library. This function MUST be called before the program exits.
* Can be safely called multiple times. This is needed because the standard dynamic library
* destructor (__attribute__((destructor))) is called after static variables have already been destroyed,
* which makes it impossible to clean up the other objects that depend on the static variables.
*/
// NOLINTNEXTLINE
EXTERN_C SHARED_EXPORT void proxyClientCleanupLibrary(void);
// NOLINTNEXTLINE
typedef struct Proxy {
const char* websocketUrl;
const char* ethereumAddress;
} Proxy;
// NOLINTNEXTLINE
typedef struct Error {
const char* message;
const char* code;
const struct Proxy* proxy;
} Error;
// NOLINTNEXTLINE
typedef struct ProxyResult {
Error* errors;
uint64_t numErrors;
Proxy* successful;
uint64_t numSuccessful;
} ProxyResult;
/**
* @brief Delete a ProxyResult. This method must be called after every call that
* returns a ProxyResult.
* @param proxyResult The ProxyResult to delete.
*/
EXTERN_C SHARED_EXPORT void proxyClientResultDelete(const ProxyResult* proxyResult);
/**
* @brief Create a new proxy client.
*
* @param proxyResult Pointer in which ProxyResult will be stored. You MUST call
* proxyClientResultDelete() on this after the call returns. The resulting ProxyResult
* may only contain "errors" - the "successful" and "numSuccessful" fields are
* unused.
* @param ownEthereumAddress The Ethereum address of the client in format
* 0x1234567890123456789012345678901234567890.
* @param streamPartId The stream part id in format
* 0xa000000000000000000000000000000000000000#01.
* @return The handle of the created client.
*/
EXTERN_C SHARED_EXPORT uint64_t proxyClientNew(
const ProxyResult** proxyResult,
const char* ownEthereumAddress,
const char* streamPartId);
/**
* @brief Delete a proxy client.
*
* @param proxyResult Pointer in which ProxyResult will be stored. You MUST call
* proxyClientResultDelete() on this after the call returns. The resulting ProxyResult
* may only contain "errors" - the "successful" and "numSuccessful" fields are
* unused.
* @param clientHandle The client handle of the client to delete.
*/
EXTERN_C SHARED_EXPORT void proxyClientDelete(
const ProxyResult** proxyResult, uint64_t clientHandle);
/**
* @brief Connect a proxy client to a list of proxies.
*
* @param proxyResult Pointer in which ProxyResult will be stored. You MUST call
* proxyClientResultDelete() on this after the call returns.
* @param clientHandle The client handle of the client to connect.
* @param proxies The array of proxies.
* @param numProxies The number of proxies.
* @return The number of proxies connected to.
*/
EXTERN_C SHARED_EXPORT uint64_t proxyClientConnect(
const ProxyResult** proxyResult,
uint64_t clientHandle,
const Proxy* proxies,
uint64_t numProxies);
/**
* @brief Disconnect a proxy client from all proxies.
*
* @param proxyResult Pointer in which ProxyResult will be stored. You MUST call
* proxyClientResultDelete() on this after the call returns. The resulting ProxyResult
* may only contain "errors" - the "successful" and "numSuccessful" fields are
* unused.
* @param clientHandle The client handle of the client to disconnect.
EXTERN_C SHARED_EXPORT void proxyClientDisconnect(
const ProxyResult** proxyResult, uint64_t clientHandle);
*/
/**
* @brief Publish a message to the stream.
*
* @param proxyResult Pointer in which ProxyResult will be stored. You MUST call
* proxyClientResultDelete() on this after the call returns.
* @param clientHandle The client handle of the client to publish.
* @param content The content to publish.
* @param contentLength The length of the content.
* @param ethereumPrivateKey as hex without 0x prefix (64 characters) or NULL if
* message should not be signed.
* @return The number of proxies to which the message was published to.
*/
EXTERN_C SHARED_EXPORT uint64_t proxyClientPublish(
const ProxyResult** proxyResult,
uint64_t clientHandle,
const char* content,
uint64_t contentLength,
const char* ethereumPrivateKey);
#endif /* LIBSTREAMRPROXYCLIENT_H */