react-native-nitro-ark 0.0.16 → 0.0.19

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 CHANGED
@@ -53,8 +53,8 @@ namespace margelo::nitro::nitroark
53
53
  }
54
54
 
55
55
  std::shared_ptr<Promise<void>>
56
- createWallet(const std::string &datadir,
57
- const BarkCreateOpts &opts) override
56
+ loadWallet(const std::string &datadir,
57
+ const BarkCreateOpts &opts) override
58
58
  {
59
59
  return Promise<void>::async([datadir, opts]()
60
60
  {
@@ -94,7 +94,6 @@ namespace margelo::nitro::nitroark
94
94
  : nullptr};
95
95
 
96
96
  bark::bark_BarkCreateOpts barkOpts = {
97
- opts.force.value_or(false),
98
97
  opts.regtest.value_or(false),
99
98
  opts.signet.value_or(false),
100
99
  opts.bitcoin.value_or(true),
@@ -105,21 +104,27 @@ namespace margelo::nitro::nitroark
105
104
  config};
106
105
 
107
106
  bark::bark_BarkError *error =
108
- bark::bark_create_wallet(datadir.c_str(), barkOpts);
107
+ bark::bark_load_wallet(datadir.c_str(), barkOpts);
108
+ check_bark_error(error); });
109
+ }
110
+
111
+ std::shared_ptr<Promise<void>> closeWallet() override
112
+ {
113
+ return Promise<void>::async([]()
114
+ {
115
+ bark::bark_BarkError *error = bark::bark_close_wallet();
109
116
  check_bark_error(error); });
110
117
  }
111
118
 
112
119
  // --- Wallet Info ---
113
120
 
114
121
  std::shared_ptr<Promise<BarkBalance>>
