1
-#include <stdint.h>
2
-#include "cstdlib"
3
-#include <chrono>
4
-#include <functional>
5
-#include <iostream>
6
-#include <unistd.h>
7
-#include <mutex>
8
-#include "thread"
9
-#if __APPLE__
10
-// Fix for randomx on ios
11
-void __clear_cache(void* start, void* end) { }
12
-#include "../External/ios/include/wallet2_api.h"
13
-#else
14
-#include "../External/android/include/wallet2_api.h"
15
-#endif
16
-
17
-using namespace std::chrono_literals;
18
-
19
-#ifdef __cplusplus
20
-extern "C"
21
-{
22
-#endif
23
- const uint64_t MONERO_BLOCK_SIZE = 1000;
24
-
25
- struct Utf8Box
26
- {
27
- char *value;
28
-
29
- Utf8Box(char *_value)
30
- {
31
- value = _value;
32
- }
33
- };
34
-
35
-
36
- struct SubaddressRow
37
- {
38
- uint64_t id;
39
- char *address;
40
- char *label;
41
-
42
- SubaddressRow(std::size_t _id, char *_address, char *_label)
43
- {
44
- id = static_cast<uint64_t>(_id);
45
- address = _address;
46
- label = _label;
47
- }
48
- };
49
-
50
- struct AccountRow
51
- {
52
- uint64_t id;
53
- char *label;
54
-
55
- AccountRow(std::size_t _id, char *_label)
56
- {
57
- id = static_cast<uint64_t>(_id);
58
- label = _label;
59
- }
60
- };
61
-
62
- struct HavenBalance
63
- {
64
- uint64_t amount;
65
- char *assetType;
66
-
67
- HavenBalance(char *_assetType, uint64_t _amount)
68
- {
69
- amount = _amount;
70
- assetType = _assetType;
71
- }
72
- };
73
-
74
- struct HavenRate
75
- {
76
- uint64_t rate;
77
- char *assetType;
78
-
79
- HavenRate(char *_assetType, uint64_t _rate)
80
- {
81
- rate = _rate;
82
- assetType = _assetType;
83
- }
84
- };
85
-
86
- struct MoneroWalletListener : Monero::WalletListener
87
- {
88
- uint64_t m_height;
89
- bool m_need_to_refresh;
90
- bool m_new_transaction;
91
-
92
- MoneroWalletListener()
93
- {
94
- m_height = 0;
95
- m_need_to_refresh = false;
96
- m_new_transaction = false;
97
- }
98
-
99
- void moneySpent(const std::string &txId, uint64_t amount, std::string assetType)
100
- {
101
- m_new_transaction = true;
102
- }
103
-
104
- void moneyReceived(const std::string &txId, uint64_t amount, std::string assetType)
105
- {
106
- m_new_transaction = true;
107
- }
108
-
109
- void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount)
110
- {
111
- m_new_transaction = true;
112
- }
113
-
114
- void newBlock(uint64_t height)
115
- {
116
- m_height = height;
117
- }
118
-
119
- void updated()
120
- {
121
- m_new_transaction = true;
122
- }
123
-
124
- void refreshed()
125
- {
126
- m_need_to_refresh = true;
127
- }
128
-
129
- void resetNeedToRefresh()
130
- {
131
- m_need_to_refresh = false;
132
- }
133
-
134
- bool isNeedToRefresh()
135
- {
136
- return m_need_to_refresh;
137
- }
138
-
139
- bool isNewTransactionExist()
140
- {
141
- return m_new_transaction;
142
- }
143
-
144
- void resetIsNewTransactionExist()
145
- {
146
- m_new_transaction = false;
147
- }
148
-
149
- uint64_t height()
150
- {
151
- return m_height;
152
- }
153
- };
154
-
155
- struct TransactionInfoRow
156
- {
157
- uint64_t amount;
158
- uint64_t fee;
159
- uint64_t blockHeight;
160
- uint64_t confirmations;
161
- uint32_t subaddrAccount;
162
- int8_t direction;
163
- int8_t isPending;
164
- uint32_t subaddrIndex;
165
-
166
- char *hash;
167
- char *paymentId;
168
- char *assetType;
169
-
170
- int64_t datetime;
171
-
172
- TransactionInfoRow(Monero::TransactionInfo *transaction)
173
- {
174
- amount = transaction->amount();
175
- fee = transaction->fee();
176
- blockHeight = transaction->blockHeight();
177
- subaddrAccount = transaction->subaddrAccount();
178
- std::set<uint32_t>::iterator it = transaction->subaddrIndex().begin();
179
- subaddrIndex = *it;
180
- confirmations = transaction->confirmations();
181
- datetime = static_cast<int64_t>(transaction->timestamp());
182
- direction = transaction->direction();
183
- isPending = static_cast<int8_t>(transaction->isPending());
184
- std::string *hash_str = new std::string(transaction->hash());
185
- hash = strdup(hash_str->c_str());
186
- paymentId = strdup(transaction->paymentId().c_str());
187
- assetType = strdup(transaction->assetType().c_str());
188
- }
189
- };
190
-
191
- struct PendingTransactionRaw
192
- {
193
- uint64_t amount;
194
- uint64_t fee;
195
- char *hash;
196
- Monero::PendingTransaction *transaction;
197
-
198
- PendingTransactionRaw(Monero::PendingTransaction *_transaction)
199
- {
200
- transaction = _transaction;
201
- amount = _transaction->amount();
202
- fee = _transaction->fee();
203
- hash = strdup(_transaction->txid()[0].c_str());
204
- }
205
- };
206
-
207
- Monero::Wallet *m_wallet;
208
- Monero::TransactionHistory *m_transaction_history;
209
- MoneroWalletListener *m_listener;
210
- Monero::Subaddress *m_subaddress;
211
- Monero::SubaddressAccount *m_account;
212
- uint64_t m_last_known_wallet_height;
213
- uint64_t m_cached_syncing_blockchain_height = 0;
214
- std::mutex store_lock;
215
- bool is_storing = false;
216
-
217
- void change_current_wallet(Monero::Wallet *wallet)
218
- {
219
- m_wallet = wallet;
220
- m_listener = nullptr;
221
-
222
-
223
- if (wallet != nullptr)
224
- {
225
- m_transaction_history = wallet->history();
226
- }
227
- else
228
- {
229
- m_transaction_history = nullptr;
230
- }
231
-
232
- if (wallet != nullptr)
233
- {
234
- m_account = wallet->subaddressAccount();
235
- }
236
- else
237
- {
238
- m_account = nullptr;
239
- }
240
-
241
- if (wallet != nullptr)
242
- {
243
- m_subaddress = wallet->subaddress();
244
- }
245
- else
246
- {
247
- m_subaddress = nullptr;
248
- }
249
- }
250
-
251
- Monero::Wallet *get_current_wallet()
252
- {
253
- return m_wallet;
254
- }
255
-
256
- bool create_wallet(char *path, char *password, char *language, int32_t networkType, char *error)
257
- {
258
- Monero::WalletManagerFactory::setLogLevel(4);
259
-
260
- Monero::NetworkType _networkType = static_cast<Monero::NetworkType>(networkType);
261
- Monero::WalletManager *walletManager = Monero::WalletManagerFactory::getWalletManager();
262
- Monero::Wallet *wallet = walletManager->createWallet(path, password, language, _networkType);
263
-
264
- int status;
265
- std::string errorString;
266
-
267
- wallet->statusWithErrorString(status, errorString);
268
-
269
- if (wallet->status() != Monero::Wallet::Status_Ok)
270
- {
271
- error = strdup(wallet->errorString().c_str());
272
- return false;
273
- }
274
-
275
- change_current_wallet(wallet);
276
-
277
- return true;
278
- }
279
-
280
- bool restore_wallet_from_seed(char *path, char *password, char *seed, int32_t networkType, uint64_t restoreHeight, char *error)
281
- {
282
- Monero::NetworkType _networkType = static_cast<Monero::NetworkType>(networkType);
283
- Monero::Wallet *wallet = Monero::WalletManagerFactory::getWalletManager()->recoveryWallet(
284
- std::string(path),
285
- std::string(password),
286
- std::string(seed),
287
- _networkType,
288
- (uint64_t)restoreHeight);
289
-
290
- int status;
291
- std::string errorString;
292
-
293
- wallet->statusWithErrorString(status, errorString);
294
-
295
- if (status != Monero::Wallet::Status_Ok || !errorString.empty())
296
- {
297
- error = strdup(errorString.c_str());
298
- return false;
299
- }
300
-
301
- change_current_wallet(wallet);
302
- return true;
303
- }
304
-
305
- bool restore_wallet_from_keys(char *path, char *password, char *language, char *address, char *viewKey, char *spendKey, int32_t networkType, uint64_t restoreHeight, char *error)
306
- {
307
- Monero::NetworkType _networkType = static_cast<Monero::NetworkType>(networkType);
308
- Monero::Wallet *wallet = Monero::WalletManagerFactory::getWalletManager()->createWalletFromKeys(
309
- std::string(path),
310
- std::string(password),
311
- std::string(language),
312
- _networkType,
313
- (uint64_t)restoreHeight,
314
- std::string(address),
315
- std::string(viewKey),
316
- std::string(spendKey));
317
-
318
- int status;
319
- std::string errorString;
320
-
321
- wallet->statusWithErrorString(status, errorString);
322
-
323
- if (status != Monero::Wallet::Status_Ok || !errorString.empty())
324
- {
325
- error = strdup(errorString.c_str());
326
- return false;
327
- }
328
-
329
- change_current_wallet(wallet);
330
- return true;
331
- }
332
-
333
- bool load_wallet(char *path, char *password, int32_t nettype)
334
- {
335
- nice(19);
336
- Monero::NetworkType networkType = static_cast<Monero::NetworkType>(nettype);
337
- Monero::WalletManager *walletManager = Monero::WalletManagerFactory::getWalletManager();
338
- Monero::Wallet *wallet = walletManager->openWallet(std::string(path), std::string(password), networkType);
339
- int status;
340
- std::string errorString;
341
-
342
- wallet->statusWithErrorString(status, errorString);
343
- change_current_wallet(wallet);
344
-
345
- return !(status != Monero::Wallet::Status_Ok || !errorString.empty());
346
- }
347
-
348
- char *error_string() {
349
- return strdup(get_current_wallet()->errorString().c_str());
350
- }
351
-
352
-
353
- bool is_wallet_exist(char *path)
354
- {
355
- return Monero::WalletManagerFactory::getWalletManager()->walletExists(std::string(path));
356
- }
357
-
358
- void close_current_wallet()
359
- {
360
- Monero::WalletManagerFactory::getWalletManager()->closeWallet(get_current_wallet());
361
- change_current_wallet(nullptr);
362
- }
363
-
364
- char *get_filename()
365
- {
366
- return strdup(get_current_wallet()->filename().c_str());
367
- }
368
-
369
- char *secret_view_key()
370
- {
371
- return strdup(get_current_wallet()->secretViewKey().c_str());
372
- }
373
-
374
- char *public_view_key()
375
- {
376
- return strdup(get_current_wallet()->publicViewKey().c_str());
377
- }
378
-
379
- char *secret_spend_key()
380
- {
381
- return strdup(get_current_wallet()->secretSpendKey().c_str());
382
- }
383
-
384
- char *public_spend_key()
385
- {
386
- return strdup(get_current_wallet()->publicSpendKey().c_str());
387
- }
388
-
389
- char *get_address(uint32_t account_index, uint32_t address_index)
390
- {
391
- return strdup(get_current_wallet()->address(account_index, address_index).c_str());
392
- }
393
-
394
-
395
- const char *seed()
396
- {
397
- return strdup(get_current_wallet()->seed().c_str());
398
- }
399
-
400
- int64_t *get_full_balance(uint32_t account_index)
401
- {
402
- std::map<std::string, uint64_t> accountBalance;
403
- std::map<uint32_t, std::map<std::string, uint64_t>> balanceSubaddresses = get_current_wallet()->balance(account_index);
404
- std::vector<std::string> assetList = Monero::Assets::list();
405
- //prefill balances
406
- for (const auto &asset_type : assetList) {
407
-
408
- accountBalance[asset_type] = 0;
409
- }
410
- // balances are mapped to their subaddress
411
- // we compute total balances of account
412
- for (auto const& balanceSubaddress : balanceSubaddresses)
413
- {
414
-
415
- std::map<std::string, uint64_t> balanceOfSubaddress = balanceSubaddress.second;
416
-
417
- for (auto const& balance : balanceOfSubaddress)
418
- {
419
-
420
- const std::string &assetType = balance.first;
421
- const uint64_t &amount = balance.second;
422
- accountBalance[assetType] +=amount;
423
- }
424
- }
425
-
426
- size_t size = accountBalance.size();
427
- int64_t *balanceAddresses = (int64_t *)malloc(size * sizeof(int64_t));
428
- int i = 0;
429
-
430
- for (auto const& balance : accountBalance)
431
- {
432
- char *assetType = strdup(balance.first.c_str());
433
- HavenBalance *hb = new HavenBalance(assetType, balance.second);
434
- balanceAddresses[i] = reinterpret_cast<int64_t>(hb);
435
- i++;
436
- }
437
- return balanceAddresses;
438
- }
439
-
440
- int64_t *get_unlocked_balance(uint32_t account_index)
441
- {
442
- std::map<std::string, uint64_t> accountBalance;
443
- std::map<uint32_t, std::map<std::string, uint64_t>> balanceSubaddresses = get_current_wallet()->unlockedBalance(account_index);
444
- std::vector<std::string> assetList = Monero::Assets::list();
445
-
446
- //prefill balances
447
- for (const auto &asset_type : assetList) {
448
-
449
- accountBalance[asset_type] = 0;
450
- }
451
- // balances are mapped to their subaddress
452
- // we compute total balances of account
453
- for (auto const& balanceSubaddress : balanceSubaddresses)
454
- {
455
-
456
- std::map<std::string, uint64_t> balanceOfSubaddress = balanceSubaddress.second;
457
-
458
- for (auto const& balance : balanceOfSubaddress)
459
- {
460
-
461
- const std::string &assetType = balance.first;
462
- const uint64_t &amount = balance.second;
463
- accountBalance[assetType] +=amount;
464
- }
465
- }
466
-
467
- size_t size = accountBalance.size();
468
- int64_t *balanceAddresses = (int64_t *)malloc(size * sizeof(int64_t));
469
- int i = 0;
470
-
471
- for (auto const& balance : accountBalance)
472
- {
473
- char *assetType = strdup(balance.first.c_str());
474
- HavenBalance *hb = new HavenBalance(assetType, balance.second);
475
- balanceAddresses[i] = reinterpret_cast<int64_t>(hb);
476
- i++;
477
- }
478
- return balanceAddresses;
479
- }
480
-
481
- uint64_t get_current_height()
482
- {
483
- return get_current_wallet()->blockChainHeight();
484
- }
485
-
486
- uint64_t get_node_height()
487
- {
488
- return get_current_wallet()->daemonBlockChainHeight();
489
- }
490
-
491
- bool connect_to_node(char *error)
492
- {
493
- nice(19);
494
- bool is_connected = get_current_wallet()->connectToDaemon();
495
-
496
- if (!is_connected)
497
- {
498
- error = strdup(get_current_wallet()->errorString().c_str());
499
- }
500
-
501
- return is_connected;
502
- }
503
-
504
- bool setup_node(char *address, char *login, char *password, bool use_ssl, bool is_light_wallet, char *error)
505
- {
506
- nice(19);
507
- Monero::Wallet *wallet = get_current_wallet();
508
-
509
- std::string _login = "";
510
- std::string _password = "";
511
-
512
- if (login != nullptr)
513
- {
514
- _login = std::string(login);
515
- }
516
-
517
- if (password != nullptr)
518
- {
519
- _password = std::string(password);
520
- }
521
-
522
- bool inited = wallet->init(std::string(address), 0, _login, _password, use_ssl, is_light_wallet);
523
-
524
- if (!inited)
525
- {
526
- error = strdup(wallet->errorString().c_str());
527
- } else if (!wallet->connectToDaemon()) {
528
- error = strdup(wallet->errorString().c_str());
529
- }
530
-
531
- return inited;
532
- }
533
-
534
- bool is_connected()
535
- {
536
- return get_current_wallet()->connected();
537
- }
538
-
539
- void start_refresh()
540
- {
541
- get_current_wallet()->refreshAsync();
542
- get_current_wallet()->startRefresh();
543
- }
544
-
545
- void set_refresh_from_block_height(uint64_t height)
546
- {
547
- get_current_wallet()->setRefreshFromBlockHeight(height);
548
- }
549
-
550
- void set_recovering_from_seed(bool is_recovery)
551
- {
552
- get_current_wallet()->setRecoveringFromSeed(is_recovery);
553
- }
554
-
555
- void store(char *path)
556
- {
557
- store_lock.lock();
558
- if (is_storing) {
559
- return;
560
- }
561
-
562
- is_storing = true;
563
- get_current_wallet()->store(std::string(path));
564
- is_storing = false;
565
- store_lock.unlock();
566
- }
567
-
568
- bool set_password(char *password, Utf8Box &error) {
569
- bool is_changed = get_current_wallet()->setPassword(std::string(password));
570
-
571
- if (!is_changed) {
572
- error = Utf8Box(strdup(get_current_wallet()->errorString().c_str()));
573
- }
574
-
575
- return is_changed;
576
- }
577
-
578
- bool transaction_create(char *address, char *asset_type, char *payment_id, char *amount,
579
- uint8_t priority_raw, uint32_t subaddr_account, Utf8Box &error, PendingTransactionRaw &pendingTransaction)
580
- {
581
- nice(19);
582
-
583
- auto priority = static_cast<Monero::PendingTransaction::Priority>(priority_raw);
584
- std::string _payment_id;
585
- Monero::PendingTransaction *transaction;
586
-
587
- if (payment_id != nullptr)
588
- {
589
- _payment_id = std::string(payment_id);
590
- }
591
-
592
- if (amount != nullptr)
593
- {
594
- uint64_t _amount = Monero::Wallet::amountFromString(std::string(amount));
595
- transaction = m_wallet->createTransaction(std::string(address), _payment_id, _amount, std::string(asset_type), std::string(asset_type), m_wallet->defaultMixin(), priority, subaddr_account, {});
596
- }
597
- else
598
- {
599
- transaction = m_wallet->createTransaction(std::string(address), _payment_id, Monero::optional<uint64_t>(),std::string(asset_type), std::string(asset_type), m_wallet->defaultMixin(), priority, subaddr_account, {});
600
- }
601
-
602
- int status = transaction->status();
603
-
604
- if (status == Monero::PendingTransaction::Status::Status_Error || status == Monero::PendingTransaction::Status::Status_Critical)
605
- {
606
- error = Utf8Box(strdup(transaction->errorString().c_str()));
607
- return false;
608
- }
609
-
610
- if (m_listener != nullptr) {
611
- m_listener->m_new_transaction = true;
612
- }
613
-
614
- pendingTransaction = PendingTransactionRaw(transaction);
615
- return true;
616
- }
617
-
618
- bool transaction_create_mult_dest(char **addresses, char *asset_type, char *payment_id, char **amounts, uint32_t size,
619
- uint8_t priority_raw, uint32_t subaddr_account, Utf8Box &error, PendingTransactionRaw &pendingTransaction)
620
- {
621
- nice(19);
622
-
623
- std::vector<std::string> _addresses;
624
- std::vector<uint64_t> _amounts;
625
-
626
- for (int i = 0; i < size; i++) {
627
- _addresses.push_back(std::string(*addresses));
628
- _amounts.push_back(Monero::Wallet::amountFromString(std::string(*amounts)));
629
- addresses++;
630
- amounts++;
631
- }
632
-
633
- auto priority = static_cast<Monero::PendingTransaction::Priority>(priority_raw);
634
- std::string _payment_id;
635
- Monero::PendingTransaction *transaction;
636
-
637
- if (payment_id != nullptr)
638
- {
639
- _payment_id = std::string(payment_id);
640
- }
641
-
642
- transaction = m_wallet->createTransactionMultDest(_addresses, _payment_id, _amounts,
643
- std::string(asset_type), std::string(asset_type), m_wallet->defaultMixin(), priority, subaddr_account,{});
644
-
645
- int status = transaction->status();
646
-
647
- if (status == Monero::PendingTransaction::Status::Status_Error || status == Monero::PendingTransaction::Status::Status_Critical)
648
- {
649
- error = Utf8Box(strdup(transaction->errorString().c_str()));
650
- return false;
651
- }
652
-
653
- if (m_listener != nullptr) {
654
- m_listener->m_new_transaction = true;
655
- }
656
-
657
- pendingTransaction = PendingTransactionRaw(transaction);
658
- return true;
659
- }
660
-
661
- bool transaction_commit(PendingTransactionRaw *transaction, Utf8Box &error)
662
- {
663
- bool committed = transaction->transaction->commit();
664
-
665
- if (!committed)
666
- {
667
- error = Utf8Box(strdup(transaction->transaction->errorString().c_str()));
668
- } else if (m_listener != nullptr) {
669
- m_listener->m_new_transaction = true;
670
- }
671
-
672
- return committed;
673
- }
674
-
675
- uint64_t get_node_height_or_update(uint64_t base_eight)
676
- {
677
- if (m_cached_syncing_blockchain_height < base_eight) {
678
- m_cached_syncing_blockchain_height = base_eight;
679
- }
680
-
681
- return m_cached_syncing_blockchain_height;
682
- }
683
-
684
- uint64_t get_syncing_height()
685
- {
686
- if (m_listener == nullptr) {
687
- return 0;
688
- }
689
-
690
- uint64_t height = m_listener->height();
691
-
692
- if (height <= 1) {
693
- return 0;
694
- }
695
-
696
- if (height != m_last_known_wallet_height)
697
- {
698
- m_last_known_wallet_height = height;
699
- }
700
-
701
- return height;
702
- }
703
-
704
- uint64_t is_needed_to_refresh()
705
- {
706
- if (m_listener == nullptr) {
707
- return false;
708
- }
709
-
710
- bool should_refresh = m_listener->isNeedToRefresh();
711
-
712
- if (should_refresh) {
713
- m_listener->resetNeedToRefresh();
714
- }
715
-
716
- return should_refresh;
717
- }
718
-
719
- uint8_t is_new_transaction_exist()
720
- {
721
- if (m_listener == nullptr) {
722
- return false;
723
- }
724
-
725
- bool is_new_transaction_exist = m_listener->isNewTransactionExist();
726
-
727
- if (is_new_transaction_exist)
728
- {
729
- m_listener->resetIsNewTransactionExist();
730
- }
731
-
732
- return is_new_transaction_exist;
733
- }
734
-
735
- void set_listener()
736
- {
737
- m_last_known_wallet_height = 0;
738
-
739
- if (m_listener != nullptr)
740
- {
741
- free(m_listener);
742
- }
743
-
744
- m_listener = new MoneroWalletListener();
745
- get_current_wallet()->setListener(m_listener);
746
- }
747
-
748
- int64_t *subaddrress_get_all()
749
- {
750
- std::vector<Monero::SubaddressRow *> _subaddresses = m_subaddress->getAll();
751
- size_t size = _subaddresses.size();
752
- int64_t *subaddresses = (int64_t *)malloc(size * sizeof(int64_t));
753
-
754
- for (int i = 0; i < size; i++)
755
- {
756
- Monero::SubaddressRow *row = _subaddresses[i];
757
- SubaddressRow *_row = new SubaddressRow(row->getRowId(), strdup(row->getAddress().c_str()), strdup(row->getLabel().c_str()));
758
- subaddresses[i] = reinterpret_cast<int64_t>(_row);
759
- }
760
-
761
- return subaddresses;
762
- }
763
-
764
- int32_t subaddrress_size()
765
- {
766
- std::vector<Monero::SubaddressRow *> _subaddresses = m_subaddress->getAll();
767
- return _subaddresses.size();
768
- }
769
-
770
- void subaddress_add_row(uint32_t accountIndex, char *label)
771
- {
772
- m_subaddress->addRow(accountIndex, std::string(label));
773
- }
774
-
775
- void subaddress_set_label(uint32_t accountIndex, uint32_t addressIndex, char *label)
776
- {
777
- m_subaddress->setLabel(accountIndex, addressIndex, std::string(label));
778
- }
779
-
780
- void subaddress_refresh(uint32_t accountIndex)
781
- {
782
- m_subaddress->refresh(accountIndex);
783
- }
784
-
785
- int32_t account_size()
786
- {
787
- std::vector<Monero::SubaddressAccountRow *> _accocunts = m_account->getAll();
788
- return _accocunts.size();
789
- }
790
-
791
- int64_t *account_get_all()
792
- {
793
- std::vector<Monero::SubaddressAccountRow *> _accocunts = m_account->getAll();
794
- size_t size = _accocunts.size();
795
- int64_t *accocunts = (int64_t *)malloc(size * sizeof(int64_t));
796
-
797
- for (int i = 0; i < size; i++)
798
- {
799
- Monero::SubaddressAccountRow *row = _accocunts[i];
800
- AccountRow *_row = new AccountRow(row->getRowId(), strdup(row->getLabel().c_str()));
801
- accocunts[i] = reinterpret_cast<int64_t>(_row);
802
- }
803
-
804
- return accocunts;
805
- }
806
-
807
- void account_add_row(char *label)
808
- {
809
- m_account->addRow(std::string(label));
810
- }
811
-
812
- void account_set_label_row(uint32_t account_index, char *label)
813
- {
814
- m_account->setLabel(account_index, label);
815
- }
816
-
817
- void account_refresh()
818
- {
819
- m_account->refresh();
820
- }
821
-
822
- int64_t *transactions_get_all()
823
- {
824
- std::vector<Monero::TransactionInfo *> transactions = m_transaction_history->getAll();
825
- size_t size = transactions.size();
826
- int64_t *transactionAddresses = (int64_t *)malloc(size * sizeof(int64_t));
827
-
828
- for (int i = 0; i < size; i++)
829
- {
830
- Monero::TransactionInfo *row = transactions[i];
831
- TransactionInfoRow *tx = new TransactionInfoRow(row);
832
- transactionAddresses[i] = reinterpret_cast<int64_t>(tx);
833
- }
834
-
835
- return transactionAddresses;
836
- }
837
-
838
- void transactions_refresh()
839
- {
840
- m_transaction_history->refresh();
841
- }
842
-
843
- int64_t transactions_count()
844
- {
845
- return m_transaction_history->count();
846
- }
847
-
848
- int LedgerExchange(
849
- unsigned char *command,
850
- unsigned int cmd_len,
851
- unsigned char *response,
852
- unsigned int max_resp_len)
853
- {
854
- return -1;
855
- }
856
-
857
- int LedgerFind(char *buffer, size_t len)
858
- {
859
- return -1;
860
- }
861
-
862
- void on_startup()
863
- {
864
- Monero::Utils::onStartup();
865
- Monero::WalletManagerFactory::setLogLevel(4);
866
- }
867
-
868
- void rescan_blockchain()
869
- {
870
- m_wallet->rescanBlockchainAsync();
871
- }
872
-
873
- char * get_tx_key(char * txId)
874
- {
875
- return strdup(m_wallet->getTxKey(std::string(txId)).c_str());
876
- }
877
-
878
- int32_t asset_types_size()
879
- {
880
- return Monero::Assets::list().size();
881
- }
882
-
883
- char **asset_types()
884
- {
885
- size_t size = Monero::Assets::list().size();
886
- std::vector<std::string> assetList = Monero::Assets::list();
887
- char **assetTypesPts;
888
- assetTypesPts = (char **) malloc( size * sizeof(char*));
889
-
890
- for (int i = 0; i < size; i++)
891
- {
892
-
893
- std::string asset = assetList[i];
894
- //assetTypes[i] = (char *)malloc( 5 * sizeof(char));
895
- assetTypesPts[i] = strdup(asset.c_str());
896
- }
897
-
898
- return assetTypesPts;
899
- }
900
-
901
- std::map<std::string, uint64_t> rates;
902
-
903
- void update_rate()
904
- {
905
- rates = get_current_wallet()->oracleRates();
906
- }
907
-
908
- int64_t *get_rate()
909
- {
910
- size_t size = rates.size();
911
- int64_t *havenRates = (int64_t *)malloc(size * sizeof(int64_t));
912
- int i = 0;
913
-
914
- for (auto const& rate : rates)
915
- {
916
- char *assetType = strdup(rate.first.c_str());
917
- HavenRate *havenRate = new HavenRate(assetType, rate.second);
918
- havenRates[i] = reinterpret_cast<int64_t>(havenRate);
919
- i++;
920
- }
921
-
922
- return havenRates;
923
- }
924
-
925
- int32_t size_of_rate()
926
- {
927
- return static_cast<int32_t>(rates.size());
928
- }
929
-
930
- void set_trusted_daemon(bool arg)
931
- {
932
- m_wallet->setTrustedDaemon(arg);
933
- }
934
-
935
- bool trusted_daemon()
936
- {
937
- return m_wallet->trustedDaemon();
938
- }
939
-
940
-#ifdef __cplusplus
941
-}
942
-#endif