react-native-nitro-ark 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cpp/NitroArk.hpp +278 -230
- package/cpp/bark-cpp.h +355 -359
- package/lib/typescript/src/NitroArk.nitro.d.ts +2 -0
- package/lib/typescript/src/NitroArk.nitro.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/BarkConfigOpts.hpp +10 -2
- package/package.json +2 -2
- package/src/NitroArk.nitro.ts +2 -0
package/cpp/NitroArk.hpp
CHANGED
|
@@ -7,33 +7,41 @@
|
|
|
7
7
|
#include <string>
|
|
8
8
|
#include <vector>
|
|
9
9
|
|
|
10
|
-
namespace margelo::nitro::nitroark
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (error
|
|
17
|
-
|
|
18
|
-
error_message =
|
|
10
|
+
namespace margelo::nitro::nitroark
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
// Helper function to handle potential errors from bark-cpp calls
|
|
14
|
+
inline void check_bark_error(bark::bark_BarkError *error)
|
|
15
|
+
{
|
|
16
|
+
if (error != nullptr)
|
|
17
|
+
{
|
|
18
|
+
std::string error_message = "Bark-cpp error: Unknown";
|
|
19
|
+
if (error->message != nullptr)
|
|
20
|
+
{
|
|
21
|
+
// Assuming error->message is valid C string allocated correctly
|
|
22
|
+
error_message = std::string("Bark-cpp error: ") + error->message;
|
|
23
|
+
}
|
|
24
|
+
// Use the FFI function to free the error struct and its contents
|
|
25
|
+
bark::bark_free_error(error);
|
|
26
|
+
throw std::runtime_error(error_message);
|
|
19
27
|
}
|
|
20
|
-
// Use the FFI function to free the error struct and its contents
|
|
21
|
-
bark::bark_free_error(error);
|
|
22
|
-
throw std::runtime_error(error_message);
|
|
23
28
|
}
|
|
24
|
-
}
|
|
25
29
|
|
|
26
|
-
class NitroArk : public HybridNitroArkSpec
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
class NitroArk : public HybridNitroArkSpec
|
|
31
|
+
{
|
|
32
|
+
public:
|
|
33
|
+
NitroArk() : HybridObject(TAG)
|
|
34
|
+
{
|
|
35
|
+
// Initialize the Rust logger once when a NitroArk object is created.
|
|
36
|
+
bark::bark_init_logger();
|
|
37
|
+
}
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
// --- Management ---
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
std::shared_ptr<Promise<std::string>> createMnemonic() override
|
|
42
|
+
{
|
|
43
|
+
return Promise<std::string>::async([]()
|
|
44
|
+
{
|
|
37
45
|
char *mnemonic_c = bark::bark_create_mnemonic();
|
|
38
46
|
if (mnemonic_c == nullptr) {
|
|
39
47
|
throw std::runtime_error(
|
|
@@ -41,14 +49,21 @@ public:
|
|
|
41
49
|
}
|
|
42
50
|
std::string mnemonic_str(mnemonic_c);
|
|
43
51
|
bark::bark_free_string(mnemonic_c);
|
|
44
|
-
return mnemonic_str;
|
|
45
|
-
}
|
|
46
|
-
|
|
52
|
+
return mnemonic_str; });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
std::shared_ptr<Promise<void>>
|
|
56
|
+
createWallet(const std::string &datadir,
|
|
57
|
+
const BarkCreateOpts &opts) override
|
|
58
|
+
{
|
|
59
|
+
return Promise<void>::async([datadir, opts]()
|
|
60
|
+
{
|
|
61
|
+
// Keep fee rate value alive for the C call
|
|
62
|
+
std::optional<uint64_t> fallback_fee_rate_val;
|
|
63
|
+
if (opts.config.has_value() && opts.config->fallback_fee_rate.has_value()) {
|
|
64
|
+
fallback_fee_rate_val = static_cast<uint64_t>(opts.config->fallback_fee_rate.value());
|
|
65
|
+
}
|
|
47
66
|
|
|
48
|
-
std::shared_ptr<Promise<void>>
|
|
49
|
-
createWallet(const std::string &datadir,
|
|
50
|
-
const BarkCreateOpts &opts) override {
|
|
51
|
-
return Promise<void>::async([datadir, opts]() {
|
|
52
67
|
bark::bark_BarkConfigOpts config = {
|
|
53
68
|
opts.config.has_value() && opts.config->asp.has_value()
|
|
54
69
|
? opts.config->asp->c_str()
|
|
@@ -67,7 +82,15 @@ public:
|
|
|
67
82
|
: nullptr,
|
|
68
83
|
opts.config.has_value() && opts.config->bitcoind_pass.has_value()
|
|
69
84
|
? opts.config->bitcoind_pass->c_str()
|
|
70
|
-
: nullptr
|
|
85
|
+
: nullptr,
|
|
86
|
+
opts.config.has_value() &&
|
|
87
|
+
opts.config->vtxo_refresh_expiry_threshold.has_value()
|
|
88
|
+
? static_cast<uint32_t>(
|
|
89
|
+
opts.config->vtxo_refresh_expiry_threshold.value())
|
|
90
|
+
: 0,
|
|
91
|
+
fallback_fee_rate_val.has_value() ? &fallback_fee_rate_val.value()
|
|
92
|
+
: nullptr
|
|
93
|
+
};
|
|
71
94
|
|
|
72
95
|
bark::bark_BarkCreateOpts barkOpts = {
|
|
73
96
|
opts.force.value_or(false),
|
|
@@ -82,16 +105,17 @@ public:
|
|
|
82
105
|
|
|
83
106
|
bark::bark_BarkError *error =
|
|
84
107
|
bark::bark_create_wallet(datadir.c_str(), barkOpts);
|
|
85
|
-
check_bark_error(error);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
108
|
+
check_bark_error(error); });
|
|
109
|
+
}
|
|
88
110
|
|
|
89
|
-
|
|
111
|
+
// --- Wallet Info ---
|
|
90
112
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
113
|
+
std::shared_ptr<Promise<BarkBalance>>
|
|
114
|
+
getBalance(const std::string &datadir, bool no_sync,
|
|
115
|
+
const std::string &mnemonic) override
|
|
116
|
+
{
|
|
117
|
+
return Promise<BarkBalance>::async([datadir, no_sync, mnemonic]()
|
|
118
|
+
{
|
|
95
119
|
bark::bark_BarkBalance c_balance;
|
|
96
120
|
bark::bark_BarkError *error = bark::bark_get_balance(
|
|
97
121
|
datadir.c_str(), no_sync, mnemonic.c_str(), &c_balance);
|
|
@@ -99,14 +123,15 @@ public:
|
|
|
99
123
|
|
|
100
124
|
return BarkBalance(static_cast<double>(c_balance.onchain),
|
|
101
125
|
static_cast<double>(c_balance.offchain),
|
|
102
|
-
static_cast<double>(c_balance.pending_exit));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
126
|
+
static_cast<double>(c_balance.pending_exit)); });
|
|
127
|
+
}
|
|
105
128
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
129
|
+
std::shared_ptr<Promise<std::string>>
|
|
130
|
+
getOnchainAddress(const std::string &datadir,
|
|
131
|
+
const std::string &mnemonic) override
|
|
132
|
+
{
|
|
133
|
+
return Promise<std::string>::async([datadir, mnemonic]()
|
|
134
|
+
{
|
|
110
135
|
char *address_c = nullptr;
|
|
111
136
|
bark::bark_BarkError *error = bark::bark_get_onchain_address(
|
|
112
137
|
datadir.c_str(), mnemonic.c_str(), &address_c);
|
|
@@ -117,14 +142,15 @@ public:
|
|
|
117
142
|
}
|
|
118
143
|
std::string address_str(address_c);
|
|
119
144
|
bark::bark_free_string(address_c); // Use helper
|
|
120
|
-
return address_str;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
145
|
+
return address_str; });
|
|
146
|
+
}
|
|
123
147
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
148
|
+
std::shared_ptr<Promise<std::string>>
|
|
149
|
+
getOnchainUtxos(const std::string &datadir, const std::string &mnemonic,
|
|
150
|
+
bool no_sync) override
|
|
151
|
+
{
|
|
152
|
+
return Promise<std::string>::async([datadir, mnemonic, no_sync]()
|
|
153
|
+
{
|
|
128
154
|
char *json_c = nullptr;
|
|
129
155
|
bark::bark_BarkError *error = bark::bark_get_onchain_utxos(
|
|
130
156
|
datadir.c_str(), mnemonic.c_str(), no_sync, &json_c);
|
|
@@ -135,14 +161,15 @@ public:
|
|
|
135
161
|
}
|
|
136
162
|
std::string json_str(json_c);
|
|
137
163
|
bark::bark_free_string(json_c); // Use helper
|
|
138
|
-
return json_str;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
164
|
+
return json_str; });
|
|
165
|
+
}
|
|
141
166
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
167
|
+
std::shared_ptr<Promise<std::string>>
|
|
168
|
+
getVtxoPubkey(const std::string &datadir,
|
|
169
|
+
const std::string &mnemonic) override
|
|
170
|
+
{
|
|
171
|
+
return Promise<std::string>::async([datadir, mnemonic]()
|
|
172
|
+
{
|
|
146
173
|
char *pubkey_c = nullptr;
|
|
147
174
|
bark::bark_BarkError *error = bark::bark_get_vtxo_pubkey(
|
|
148
175
|
datadir.c_str(), mnemonic.c_str(), &pubkey_c);
|
|
@@ -153,14 +180,15 @@ public:
|
|
|
153
180
|
}
|
|
154
181
|
std::string pubkey_str(pubkey_c);
|
|
155
182
|
bark::bark_free_string(pubkey_c); // Use helper
|
|
156
|
-
return pubkey_str;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
183
|
+
return pubkey_str; });
|
|
184
|
+
}
|
|
159
185
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
186
|
+
std::shared_ptr<Promise<std::string>> getVtxos(const std::string &datadir,
|
|
187
|
+
const std::string &mnemonic,
|
|
188
|
+
bool no_sync) override
|
|
189
|
+
{
|
|
190
|
+
return Promise<std::string>::async([datadir, mnemonic, no_sync]()
|
|
191
|
+
{
|
|
164
192
|
char *json_c = nullptr;
|
|
165
193
|
bark::bark_BarkError *error = bark::bark_get_vtxos(
|
|
166
194
|
datadir.c_str(), mnemonic.c_str(), no_sync, &json_c);
|
|
@@ -171,18 +199,19 @@ public:
|
|
|
171
199
|
}
|
|
172
200
|
std::string json_str(json_c);
|
|
173
201
|
bark::bark_free_string(json_c); // Use helper
|
|
174
|
-
return json_str;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
202
|
+
return json_str; });
|
|
203
|
+
}
|
|
177
204
|
|
|
178
|
-
|
|
205
|
+
// --- Onchain Operations ---
|
|
179
206
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
207
|
+
std::shared_ptr<Promise<std::string>>
|
|
208
|
+
sendOnchain(const std::string &datadir, const std::string &mnemonic,
|
|
209
|
+
const std::string &destination, double amountSat,
|
|
210
|
+
bool no_sync) override
|
|
211
|
+
{
|
|
212
|
+
return Promise<std::string>::async([datadir, mnemonic, destination,
|
|
213
|
+
amountSat, no_sync]()
|
|
214
|
+
{
|
|
186
215
|
char *txid_c = nullptr;
|
|
187
216
|
bark::bark_BarkError *error = bark::bark_send_onchain(
|
|
188
217
|
datadir.c_str(), mnemonic.c_str(), destination.c_str(),
|
|
@@ -194,35 +223,39 @@ public:
|
|
|
194
223
|
}
|
|
195
224
|
std::string txid_str(txid_c);
|
|
196
225
|
bark::bark_free_string(txid_c); // Use helper
|
|
197
|
-
return txid_str;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
226
|
+
return txid_str; });
|
|
227
|
+
}
|
|
200
228
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
229
|
+
std::shared_ptr<Promise<std::string>>
|
|
230
|
+
drainOnchain(const std::string &datadir, const std::string &mnemonic,
|
|
231
|
+
const std::string &destination, bool no_sync) override
|
|
232
|
+
{
|
|
233
|
+
return Promise<std::string>::async(
|
|
234
|
+
[datadir, mnemonic, destination, no_sync]()
|
|
235
|
+
{
|
|
236
|
+
char *txid_c = nullptr;
|
|
237
|
+
bark::bark_BarkError *error =
|
|
238
|
+
bark::bark_drain_onchain(datadir.c_str(), mnemonic.c_str(),
|
|
239
|
+
destination.c_str(), no_sync, &txid_c);
|
|
240
|
+
check_bark_error(error);
|
|
241
|
+
if (txid_c == nullptr)
|
|
242
|
+
{
|
|
243
|
+
throw std::runtime_error("Bark-cpp error: drainOnchain returned "
|
|
244
|
+
"success but txid is null");
|
|
245
|
+
}
|
|
246
|
+
std::string txid_str(txid_c);
|
|
247
|
+
bark::bark_free_string(txid_c); // Use helper
|
|
248
|
+
return txid_str;
|
|
249
|
+
});
|
|
250
|
+
}
|
|
220
251
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
252
|
+
std::shared_ptr<Promise<std::string>>
|
|
253
|
+
sendManyOnchain(const std::string &datadir, const std::string &mnemonic,
|
|
254
|
+
const std::vector<BarkSendManyOutput> &outputs,
|
|
255
|
+
bool no_sync) override
|
|
256
|
+
{
|
|
257
|
+
return Promise<std::string>::async([datadir, mnemonic, outputs, no_sync]()
|
|
258
|
+
{
|
|
226
259
|
size_t num_outputs = outputs.size();
|
|
227
260
|
if (num_outputs == 0) {
|
|
228
261
|
throw std::runtime_error(
|
|
@@ -252,17 +285,18 @@ public:
|
|
|
252
285
|
}
|
|
253
286
|
std::string txid_str(txid_c);
|
|
254
287
|
bark::bark_free_string(txid_c); // Use helper
|
|
255
|
-
return txid_str;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
288
|
+
return txid_str; });
|
|
289
|
+
}
|
|
258
290
|
|
|
259
|
-
|
|
291
|
+
// --- Ark Operations ---
|
|
260
292
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
293
|
+
std::shared_ptr<Promise<std::string>>
|
|
294
|
+
refreshVtxos(const std::string &datadir, const std::string &mnemonic,
|
|
295
|
+
const BarkRefreshOpts &refreshOpts, bool no_sync) override
|
|
296
|
+
{
|
|
297
|
+
return Promise<std::string>::async([datadir, mnemonic, refreshOpts,
|
|
298
|
+
no_sync]()
|
|
299
|
+
{
|
|
266
300
|
bark::bark_BarkRefreshOpts c_opts;
|
|
267
301
|
std::vector<const char *> specific_ids_c; // Keep alive for the C call
|
|
268
302
|
|
|
@@ -333,16 +367,17 @@ public:
|
|
|
333
367
|
}
|
|
334
368
|
std::string status_str(status_c);
|
|
335
369
|
bark::bark_free_string(status_c); // Use helper
|
|
336
|
-
return status_str;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
370
|
+
return status_str; });
|
|
371
|
+
}
|
|
339
372
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
373
|
+
std::shared_ptr<Promise<std::string>> boardAmount(const std::string &datadir,
|
|
374
|
+
const std::string &mnemonic,
|
|
375
|
+
double amountSat,
|
|
376
|
+
bool no_sync) override
|
|
377
|
+
{
|
|
378
|
+
return Promise<std::string>::async([datadir, mnemonic, amountSat,
|
|
379
|
+
no_sync]()
|
|
380
|
+
{
|
|
346
381
|
char *status_c = nullptr;
|
|
347
382
|
bark::bark_BarkError *error = bark::bark_board_amount(
|
|
348
383
|
datadir.c_str(), mnemonic.c_str(), static_cast<uint64_t>(amountSat),
|
|
@@ -354,14 +389,15 @@ public:
|
|
|
354
389
|
}
|
|
355
390
|
std::string status_str(status_c);
|
|
356
391
|
bark::bark_free_string(status_c); // Use helper
|
|
357
|
-
return status_str;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
392
|
+
return status_str; });
|
|
393
|
+
}
|
|
360
394
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
395
|
+
std::shared_ptr<Promise<std::string>> boardAll(const std::string &datadir,
|
|
396
|
+
const std::string &mnemonic,
|
|
397
|
+
bool no_sync) override
|
|
398
|
+
{
|
|
399
|
+
return Promise<std::string>::async([datadir, mnemonic, no_sync]()
|
|
400
|
+
{
|
|
365
401
|
char *status_c = nullptr;
|
|
366
402
|
bark::bark_BarkError *error = bark::bark_board_all(
|
|
367
403
|
datadir.c_str(), mnemonic.c_str(), no_sync, &status_c);
|
|
@@ -372,16 +408,17 @@ public:
|
|
|
372
408
|
}
|
|
373
409
|
std::string status_str(status_c);
|
|
374
410
|
bark::bark_free_string(status_c); // Use helper
|
|
375
|
-
return status_str;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
411
|
+
return status_str; });
|
|
412
|
+
}
|
|
378
413
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
414
|
+
std::shared_ptr<Promise<std::string>>
|
|
415
|
+
send(const std::string &datadir, const std::string &mnemonic,
|
|
416
|
+
const std::string &destination, double amountSat,
|
|
417
|
+
const std::optional<std::string> &comment, bool no_sync) override
|
|
418
|
+
{
|
|
419
|
+
return Promise<std::string>::async([datadir, mnemonic, destination,
|
|
420
|
+
amountSat, comment, no_sync]()
|
|
421
|
+
{
|
|
385
422
|
char *status_c = nullptr;
|
|
386
423
|
const char *comment_c = comment.has_value() ? comment->c_str() : nullptr;
|
|
387
424
|
// NOTE: bark_send in ffi.rs expects u64::MAX if amount is not provided.
|
|
@@ -399,73 +436,82 @@ public:
|
|
|
399
436
|
}
|
|
400
437
|
std::string status_str(status_c);
|
|
401
438
|
bark::bark_free_string(status_c); // Use helper
|
|
402
|
-
return status_str;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
439
|
+
return status_str; });
|
|
440
|
+
}
|
|
405
441
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
442
|
+
std::shared_ptr<Promise<std::string>>
|
|
443
|
+
sendRoundOnchain(const std::string &datadir, const std::string &mnemonic,
|
|
444
|
+
const std::string &destination, double amountSat,
|
|
445
|
+
bool no_sync) override
|
|
446
|
+
{
|
|
447
|
+
return Promise<std::string>::async(
|
|
448
|
+
[datadir, mnemonic, destination, amountSat, no_sync]()
|
|
449
|
+
{
|
|
450
|
+
char *status_c = nullptr;
|
|
451
|
+
bark::bark_BarkError *error = bark::bark_send_round_onchain(
|
|
452
|
+
datadir.c_str(), mnemonic.c_str(), destination.c_str(),
|
|
453
|
+
static_cast<uint64_t>(amountSat), no_sync, &status_c);
|
|
454
|
+
check_bark_error(error);
|
|
455
|
+
if (status_c == nullptr)
|
|
456
|
+
{
|
|
457
|
+
throw std::runtime_error("Bark-cpp error: sendRoundOnchain "
|
|
458
|
+
"returned success but status is null");
|
|
459
|
+
}
|
|
460
|
+
std::string status_str(status_c);
|
|
461
|
+
bark::bark_free_string(status_c); // Use helper
|
|
462
|
+
return status_str;
|
|
463
|
+
});
|
|
464
|
+
}
|
|
426
465
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
ids_c
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
466
|
+
// --- Offboarding / Exiting ---
|
|
467
|
+
|
|
468
|
+
std::shared_ptr<Promise<std::string>>
|
|
469
|
+
offboardSpecific(const std::string &datadir, const std::string &mnemonic,
|
|
470
|
+
const std::vector<std::string> &vtxoIds,
|
|
471
|
+
const std::optional<std::string> &optionalAddress,
|
|
472
|
+
bool no_sync) override
|
|
473
|
+
{
|
|
474
|
+
return Promise<std::string>::async(
|
|
475
|
+
[datadir, mnemonic, vtxoIds, optionalAddress, no_sync]()
|
|
476
|
+
{
|
|
477
|
+
if (vtxoIds.empty())
|
|
478
|
+
{
|
|
479
|
+
throw std::runtime_error(
|
|
480
|
+
"offboardSpecific requires at least one vtxoId");
|
|
481
|
+
}
|
|
482
|
+
std::vector<const char *> ids_c;
|
|
483
|
+
ids_c.reserve(vtxoIds.size());
|
|
484
|
+
for (const auto &id : vtxoIds)
|
|
485
|
+
{
|
|
486
|
+
ids_c.push_back(id.c_str());
|
|
487
|
+
}
|
|
488
|
+
const char *addr_c =
|
|
489
|
+
optionalAddress.has_value() ? optionalAddress->c_str() : nullptr;
|
|
490
|
+
char *status_c = nullptr;
|
|
491
|
+
|
|
492
|
+
bark::bark_BarkError *error = bark::bark_offboard_specific(
|
|
493
|
+
datadir.c_str(), mnemonic.c_str(), ids_c.data(), ids_c.size(),
|
|
494
|
+
addr_c, no_sync, &status_c);
|
|
495
|
+
check_bark_error(error);
|
|
496
|
+
if (status_c == nullptr)
|
|
497
|
+
{
|
|
498
|
+
throw std::runtime_error("Bark-cpp error: offboardSpecific "
|
|
499
|
+
"returned success but status is null");
|
|
500
|
+
}
|
|
501
|
+
std::string status_str(status_c);
|
|
502
|
+
bark::bark_free_string(status_c); // Use helper
|
|
503
|
+
return status_str;
|
|
504
|
+
});
|
|
505
|
+
}
|
|
462
506
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
507
|
+
std::shared_ptr<Promise<std::string>>
|
|
508
|
+
offboardAll(const std::string &datadir, const std::string &mnemonic,
|
|
509
|
+
const std::optional<std::string> &optionalAddress,
|
|
510
|
+
bool no_sync) override
|
|
511
|
+
{
|
|
512
|
+
return Promise<std::string>::async([datadir, mnemonic, optionalAddress,
|
|
513
|
+
no_sync]()
|
|
514
|
+
{
|
|
469
515
|
const char *addr_c =
|
|
470
516
|
optionalAddress.has_value() ? optionalAddress->c_str() : nullptr;
|
|
471
517
|
char *status_c = nullptr;
|
|
@@ -478,15 +524,16 @@ public:
|
|
|
478
524
|
}
|
|
479
525
|
std::string status_str(status_c);
|
|
480
526
|
bark::bark_free_string(status_c); // Use helper
|
|
481
|
-
return status_str;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
527
|
+
return status_str; });
|
|
528
|
+
}
|
|
484
529
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
530
|
+
std::shared_ptr<Promise<std::string>> exitStartSpecific(
|
|
531
|
+
const std::string &datadir, const std::string &mnemonic,
|
|
532
|
+
const std::vector<std::string> &vtxoIds,
|
|
533
|
+
bool no_sync /* Potential C header mismatch noted */) override
|
|
534
|
+
{
|
|
535
|
+
return Promise<std::string>::async([datadir, mnemonic, vtxoIds, no_sync]()
|
|
536
|
+
{
|
|
490
537
|
if (vtxoIds.empty()) {
|
|
491
538
|
throw std::runtime_error(
|
|
492
539
|
"exitStartSpecific requires at least one vtxoId");
|
|
@@ -509,14 +556,15 @@ public:
|
|
|
509
556
|
}
|
|
510
557
|
std::string status_str(status_c);
|
|
511
558
|
bark::bark_free_string(status_c); // Use helper
|
|
512
|
-
return status_str;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
559
|
+
return status_str; });
|
|
560
|
+
}
|
|
515
561
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
562
|
+
std::shared_ptr<Promise<std::string>>
|
|
563
|
+
exitStartAll(const std::string &datadir, const std::string &mnemonic,
|
|
564
|
+
bool no_sync /* Potential C header mismatch noted */) override
|
|
565
|
+
{
|
|
566
|
+
return Promise<std::string>::async([datadir, mnemonic, no_sync]()
|
|
567
|
+
{
|
|
520
568
|
char *status_c = nullptr;
|
|
521
569
|
// Call reflects C header (which might be missing no_sync)
|
|
522
570
|
bark::bark_BarkError *error = bark::bark_exit_start_all(
|
|
@@ -528,14 +576,15 @@ public:
|
|
|
528
576
|
}
|
|
529
577
|
std::string status_str(status_c);
|
|
530
578
|
bark::bark_free_string(status_c); // Use helper
|
|
531
|
-
return status_str;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
579
|
+
return status_str; });
|
|
580
|
+
}
|
|
534
581
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
582
|
+
std::shared_ptr<Promise<std::string>>
|
|
583
|
+
exitProgressOnce(const std::string &datadir,
|
|
584
|
+
const std::string &mnemonic) override
|
|
585
|
+
{
|
|
586
|
+
return Promise<std::string>::async([datadir, mnemonic]()
|
|
587
|
+
{
|
|
539
588
|
char *status_c = nullptr;
|
|
540
589
|
bark::bark_BarkError *error = bark::bark_exit_progress_once(
|
|
541
590
|
datadir.c_str(), mnemonic.c_str(), &status_c);
|
|
@@ -546,13 +595,12 @@ public:
|
|
|
546
595
|
}
|
|
547
596
|
std::string status_str(status_c);
|
|
548
597
|
bark::bark_free_string(status_c); // Use helper
|
|
549
|
-
return status_str;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
598
|
+
return status_str; });
|
|
599
|
+
}
|
|
552
600
|
|
|
553
|
-
private:
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
};
|
|
601
|
+
private:
|
|
602
|
+
// Tag for logging/debugging within Nitro
|
|
603
|
+
static constexpr auto TAG = "NitroArk";
|
|
604
|
+
};
|
|
557
605
|
|
|
558
606
|
} // namespace margelo::nitro::nitroark
|