This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 736
/
pool.rs
executable file
·315 lines (264 loc) · 11.2 KB
/
pool.rs
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
use indy_api_types::{ErrorCode, CommandHandle, PoolHandle, INVALID_POOL_HANDLE};
use crate::commands::{Command, CommandExecutor};
use crate::commands::pool::PoolCommand;
use crate::domain::pool::{PoolConfig, PoolOpenConfig};
use indy_api_types::errors::prelude::*;
use indy_utils::ctypes;
use indy_api_types::validation::Validatable;
use serde_json;
use libc::c_char;
/// Creates a new local pool ledger configuration that can be used later to connect pool nodes.
///
/// #Params
/// config_name: Name of the pool ledger configuration.
/// config (optional): Pool configuration json. if NULL, then default config will be used. Example:
/// {
/// "genesis_txn": string (optional), A path to genesis transaction file. If NULL, then a default one will be used.
/// If file doesn't exists default one will be created.
/// }
///
/// #Returns
/// Error code
///
/// #Errors
/// Common*
/// Ledger*
#[no_mangle]
pub extern fn indy_create_pool_ledger_config(command_handle: CommandHandle,
config_name: *const c_char,
config: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode)>) -> ErrorCode {
trace!("indy_create_pool_ledger_config: >>> config_name: {:?}, config: {:?}", config_name, config);
check_useful_c_str!(config_name, ErrorCode::CommonInvalidParam2);
check_useful_opt_json!(config, ErrorCode::CommonInvalidParam3, PoolConfig);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
trace!("indy_create_pool_ledger_config: entities >>> config_name: {:?}, config: {:?}", config_name, config);
let result = CommandExecutor::instance()
.send(Command::Pool(PoolCommand::Create(
config_name,
config,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_create_pool_ledger_config:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_create_pool_ledger_config: <<< res: {:?}", res);
res
}
/// Opens pool ledger and performs connecting to pool nodes.
///
/// Pool ledger configuration with corresponded name must be previously created
/// with indy_create_pool_ledger_config method.
/// It is impossible to open pool with the same name more than once.
///
/// config_name: Name of the pool ledger configuration.
/// config (optional): Runtime pool configuration json.
/// if NULL, then default config will be used. Example:
/// {
/// "timeout": int (optional), timeout for network request (in sec).
/// "extended_timeout": int (optional), extended timeout for network request (in sec).
/// "preordered_nodes": array<string> - (optional), names of nodes which will have a priority during request sending:
/// ["name_of_1st_prior_node", "name_of_2nd_prior_node", .... ]
/// This can be useful if a user prefers querying specific nodes.
/// Assume that `Node1` and `Node2` nodes reply faster.
/// If you pass them Libindy always sends a read request to these nodes first and only then (if not enough) to others.
/// Note: Nodes not specified will be placed randomly.
/// "number_read_nodes": int (optional) - the number of nodes to send read requests (2 by default)
/// By default Libindy sends a read requests to 2 nodes in the pool.
/// If response isn't received or `state proof` is invalid Libindy sends the request again but to 2 (`number_read_nodes`) * 2 = 4 nodes and so far until completion.
/// "socks_proxy": string (optional) - ZMQ socks proxy host name and port (example: proxy1.intranet.company.com:1080)
/// }
///
/// #Returns
/// Handle to opened pool to use in methods that require pool connection.
///
/// #Errors
/// Common*
/// Ledger*
#[no_mangle]
pub extern fn indy_open_pool_ledger(command_handle: CommandHandle,
config_name: *const c_char,
config: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode,
pool_handle: PoolHandle)>) -> ErrorCode {
trace!("indy_open_pool_ledger: >>> config_name: {:?}, config: {:?}", config_name, config);
check_useful_c_str!(config_name, ErrorCode::CommonInvalidParam2);
check_useful_opt_validatable_json!(config, ErrorCode::CommonInvalidParam3, PoolOpenConfig);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
trace!("indy_open_pool_ledger: entities >>> config_name: {:?}, config: {:?}", config_name, config);
let result = CommandExecutor::instance()
.send(Command::Pool(PoolCommand::Open(
config_name,
config,
Box::new(move |result| {
let (err, pool_handle) = prepare_result_1!(result, INVALID_POOL_HANDLE);
trace!("indy_open_pool_ledger: pool_handle: {:?}", pool_handle);
cb(command_handle, err, pool_handle)
})
)));
let res = prepare_result!(result);
trace!("indy_open_pool_ledger: <<< res: {:?}", res);
res
}
/// Refreshes a local copy of a pool ledger and updates pool nodes connections.
///
/// #Params
/// handle: pool handle returned by indy_open_pool_ledger
///
/// #Returns
/// Error code
///
/// #Errors
/// Common*
/// Ledger*
#[no_mangle]
pub extern fn indy_refresh_pool_ledger(command_handle: CommandHandle,
handle: PoolHandle,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode)>) -> ErrorCode {
trace!("indy_refresh_pool_ledger: >>> handle: {:?}", handle);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam3);
trace!("indy_refresh_pool_ledger: entities >>> handle: {:?}", handle);
let result = CommandExecutor::instance()
.send(Command::Pool(PoolCommand::Refresh(
handle,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_refresh_pool_ledger:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_refresh_pool_ledger: <<< res: {:?}", res);
res
}
/// Lists names of created pool ledgers
///
/// #Params
///
/// #Returns
/// Error code
///
/// #Errors
#[no_mangle]
pub extern fn indy_list_pools(command_handle: CommandHandle,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode,
pools: *const c_char)>) -> ErrorCode {
trace!("indy_list_pools: >>>");
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam2);
trace!("indy_list_pools: entities >>>");
let result = CommandExecutor::instance()
.send(Command::Pool(PoolCommand::List(boxed_callback_string!("indy_list_pools", cb, command_handle))));
let res = prepare_result!(result);
trace!("indy_list_pools: <<< res: {:?}", res);
res
}
/// Closes opened pool ledger, opened nodes connections and frees allocated resources.
///
/// #Params
/// handle: pool handle returned by indy_open_pool_ledger.
///
/// #Returns
/// Error code
///
/// #Errors
/// Common*
/// Ledger*
#[no_mangle]
pub extern fn indy_close_pool_ledger(command_handle: CommandHandle,
handle: PoolHandle,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode)>) -> ErrorCode {
trace!("indy_close_pool_ledger: >>> handle: {:?}", handle);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam3);
trace!("indy_close_pool_ledger: entities >>> handle: {:?}", handle);
let result = CommandExecutor::instance()
.send(Command::Pool(PoolCommand::Close(
handle,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_close_pool_ledger:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_close_pool_ledger: <<< res: {:?}", res);
res
}
/// Deletes created pool ledger configuration.
///
/// #Params
/// config_name: Name of the pool ledger configuration to delete.
///
/// #Returns
/// Error code
///
/// #Errors
/// Common*
/// Ledger*
#[no_mangle]
pub extern fn indy_delete_pool_ledger_config(command_handle: CommandHandle,
config_name: *const c_char,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode)>) -> ErrorCode {
trace!("indy_delete_pool_ledger_config: >>> config_name: {:?}", config_name);
check_useful_c_str!(config_name, ErrorCode::CommonInvalidParam2);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam3);
trace!("indy_delete_pool_ledger_config: entities >>> config_name: {:?}", config_name);
let result = CommandExecutor::instance()
.send(Command::Pool(PoolCommand::Delete(
config_name,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_delete_pool_ledger_config:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_delete_pool_ledger_config: <<< res: {:?}", res);
res
}
/// Set PROTOCOL_VERSION to specific version.
///
/// There is a global property PROTOCOL_VERSION that used in every request to the pool and
/// specified version of Indy Node which Libindy works.
///
/// By default PROTOCOL_VERSION=1.
///
/// #Params
/// protocol_version: Protocol version will be used:
/// 1 - for Indy Node 1.3
/// 2 - for Indy Node 1.4 and greater
///
/// #Returns
/// Error code
///
/// #Errors
/// Common*
#[no_mangle]
pub extern fn indy_set_protocol_version(command_handle: CommandHandle,
protocol_version: usize,
cb: Option<extern fn(command_handle_: CommandHandle,
err: ErrorCode)>) -> ErrorCode {
trace!("indy_set_protocol_version: >>> protocol_version: {:?}", protocol_version);
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam3);
trace!("indy_set_protocol_version: entities >>> protocol_version: {:?}", protocol_version);
let result = CommandExecutor::instance()
.send(Command::Pool(
PoolCommand::SetProtocolVersion(
protocol_version,
Box::new(move |result| {
let err = prepare_result!(result);
trace!("indy_set_protocol_version:");
cb(command_handle, err)
})
)));
let res = prepare_result!(result);
trace!("indy_set_protocol_version: <<< res: {:?}", res);
res
}