115
- getBalance(const std::string &datadir, bool no_sync,
116
- const std::string &mnemonic) override
122
+ getBalance(bool no_sync) override
117
123
  {
118
- return Promise<BarkBalance>::async([datadir, no_sync, mnemonic]()
124
+ return Promise<BarkBalance>::async([no_sync]()
119
125
  {
120
126
  bark::bark_BarkBalance c_balance;
121
- bark::bark_BarkError *error = bark::bark_get_balance(
122
- datadir.c_str(), no_sync, mnemonic.c_str(), &c_balance);
127
+ bark::bark_BarkError *error = bark::bark_get_balance(no_sync, &c_balance);
123
128
  check_bark_error(error);
124
129
 
125
130
  return BarkBalance(static_cast<double>(c_balance.onchain),
@@ -128,14 +133,12 @@ namespace margelo::nitro::nitroark
128
133
  }
129
134
 
130
135
  std::shared_ptr<Promise<std::string>>
131
- getOnchainAddress(const std::string &datadir,
132
- const std::string &mnemonic) override
136
+ getOnchainAddress() override
133
137
  {
134
- return Promise<std::string>::async([datadir, mnemonic]()
138
+ return Promise<std::string>::async([]()
135
139
  {
136
140
  char *address_c = nullptr;
137
- bark::bark_BarkError *error = bark::bark_get_onchain_address(
138
- datadir.c_str(), mnemonic.c_str(), &address_c);
141
+ bark::bark_BarkError *error = bark::bark_get_onchain_address(&address_c);
139
142
  check_bark_error(error);
140
143
  if (address_c == nullptr) {
141
144
  throw std::runtime_error("Bark-cpp error: getOnchainAddress returned "
@@ -147,14 +150,12 @@ namespace margelo::nitro::nitroark
147
150
  }
148
151
 
149
152
  std::shared_ptr<Promise<std::string>>
150
- getOnchainUtxos(const std::string &datadir, const std::string &mnemonic,
151
- bool no_sync) override
153
+ getOnchainUtxos(bool no_sync) override
152
154
  {
153
- return Promise<std::string>::async([datadir, mnemonic, no_sync]()
155
+ return Promise<std::string>::async([no_sync]()
154
156
  {
155
157
  char *json_c = nullptr;
156
- bark::bark_BarkError *error = bark::bark_get_onchain_utxos(
157
- datadir.c_str(), mnemonic.c_str(), no_sync, &json_c);
158
+ bark::bark_BarkError *error = bark::bark_get_onchain_utxos(no_sync, &json_c);
158
159
  check_bark_error(error);
159
160
  if (json_c == nullptr) {
160
161
  throw std::runtime_error("Bark-cpp error: getOnchainUtxos returned "
@@ -166,14 +167,18 @@ namespace margelo::nitro::nitroark
166
167
  }
167
168
 
168
169
  std::shared_ptr<Promise<std::string>>
169
- getVtxoPubkey(const std::string &datadir,
170
- const std::string &mnemonic) override
170
+ getVtxoPubkey(std::optional<double> index) override
171
171
  {
172
- return Promise<std::string>::async([datadir, mnemonic]()
172
+ return Promise<std::string>::async([index]()
173
173
  {
174
174
  char *pubkey_c = nullptr;
175
+ std::optional<uint32_t> index_val;
176
+ if (index.has_value()) {
177
+ index_val = static_cast<uint32_t>(index.value());
178
+ }
179
+
175
180
  bark::bark_BarkError *error = bark::bark_get_vtxo_pubkey(
176
- datadir.c_str(), mnemonic.c_str(), &pubkey_c);
181
+ index_val.has_value() ? &index_val.value() : nullptr, &pubkey_c);
177
182
  check_bark_error(error);
178
183
  if (pubkey_c == nullptr) {
179
184
  throw std::runtime_error("Bark-cpp error: getVtxoPubkey returned "
@@ -184,15 +189,12 @@ namespace margelo::nitro::nitroark
184
189
  return pubkey_str; });
185
190
  }
186
191
 
187
- std::shared_ptr<Promise<std::string>> getVtxos(const std::string &datadir,
188
- const std::string &mnemonic,
189
- bool no_sync) override
192
+ std::shared_ptr<Promise<std::string>> getVtxos(bool no_sync) override
190
193
  {
191
- return Promise<std::string>::async([datadir, mnemonic, no_sync]()
194
+ return Promise<std::string>::async([no_sync]()
192
195
  {
193
196
  char *json_c = nullptr;
194
- bark::bark_BarkError *error = bark::bark_get_vtxos(
195
- datadir.c_str(), mnemonic.c_str(), no_sync, &json_c);
197
+ bark::bark_BarkError *error = bark::bark_get_vtxos(no_sync, &json_c);
196
198
  check_bark_error(error);
197
199
  if (json_c == nullptr) {
198
200
  throw std::runtime_error(
@@ -206,17 +208,14 @@ namespace margelo::nitro::nitroark
206
208
  // --- Onchain Operations ---
207
209
 
208
210
  std::shared_ptr<Promise<std::string>>
209
- sendOnchain(const std::string &datadir, const std::string &mnemonic,
210
- const std::string &destination, double amountSat,
211
+ sendOnchain(const std::string &destination, double amountSat,
211
212
  bool no_sync) override
212
213
  {
213
- return Promise<std::string>::async([datadir, mnemonic, destination,
214
- amountSat, no_sync]()
214
+ return Promise<std::string>::async([destination, amountSat, no_sync]()
215
215
  {
216
216
  char *txid_c = nullptr;
217
217
  bark::bark_BarkError *error = bark::bark_send_onchain(
218
- datadir.c_str(), mnemonic.c_str(), destination.c_str(),
219
- static_cast<uint64_t>(amountSat), no_sync, &txid_c);
218
+ destination.c_str(), static_cast<uint64_t>(amountSat), no_sync, &txid_c);
220
219
  check_bark_error(error);
221
220
  if (txid_c == nullptr) {
222
221
  throw std::runtime_error(
@@ -228,16 +227,14 @@ namespace margelo::nitro::nitroark
228
227
  }
229
228
 
230
229
  std::shared_ptr<Promise<std::string>>
231
- drainOnchain(const std::string &datadir, const std::string &mnemonic,
232
- const std::string &destination, bool no_sync) override
230
+ drainOnchain(const std::string &destination, bool no_sync) override
233
231
  {
234
232
  return Promise<std::string>::async(
235
- [datadir, mnemonic, destination, no_sync]()
233
+ [destination, no_sync]()
236
234
  {
237
235
  char *txid_c = nullptr;
238
236
  bark::bark_BarkError *error =
239
- bark::bark_drain_onchain(datadir.c_str(), mnemonic.c_str(),
240
- destination.c_str(), no_sync, &txid_c);
237
+ bark::bark_drain_onchain(destination.c_str(), no_sync, &txid_c);
241
238
  check_bark_error(error);
242
239
  if (txid_c == nullptr)
243
240
  {
@@ -251,11 +248,10 @@ namespace margelo::nitro::nitroark
251
248
  }
252
249
 
253
250
  std::shared_ptr<Promise<std::string>>
254
- sendManyOnchain(const std::string &datadir, const std::string &mnemonic,
255
- const std::vector<BarkSendManyOutput> &outputs,
251
+ sendManyOnchain(const std::vector<BarkSendManyOutput> &outputs,
256
252
  bool no_sync) override
257
253
  {
258
- return Promise<std::string>::async([datadir, mnemonic, outputs, no_sync]()
254
+ return Promise<std::string>::async([outputs, no_sync]()
259
255
  {
260
256
  size_t num_outputs = outputs.size();
261
257
  if (num_outputs == 0) {
@@ -269,16 +265,13 @@ namespace margelo::nitro::nitroark
269
265
  amounts_c.reserve(num_outputs);
270
266
 
271
267
  for (const auto &output : outputs) {
272
- // --- FIX: Access directly, no .value() ---
273
268
  destinations_c.push_back(output.destination.c_str());
274
269
  amounts_c.push_back(static_cast<uint64_t>(output.amountSat));
275
- // --- End FIX ---
276
270
  }
277
271
 
278
272
  char *txid_c = nullptr;
279
273
  bark::bark_BarkError *error = bark::bark_send_many_onchain(
280
- datadir.c_str(), mnemonic.c_str(), destinations_c.data(),
281
- amounts_c.data(), num_outputs, no_sync, &txid_c);
274
+ destinations_c.data(), amounts_c.data(), num_outputs, no_sync, &txid_c);
282
275
  check_bark_error(error);
283
276
  if (txid_c == nullptr) {
284
277
  throw std::runtime_error("Bark-cpp error: sendManyOnchain returned "
@@ -292,10 +285,9 @@ namespace margelo::nitro::nitroark
292
285
  // --- Ark Operations ---
293
286
 
294
287
  std::shared_ptr<Promise<std::string>>
295
- refreshVtxos(const std::string &datadir, const std::string &mnemonic,
296
- const BarkRefreshOpts &refreshOpts, bool no_sync) override
288
+ refreshVtxos(const BarkRefreshOpts &refreshOpts, bool no_sync) override
297
289
  {
298
- return Promise<std::string>::async([datadir, mnemonic, refreshOpts,
290
+ return Promise<std::string>::async([refreshOpts,
299
291
  no_sync]()
300
292
  {
301
293
  bark::bark_BarkRefreshOpts c_opts;
@@ -356,8 +348,7 @@ namespace margelo::nitro::nitroark
356
348
 
357
349
  // Make the C FFI call
358
350
  char *status_c = nullptr;
359
- bark::bark_BarkError *error = bark::bark_refresh_vtxos(
360
- datadir.c_str(), mnemonic.c_str(), c_opts, no_sync, &status_c);
351
+ bark::bark_BarkError *error = bark::bark_refresh_vtxos(c_opts, no_sync, &status_c);
361
352
 
362
353
  check_bark_error(error);
363
354
  if (status_c == nullptr) {
@@ -371,17 +362,15 @@ namespace margelo::nitro::nitroark
371
362
  return status_str; });
372
363
  }
373
364
 
374
- std::shared_ptr<Promise<std::string>> boardAmount(const std::string &datadir,
375
- const std::string &mnemonic,
376
- double amountSat,
365
+ std::shared_ptr<Promise<std::string>> boardAmount(double amountSat,
377
366
  bool no_sync) override
378
367
  {
379
- return Promise<std::string>::async([datadir, mnemonic, amountSat,
368
+ return Promise<std::string>::async([amountSat,
380
369
  no_sync]()
381
370
  {
382
371
  char *status_c = nullptr;
383
372
  bark::bark_BarkError *error = bark::bark_board_amount(
384
- datadir.c_str(), mnemonic.c_str(), static_cast<uint64_t>(amountSat),
373
+ static_cast<uint64_t>(amountSat),
385
374
  no_sync, &status_c);
386
375
  check_bark_error(error);
387
376
  if (status_c == nullptr) {
@@ -393,15 +382,12 @@ namespace margelo::nitro::nitroark
393
382
  return status_str; });
394
383
  }
395
384
 
396
- std::shared_ptr<Promise<std::string>> boardAll(const std::string &datadir,
397
- const std::string &mnemonic,
398
- bool no_sync) override
385
+ std::shared_ptr<Promise<std::string>> boardAll(bool no_sync) override
399
386
  {
400
- return Promise<std::string>::async([datadir, mnemonic, no_sync]()
387
+ return Promise<std::string>::async([no_sync]()
401
388
  {
402
389
  char *status_c = nullptr;
403
- bark::bark_BarkError *error = bark::bark_board_all(
404
- datadir.c_str(), mnemonic.c_str(), no_sync, &status_c);
390
+ bark::bark_BarkError *error = bark::bark_board_all(no_sync, &status_c);
405
391
  check_bark_error(error);
406
392
  if (status_c == nullptr) {
407
393
  throw std::runtime_error(
@@ -413,22 +399,16 @@ namespace margelo::nitro::nitroark
413
399
  }
414
400
 
415
401
  std::shared_ptr<Promise<std::string>>
416
- send(const std::string &datadir, const std::string &mnemonic,
417
- const std::string &destination, double amountSat,
402
+ send(const std::string &destination, double amountSat,
418
403
  const std::optional<std::string> &comment, bool no_sync) override
419
404
  {
420
- return Promise<std::string>::async([datadir, mnemonic, destination,
405
+ return Promise<std::string>::async([destination,
421
406
  amountSat, comment, no_sync]()
422
407
  {
423
408
  char *status_c = nullptr;
424
409
  const char *comment_c = comment.has_value() ? comment->c_str() : nullptr;
425
- // NOTE: bark_send in ffi.rs expects u64::MAX if amount is not provided.
426
- // Here, amountSat (double) is always passed from TS. If you want to
427
- // support sending MAX, the TS/Nitro interface needs adjustment (e.g.,
428
- // optional amount). Assuming amountSat passed from TS is always the
429
- // intended amount.
430
410
  bark::bark_BarkError *error = bark::bark_send(
431
- datadir.c_str(), mnemonic.c_str(), destination.c_str(),
411
+ destination.c_str(),
432
412
  static_cast<uint64_t>(amountSat), comment_c, no_sync, &status_c);
433
413
  check_bark_error(error);
434
414
  if (status_c == nullptr) {
@@ -441,16 +421,15 @@ namespace margelo::nitro::nitroark
441
421
  }
442
422
 
443
423
  std::shared_ptr<Promise<std::string>>
444
- sendRoundOnchain(const std::string &datadir, const std::string &mnemonic,
445
- const std::string &destination, double amountSat,
424
+ sendRoundOnchain(const std::string &destination, double amountSat,
446
425
  bool no_sync) override
447
426
  {
448
427
  return Promise<std::string>::async(
449
- [datadir, mnemonic, destination, amountSat, no_sync]()
428
+ [destination, amountSat, no_sync]()
450
429
  {
451
430
  char *status_c = nullptr;
452
431
  bark::bark_BarkError *error = bark::bark_send_round_onchain(
453
- datadir.c_str(), mnemonic.c_str(), destination.c_str(),
432
+ destination.c_str(),
454
433
  static_cast<uint64_t>(amountSat), no_sync, &status_c);
455
434
  check_bark_error(error);
456
435
  if (status_c == nullptr)
@@ -467,14 +446,13 @@ namespace margelo::nitro::nitroark
467
446
  // --- Lightning Operations ---
468
447
 
469
448
  std::shared_ptr<Promise<std::string>>
470
- bolt11Invoice(const std::string &datadir, const std::string &mnemonic,
471
- double amountSat) override
449
+ bolt11Invoice(double amountMsat) override
472
450
  {
473
- return Promise<std::string>::async([datadir, mnemonic, amountSat]()
451
+ return Promise<std::string>::async([amountMsat]()
474
452
  {
475
453
  char *invoice_c = nullptr;
476
454
  bark::bark_BarkError *error = bark::bark_bolt11_invoice(
477
- datadir.c_str(), mnemonic.c_str(), static_cast<uint64_t>(amountSat),
455
+ static_cast<uint64_t>(amountMsat),
478
456
  &invoice_c);
479
457
  check_bark_error(error);
480
458
  if (invoice_c == nullptr) {
@@ -487,26 +465,23 @@ namespace margelo::nitro::nitroark
487
465
  }
488
466
 
489
467
  std::shared_ptr<Promise<void>>
490
- claimBolt11Payment(const std::string &datadir, const std::string &mnemonic,
491
- const std::string &bolt11) override
468
+ claimBolt11Payment(const std::string &bolt11) override
492
469
  {
493
- return Promise<void>::async([datadir, mnemonic, bolt11]()
470
+ return Promise<void>::async([bolt11]()
494
471
  {
495
- bark::bark_BarkError *error = bark::bark_claim_bolt11_payment(
496
- datadir.c_str(), mnemonic.c_str(), bolt11.c_str());
472
+ bark::bark_BarkError *error = bark::bark_claim_bolt11_payment(bolt11.c_str());
497
473
  check_bark_error(error); });
498
474
  }
499
475
 
500
476
  // --- Offboarding / Exiting ---
501
477
 
502
478
  std::shared_ptr<Promise<std::string>>
503
- offboardSpecific(const std::string &datadir, const std::string &mnemonic,
504
- const std::vector<std::string> &vtxoIds,
479
+ offboardSpecific(const std::vector<std::string> &vtxoIds,
505
480
  const std::optional<std::string> &optionalAddress,
506
481
  bool no_sync) override
507
482
  {
508
483
  return Promise<std::string>::async(
509
- [datadir, mnemonic, vtxoIds, optionalAddress, no_sync]()
484
+ [vtxoIds, optionalAddress, no_sync]()
510
485
  {
511
486
  if (vtxoIds.empty())
512
487
  {
@@ -524,7 +499,7 @@ namespace margelo::nitro::nitroark
524
499
  char *status_c = nullptr;
525
500
 
526
501
  bark::bark_BarkError *error = bark::bark_offboard_specific(
527
- datadir.c_str(), mnemonic.c_str(), ids_c.data(), ids_c.size(),
502
+ ids_c.data(), ids_c.size(),
528
503
  addr_c, no_sync, &status_c);
529
504
  check_bark_error(error);
530
505
  if (status_c == nullptr)
@@ -539,18 +514,17 @@ namespace margelo::nitro::nitroark
539
514
  }
540
515
 
541
516
  std::shared_ptr<Promise<std::string>>
542
- offboardAll(const std::string &datadir, const std::string &mnemonic,
543
- const std::optional<std::string> &optionalAddress,
517
+ offboardAll(const std::optional<std::string> &optionalAddress,
544
518
  bool no_sync) override
545
519
  {
546
- return Promise<std::string>::async([datadir, mnemonic, optionalAddress,
520
+ return Promise<std::string>::async([optionalAddress,
547
521
  no_sync]()
548
522
  {
549
523
  const char *addr_c =
550
524
  optionalAddress.has_value() ? optionalAddress->c_str() : nullptr;
551
525
  char *status_c = nullptr;
552
526
  bark::bark_BarkError *error = bark::bark_offboard_all(
553
- datadir.c_str(), mnemonic.c_str(), addr_c, no_sync, &status_c);
527
+ addr_c, no_sync, &status_c);
554
528
  check_bark_error(error);
555
529
  if (status_c == nullptr) {
556
530
  throw std::runtime_error(
@@ -562,11 +536,9 @@ namespace margelo::nitro::nitroark
562
536
  }
563
537
 
564
538
  std::shared_ptr<Promise<std::string>> exitStartSpecific(
565
- const std::string &datadir, const std::string &mnemonic,
566
- const std::vector<std::string> &vtxoIds,
567
- bool no_sync /* Potential C header mismatch noted */) override
539
+ const std::vector<std::string> &vtxoIds) override
568
540
  {
569
- return Promise<std::string>::async([datadir, mnemonic, vtxoIds, no_sync]()
541
+ return Promise<std::string>::async([vtxoIds]()
570
542
  {
571
543
  if (vtxoIds.empty()) {
572
544
  throw std::runtime_error(
@@ -579,10 +551,8 @@ namespace margelo::nitro::nitroark
579
551
  }
580
552
  char *status_c = nullptr;
581
553
 
582
- // Call reflects C header (which might be missing no_sync)
583
554
  bark::bark_BarkError *error =
584
- bark::bark_exit_start_specific(datadir.c_str(), mnemonic.c_str(),
585
- ids_c.data(), ids_c.size(), &status_c);
555
+ bark::bark_exit_start_specific(ids_c.data(), ids_c.size(), &status_c);
586
556
  check_bark_error(error);
587
557
  if (status_c == nullptr) {
588
558
  throw std::runtime_error("Bark-cpp error: exitStartSpecific returned "
@@ -594,15 +564,12 @@ namespace margelo::nitro::nitroark
594
564
  }
595
565
 
596
566
  std::shared_ptr<Promise<std::string>>
597
- exitStartAll(const std::string &datadir, const std::string &mnemonic,
598
- bool no_sync /* Potential C header mismatch noted */) override
567
+ exitStartAll() override
599
568
  {
600
- return Promise<std::string>::async([datadir, mnemonic, no_sync]()
569
+ return Promise<std::string>::async([]()
601
570
  {
602
571
  char *status_c = nullptr;
603
- // Call reflects C header (which might be missing no_sync)
604
- bark::bark_BarkError *error = bark::bark_exit_start_all(
605
- datadir.c_str(), mnemonic.c_str(), &status_c);
572
+ bark::bark_BarkError *error = bark::bark_exit_start_all(&status_c);
606
573
  check_bark_error(error);
607
574
  if (status_c == nullptr) {
608
575
  throw std::runtime_error(
@@ -614,14 +581,12 @@ namespace margelo::nitro::nitroark
614
581
  }
615
582
 
616
583
  std::shared_ptr<Promise<std::string>>
617
- exitProgressOnce(const std::string &datadir,
618
- const std::string &mnemonic) override
584
+ exitProgressOnce() override
619
585
  {
620
- return Promise<std::string>::async([datadir, mnemonic]()
586
+ return Promise<std::string>::async([]()
621
587
  {
622
588
  char *status_c = nullptr;
623
- bark::bark_BarkError *error = bark::bark_exit_progress_once(
624
- datadir.c_str(), mnemonic.c_str(), &status_c);
589
+ bark::bark_BarkError *error = bark::bark_exit_progress_once(&status_c);
625
590
  check_bark_error(error);
626
591
  if (status_c == nullptr) {
627
592
  throw std::runtime_error("Bark-cpp error: exitProgressOnce returned "