-
Notifications
You must be signed in to change notification settings - Fork 28
/
monero_wallet_full.cpp
3874 lines (3343 loc) · 183 KB
/
monero_wallet_full.cpp
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) woodser
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Parts of this file are originally copyright (c) 2014-2019, The Monero Project
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* All rights reserved.
*
* 1. Redistributions of source code must retain the above copyright notice, this std::list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this std::list
* of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
*/
#include "monero_wallet_full.h"
#ifdef WIN32_LEAN_AND_MEAN
#include <boost/locale.hpp>
#include <boost/filesystem.hpp>
#include <thread>
#endif
#include "utils/monero_utils.h"
#include <chrono>
#include <iostream>
#include "mnemonics/electrum-words.h"
#include "mnemonics/english.h"
#include "wallet/wallet_rpc_server_commands_defs.h"
#include "serialization/binary_utils.h"
#include "serialization/string.h"
#include "common/threadpool.h"
using namespace tools;
/**
* Implements a monero_wallet.h by wrapping wallet2.h.
*/
namespace monero {
// ------------------------- INITIALIZE CONSTANTS ---------------------------
static const int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 1000 * 30; // default connection timeout 30 sec
static const bool STRICT_ = false; // relies exclusively on blockchain data if true, includes local wallet data if false TODO: good use case to expose externally? (note: cannot use `STRICT` due to namespace collision on Windows)
// ----------------------- INTERNAL PRIVATE HELPERS -----------------------
struct key_image_list
{
std::list<std::string> key_images;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(key_images)
END_KV_SERIALIZE_MAP()
};
/**
* Remove query criteria which require looking up other transfers/outputs to
* fulfill query.
*
* @param query the query to decontextualize
* @return a reference to the query for convenience
*/
std::shared_ptr<monero_tx_query> decontextualize(std::shared_ptr<monero_tx_query> query) {
query->m_is_incoming = boost::none;
query->m_is_outgoing = boost::none;
query->m_transfer_query = boost::none;
query->m_input_query = boost::none;
query->m_output_query = boost::none;
return query;
}
bool is_contextual(const monero_transfer_query& query) {
if (query.m_tx_query == boost::none) return false;
if (query.m_tx_query.get()->m_is_incoming != boost::none) return true; // requires context of all transfers
if (query.m_tx_query.get()->m_is_outgoing != boost::none) return true;
if (query.m_tx_query.get()->m_input_query != boost::none) return true; // requires context of inputs
if (query.m_tx_query.get()->m_output_query != boost::none) return true; // requires context of outputs
return false;
}
bool is_contextual(const monero_output_query& query) {
if (query.m_tx_query == boost::none) return false;
if (query.m_tx_query.get()->m_is_incoming != boost::none) return true; // requires context of all transfers
if (query.m_tx_query.get()->m_is_outgoing != boost::none) return true;
if (query.m_tx_query.get()->m_transfer_query != boost::none) return true; // requires context of transfers
return false;
}
bool bool_equals(bool val, const boost::optional<bool>& opt_val) {
return opt_val == boost::none ? false : val == *opt_val;
}
// compute m_num_confirmations TODO monero-project: this logic is based on wallet_rpc_server.cpp `set_confirmations` but it should be encapsulated in wallet2
void set_num_confirmations(std::shared_ptr<monero_tx_wallet>& tx, uint64_t blockchain_height) {
std::shared_ptr<monero_block>& block = tx->m_block.get();
if (block->m_height.get() >= blockchain_height || (block->m_height.get() == 0 && !tx->m_in_tx_pool.get())) tx->m_num_confirmations = 0;
else tx->m_num_confirmations = blockchain_height - block->m_height.get();
}
// compute m_num_suggested_confirmations TODO monero-project: this logic is based on wallet_rpc_server.cpp `set_confirmations` but it should be encapsulated in wallet2
void set_num_suggested_confirmations(std::shared_ptr<monero_incoming_transfer>& incoming_transfer, uint64_t blockchain_height, uint64_t block_reward, uint64_t unlock_time) {
if (block_reward == 0) incoming_transfer->m_num_suggested_confirmations = 0;
else incoming_transfer->m_num_suggested_confirmations = (incoming_transfer->m_amount.get() + block_reward - 1) / block_reward;
if (unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER) {
if (unlock_time > blockchain_height) incoming_transfer->m_num_suggested_confirmations = std::max(incoming_transfer->m_num_suggested_confirmations.get(), unlock_time - blockchain_height);
} else {
const uint64_t now = time(NULL);
if (unlock_time > now) incoming_transfer->m_num_suggested_confirmations = std::max(incoming_transfer->m_num_suggested_confirmations.get(), (unlock_time - now + DIFFICULTY_TARGET_V2 - 1) / DIFFICULTY_TARGET_V2);
}
}
std::shared_ptr<monero_tx_wallet> build_tx_with_incoming_transfer(tools::wallet2& m_w2, uint64_t height, const crypto::hash &payment_id, const tools::wallet2::payment_details &pd) {
// construct block
std::shared_ptr<monero_block> block = std::make_shared<monero_block>();
block->m_height = pd.m_block_height;
block->m_timestamp = pd.m_timestamp;
// construct tx
std::shared_ptr<monero_tx_wallet> tx = std::make_shared<monero_tx_wallet>();
tx->m_block = block;
block->m_txs.push_back(tx);
tx->m_hash = epee::string_tools::pod_to_hex(pd.m_tx_hash);
tx->m_is_incoming = true;
tx->m_payment_id = epee::string_tools::pod_to_hex(payment_id);
if (tx->m_payment_id->substr(16).find_first_not_of('0') == std::string::npos) tx->m_payment_id = tx->m_payment_id->substr(0, 16); // TODO monero-project: this should be part of core wallet
if (tx->m_payment_id == monero_tx::DEFAULT_PAYMENT_ID) tx->m_payment_id = boost::none; // clear default payment id
tx->m_unlock_time = pd.m_unlock_time;
tx->m_is_locked = !m_w2.is_transfer_unlocked(pd.m_unlock_time, pd.m_block_height);
tx->m_fee = pd.m_fee;
tx->m_note = m_w2.get_tx_note(pd.m_tx_hash);
if (tx->m_note->empty()) tx->m_note = boost::none; // clear empty note
tx->m_is_miner_tx = pd.m_coinbase ? true : false;
tx->m_is_confirmed = true;
tx->m_is_failed = false;
tx->m_is_relayed = true;
tx->m_in_tx_pool = false;
tx->m_relay = true;
tx->m_is_double_spend_seen = false;
set_num_confirmations(tx, height);
// construct transfer
std::shared_ptr<monero_incoming_transfer> incoming_transfer = std::make_shared<monero_incoming_transfer>();
incoming_transfer->m_tx = tx;
tx->m_incoming_transfers.push_back(incoming_transfer);
incoming_transfer->m_amount = pd.m_amount;
incoming_transfer->m_account_index = pd.m_subaddr_index.major;
incoming_transfer->m_subaddress_index = pd.m_subaddr_index.minor;
incoming_transfer->m_address = m_w2.get_subaddress_as_str(pd.m_subaddr_index);
set_num_suggested_confirmations(incoming_transfer, height, m_w2.get_last_block_reward(), pd.m_unlock_time);
// return pointer to new tx
return tx;
}
std::shared_ptr<monero_tx_wallet> build_tx_with_outgoing_transfer(tools::wallet2& m_w2, uint64_t height, const crypto::hash &txid, const tools::wallet2::confirmed_transfer_details &pd) {
// construct block
std::shared_ptr<monero_block> block = std::make_shared<monero_block>();
block->m_height = pd.m_block_height;
block->m_timestamp = pd.m_timestamp;
// construct tx
std::shared_ptr<monero_tx_wallet> tx = std::make_shared<monero_tx_wallet>();
tx->m_block = block;
block->m_txs.push_back(tx);
tx->m_hash = epee::string_tools::pod_to_hex(txid);
tx->m_is_outgoing = true;
tx->m_payment_id = epee::string_tools::pod_to_hex(pd.m_payment_id);
if (tx->m_payment_id->substr(16).find_first_not_of('0') == std::string::npos) tx->m_payment_id = tx->m_payment_id->substr(0, 16); // TODO monero-project: this should be part of core wallet
if (tx->m_payment_id == monero_tx::DEFAULT_PAYMENT_ID) tx->m_payment_id = boost::none; // clear default payment id
tx->m_unlock_time = pd.m_unlock_time;
tx->m_is_locked = !m_w2.is_transfer_unlocked(pd.m_unlock_time, pd.m_block_height);
tx->m_fee = pd.m_amount_in - pd.m_amount_out;
tx->m_note = m_w2.get_tx_note(txid);
if (tx->m_note->empty()) tx->m_note = boost::none; // clear empty note
tx->m_is_miner_tx = false;
tx->m_is_confirmed = true;
tx->m_is_failed = false;
tx->m_is_relayed = true;
tx->m_in_tx_pool = false;
tx->m_relay = true;
tx->m_is_double_spend_seen = false;
set_num_confirmations(tx, height);
// construct transfer
std::shared_ptr<monero_outgoing_transfer> outgoing_transfer = std::make_shared<monero_outgoing_transfer>();
outgoing_transfer->m_tx = tx;
tx->m_outgoing_transfer = outgoing_transfer;
uint64_t change = pd.m_change == (uint64_t)-1 ? 0 : pd.m_change; // change may not be known
outgoing_transfer->m_amount = pd.m_amount_in - change - *tx->m_fee;
outgoing_transfer->m_account_index = pd.m_subaddr_account;
std::vector<uint32_t> subaddress_indices;
std::vector<std::string> addresses;
for (uint32_t i: pd.m_subaddr_indices) {
subaddress_indices.push_back(i);
addresses.push_back(m_w2.get_subaddress_as_str({pd.m_subaddr_account, i}));
}
outgoing_transfer->m_subaddress_indices = subaddress_indices;
outgoing_transfer->m_addresses = addresses;
// initialize destinations
for (const auto &d: pd.m_dests) {
std::shared_ptr<monero_destination> destination = std::make_shared<monero_destination>();
destination->m_amount = d.amount;
destination->m_address = d.address(m_w2.nettype(), pd.m_payment_id);
outgoing_transfer->m_destinations.push_back(destination);
}
// replace transfer amount with destination sum
// TODO monero-project: confirmed tx from/to same account has amount 0 but cached transfer destinations
if (*outgoing_transfer->m_amount == 0 && !outgoing_transfer->m_destinations.empty()) {
uint64_t amount = 0;
for (const std::shared_ptr<monero_destination>& destination : outgoing_transfer->m_destinations) amount += *destination->m_amount;
outgoing_transfer->m_amount = amount;
}
// return pointer to new tx
return tx;
}
std::shared_ptr<monero_tx_wallet> build_tx_with_incoming_transfer_unconfirmed(const tools::wallet2& m_w2, uint64_t height, const crypto::hash &payment_id, const tools::wallet2::pool_payment_details &ppd) {
// construct tx
const tools::wallet2::payment_details &pd = ppd.m_pd;
std::shared_ptr<monero_tx_wallet> tx = std::make_shared<monero_tx_wallet>();
tx->m_hash = epee::string_tools::pod_to_hex(pd.m_tx_hash);
tx->m_is_incoming = true;
tx->m_payment_id = epee::string_tools::pod_to_hex(payment_id);
if (tx->m_payment_id->substr(16).find_first_not_of('0') == std::string::npos) tx->m_payment_id = tx->m_payment_id->substr(0, 16); // TODO monero-project: this should be part of core wallet
if (tx->m_payment_id == monero_tx::DEFAULT_PAYMENT_ID) tx->m_payment_id = boost::none; // clear default payment id
tx->m_unlock_time = pd.m_unlock_time;
tx->m_is_locked = true;
tx->m_fee = pd.m_fee;
tx->m_note = m_w2.get_tx_note(pd.m_tx_hash);
if (tx->m_note->empty()) tx->m_note = boost::none; // clear empty note
tx->m_is_miner_tx = false;
tx->m_is_confirmed = false;
tx->m_is_failed = false;
tx->m_is_relayed = true;
tx->m_in_tx_pool = true;
tx->m_relay = true;
tx->m_is_double_spend_seen = ppd.m_double_spend_seen;
tx->m_num_confirmations = 0;
// construct transfer
std::shared_ptr<monero_incoming_transfer> incoming_transfer = std::make_shared<monero_incoming_transfer>();
incoming_transfer->m_tx = tx;
tx->m_incoming_transfers.push_back(incoming_transfer);
incoming_transfer->m_amount = pd.m_amount;
incoming_transfer->m_account_index = pd.m_subaddr_index.major;
incoming_transfer->m_subaddress_index = pd.m_subaddr_index.minor;
incoming_transfer->m_address = m_w2.get_subaddress_as_str(pd.m_subaddr_index);
set_num_suggested_confirmations(incoming_transfer, height, m_w2.get_last_block_reward(), pd.m_unlock_time);
// return pointer to new tx
return tx;
}
std::shared_ptr<monero_tx_wallet> build_tx_with_outgoing_transfer_unconfirmed(const tools::wallet2& m_w2, const crypto::hash &txid, const tools::wallet2::unconfirmed_transfer_details &pd) {
// construct tx
std::shared_ptr<monero_tx_wallet> tx = std::make_shared<monero_tx_wallet>();
tx->m_is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed;
tx->m_hash = epee::string_tools::pod_to_hex(txid);
tx->m_is_outgoing = true;
tx->m_payment_id = epee::string_tools::pod_to_hex(pd.m_payment_id);
if (tx->m_payment_id->substr(16).find_first_not_of('0') == std::string::npos) tx->m_payment_id = tx->m_payment_id->substr(0, 16); // TODO monero-project: this should be part of core wallet
if (tx->m_payment_id == monero_tx::DEFAULT_PAYMENT_ID) tx->m_payment_id = boost::none; // clear default payment id
tx->m_unlock_time = pd.m_tx.unlock_time;
tx->m_is_locked = true;
tx->m_fee = pd.m_amount_in - pd.m_amount_out;
tx->m_note = m_w2.get_tx_note(txid);
if (tx->m_note->empty()) tx->m_note = boost::none; // clear empty note
tx->m_is_miner_tx = false;
tx->m_is_confirmed = false;
tx->m_is_relayed = !tx->m_is_failed.get();
tx->m_in_tx_pool = !tx->m_is_failed.get();
tx->m_relay = true;
if (!tx->m_is_failed.get() && tx->m_is_relayed.get()) tx->m_is_double_spend_seen = false; // TODO: test and handle if true
tx->m_num_confirmations = 0;
// construct transfer
std::shared_ptr<monero_outgoing_transfer> outgoing_transfer = std::make_shared<monero_outgoing_transfer>();
outgoing_transfer->m_tx = tx;
tx->m_outgoing_transfer = outgoing_transfer;
outgoing_transfer->m_amount = pd.m_amount_in - pd.m_change - tx->m_fee.get();
outgoing_transfer->m_account_index = pd.m_subaddr_account;
std::vector<uint32_t> subaddress_indices;
std::vector<std::string> addresses;
for (uint32_t i: pd.m_subaddr_indices) {
subaddress_indices.push_back(i);
addresses.push_back(m_w2.get_subaddress_as_str({pd.m_subaddr_account, i}));
}
outgoing_transfer->m_subaddress_indices = subaddress_indices;
outgoing_transfer->m_addresses = addresses;
// initialize destinations
for (const auto &d: pd.m_dests) {
std::shared_ptr<monero_destination> destination = std::make_shared<monero_destination>();
destination->m_amount = d.amount;
destination->m_address = d.address(m_w2.nettype(), pd.m_payment_id);
outgoing_transfer->m_destinations.push_back(destination);
}
// replace transfer amount with destination sum
// TODO monero-project: confirmed tx from/to same account has amount 0 but cached transfer destinations
if (*outgoing_transfer->m_amount == 0 && !outgoing_transfer->m_destinations.empty()) {
uint64_t amount = 0;
for (const std::shared_ptr<monero_destination>& destination : outgoing_transfer->m_destinations) amount += *destination->m_amount;
outgoing_transfer->m_amount = amount;
}
// return pointer to new tx
return tx;
}
std::shared_ptr<monero_tx_wallet> build_tx_with_vout(tools::wallet2& m_w2, const tools::wallet2::transfer_details& td) {
// construct block
std::shared_ptr<monero_block> block = std::make_shared<monero_block>();
block->m_height = td.m_block_height;
// construct tx
std::shared_ptr<monero_tx_wallet> tx = std::make_shared<monero_tx_wallet>();
tx->m_block = block;
block->m_txs.push_back(tx);
tx->m_hash = epee::string_tools::pod_to_hex(td.m_txid);
tx->m_is_confirmed = true;
tx->m_is_failed = false;
tx->m_is_relayed = true;
tx->m_in_tx_pool = false;
tx->m_relay = true;
tx->m_is_double_spend_seen = false;
tx->m_is_locked = !m_w2.is_transfer_unlocked(td);
// construct output
std::shared_ptr<monero_output_wallet> output = std::make_shared<monero_output_wallet>();
output->m_tx = tx;
tx->m_outputs.push_back(output);
output->m_amount = td.amount();
output->m_index = td.m_global_output_index;
output->m_account_index = td.m_subaddr_index.major;
output->m_subaddress_index = td.m_subaddr_index.minor;
output->m_is_spent = td.m_spent;
output->m_is_frozen = td.m_frozen;
output->m_stealth_public_key = epee::string_tools::pod_to_hex(td.get_public_key());
if (td.m_key_image_known) {
output->m_key_image = std::make_shared<monero_key_image>();
output->m_key_image.get()->m_hex = epee::string_tools::pod_to_hex(td.m_key_image);
}
// return pointer to new tx
return tx;
}
/**
* Merges a transaction into a unique set of transactions.
*
* @param tx is the transaction to merge into the existing txs
* @param tx_map maps tx hashes to txs
* @param block_map maps block heights to blocks
*/
void merge_tx(const std::shared_ptr<monero_tx_wallet>& tx, std::map<std::string, std::shared_ptr<monero_tx_wallet>>& tx_map, std::map<uint64_t, std::shared_ptr<monero_block>>& block_map) {
if (tx->m_hash == boost::none) throw std::runtime_error("Tx hash is not initialized");
// merge tx
std::map<std::string, std::shared_ptr<monero_tx_wallet>>::const_iterator tx_iter = tx_map.find(*tx->m_hash);
if (tx_iter == tx_map.end()) {
tx_map[*tx->m_hash] = tx; // cache new tx
} else {
std::shared_ptr<monero_tx_wallet>& a_tx = tx_map[*tx->m_hash];
a_tx->merge(a_tx, tx); // merge with existing tx
}
// merge tx's block if confirmed
if (tx->get_height() != boost::none) {
std::map<uint64_t, std::shared_ptr<monero_block>>::const_iterator block_iter = block_map.find(tx->get_height().get());
if (block_iter == block_map.end()) {
block_map[tx->get_height().get()] = tx->m_block.get(); // cache new block
} else {
std::shared_ptr<monero_block>& a_block = block_map[tx->get_height().get()];
a_block->merge(a_block, tx->m_block.get()); // merge with existing block
}
}
}
/**
* Returns true iff tx1's height is known to be less than tx2's height for sorting.
*/
bool tx_height_less_than(const std::shared_ptr<monero_tx>& tx1, const std::shared_ptr<monero_tx>& tx2) {
if (tx1->m_block != boost::none && tx2->m_block != boost::none) return tx1->get_height() < tx2->get_height();
else if (tx1->m_block == boost::none) return false;
else return true;
}
/**
* Returns true iff transfer1 is ordered before transfer2 by ascending account and subaddress indices.
*/
bool incoming_transfer_before(const std::shared_ptr<monero_incoming_transfer>& transfer1, const std::shared_ptr<monero_incoming_transfer>& transfer2) {
// compare by height
if (tx_height_less_than(transfer1->m_tx, transfer2->m_tx)) return true;
// compare by account and subaddress index
if (transfer1->m_account_index.get() < transfer2->m_account_index.get()) return true;
else if (transfer1->m_account_index.get() == transfer2->m_account_index.get()) return transfer1->m_subaddress_index.get() < transfer2->m_subaddress_index.get();
else return false;
}
/**
* Returns true iff wallet vout1 is ordered before vout2 by ascending account and subaddress indices then index.
*/
bool vout_before(const std::shared_ptr<monero_output>& o1, const std::shared_ptr<monero_output>& o2) {
if (o1 == o2) return false; // ignore equal references
std::shared_ptr<monero_output_wallet> ow1 = std::static_pointer_cast<monero_output_wallet>(o1);
std::shared_ptr<monero_output_wallet> ow2 = std::static_pointer_cast<monero_output_wallet>(o2);
// compare by height
if (tx_height_less_than(ow1->m_tx, ow2->m_tx)) return true;
// compare by account index, subaddress index, output index, then key image hex
if (ow1->m_account_index.get() < ow2->m_account_index.get()) return true;
if (ow1->m_account_index.get() == ow2->m_account_index.get()) {
if (ow1->m_subaddress_index.get() < ow2->m_subaddress_index.get()) return true;
if (ow1->m_subaddress_index.get() == ow2->m_subaddress_index.get()) {
if (ow1->m_index.get() < ow2->m_index.get()) return true;
if (ow1->m_index.get() == ow2->m_index.get()) throw std::runtime_error("Should never sort outputs with duplicate indices");
}
}
return false;
}
std::string get_default_ringdb_path(cryptonote::network_type nettype)
{
boost::filesystem::path dir = tools::get_default_data_dir();
// remove .bitmonero, replace with .shared-ringdb
dir = dir.remove_filename();
dir /= ".shared-ringdb";
if (nettype == cryptonote::TESTNET)
dir /= "testnet";
else if (nettype == cryptonote::STAGENET)
dir /= "stagenet";
return dir.string();
}
/**
* ---------------- DUPLICATED WALLET RPC TRANSFER CODE ---------------------
*
* These functions are duplicated from private functions in wallet rpc
* on_transfer/on_transfer_split, with minor modifications to not be class members.
*
* This code is used to generate and send transactions with equivalent functionality as
* wallet rpc.
*
* Duplicated code is not ideal. Solutions considered:
*
* (1) Duplicate wallet rpc code as done here.
* (2) Modify monero-wallet-rpc on_transfer() / on_transfer_split() to be public.
* (3) Modify monero-wallet-rpc to make this class a friend.
* (4) Move all logic in monero-wallet-rpc to wallet2 so all users can access.
*
* Options 2-4 require modification of monero-project C++. Of those, (4) is probably ideal.
* TODO: open patch on monero-project which moves common wallet rpc logic (e.g. on_transfer, on_transfer_split) to m_w2.
*
* Until then, option (1) is used because it allows monero-project binaries to be used without modification, it's easy, and
* anything other than (4) is temporary.
*/
//------------------------------------------------------------------------------------------------------------------------------
bool validate_transfer(wallet2* m_w2, const std::list<wallet_rpc::transfer_destination>& destinations, const std::string& payment_id, std::vector<cryptonote::tx_destination_entry>& dsts, std::vector<uint8_t>& extra, bool at_least_one_destination, epee::json_rpc::error& er)
{
crypto::hash8 integrated_payment_id = crypto::null_hash8;
std::string extra_nonce;
for (auto it = destinations.begin(); it != destinations.end(); it++)
{
cryptonote::address_parse_info info;
cryptonote::tx_destination_entry de;
er.message = "";
if(!get_account_address_from_str_or_url(info, m_w2->nettype(), it->address,
[&er](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)->std::string {
if (!dnssec_valid)
{
er.message = std::string("Invalid DNSSEC for ") + url;
return {};
}
if (addresses.empty())
{
er.message = std::string("No Monero address found at ") + url;
return {};
}
return addresses[0];
}))
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS;
if (er.message.empty())
er.message = std::string("Invalid destination address");
return false;
}
de.original = it->address;
de.addr = info.address;
de.is_subaddress = info.is_subaddress;
de.amount = it->amount;
de.is_integrated = info.has_payment_id;
dsts.push_back(de);
if (info.has_payment_id)
{
if (!payment_id.empty() || integrated_payment_id != crypto::null_hash8)
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
er.message = "A single payment id is allowed per transaction";
return false;
}
integrated_payment_id = info.payment_id;
cryptonote::set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, integrated_payment_id);
/* Append Payment ID data into extra */
if (!cryptonote::add_extra_nonce_to_tx_extra(extra, extra_nonce)) {
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
er.message = "Something went wrong with integrated payment_id.";
return false;
}
}
}
if (at_least_one_destination && dsts.empty())
{
er.code = WALLET_RPC_ERROR_CODE_ZERO_DESTINATION;
er.message = "No destinations for this transfer";
return false;
}
if (!payment_id.empty())
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
er.message = "Standalone payment IDs are obsolete. Use subaddresses or integrated addresses instead";
return false;
}
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
static std::string ptx_to_string(const tools::wallet2::pending_tx &ptx)
{
std::ostringstream oss;
boost::archive::portable_binary_oarchive ar(oss);
try
{
ar << ptx;
}
catch (...)
{
return "";
}
return epee::string_tools::buff_to_hex_nodelimer(oss.str());
}
//------------------------------------------------------------------------------------------------------------------------------
template<typename T> static bool is_error_value(const T &val) { return false; }
static bool is_error_value(const std::string &s) { return s.empty(); }
//------------------------------------------------------------------------------------------------------------------------------
template<typename T, typename V>
static bool fill(T &where, V s)
{
if (is_error_value(s)) return false;
where = std::move(s);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
template<typename T, typename V>
static bool fill(std::list<T> &where, V s)
{
if (is_error_value(s)) return false;
where.emplace_back(std::move(s));
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
static uint64_t total_amount(const tools::wallet2::pending_tx &ptx)
{
uint64_t amount = 0;
for (const auto &dest: ptx.dests) amount += dest.amount;
return amount;
}
//------------------------------------------------------------------------------------------------------------------------------
template<typename Ts, typename Tu, typename Tk, typename Ta>
bool fill_response(wallet2* m_w2, std::vector<tools::wallet2::pending_tx> &ptx_vector,
bool get_tx_key, Ts& tx_key, Tu &amount, Ta &amounts_by_dest, Tu &fee, Tu &weight, std::string &multisig_txset, std::string &unsigned_txset, bool do_not_relay,
Ts &tx_hash, bool get_tx_hex, Ts &tx_blob, bool get_tx_metadata, Ts &tx_metadata, Tk &spent_key_images, epee::json_rpc::error &er)
{
for (const auto & ptx : ptx_vector)
{
if (get_tx_key)
{
epee::wipeable_string s = epee::to_hex::wipeable_string(ptx.tx_key);
for (const crypto::secret_key& additional_tx_key : ptx.additional_tx_keys)
s += epee::to_hex::wipeable_string(additional_tx_key);
fill(tx_key, std::string(s.data(), s.size()));
}
// Compute amount leaving wallet in tx. By convention dests does not include change outputs
fill(amount, total_amount(ptx));
fill(fee, ptx.fee);
fill(weight, cryptonote::get_transaction_weight(ptx.tx));
// add amounts by destination
tools::wallet_rpc::amounts_list abd;
for (const auto& dst : ptx.dests)
abd.amounts.push_back(dst.amount);
fill(amounts_by_dest, abd);
// add spent key images
key_image_list key_image_list;
bool all_are_txin_to_key = std::all_of(ptx.tx.vin.begin(), ptx.tx.vin.end(), [&](const cryptonote::txin_v& s_e) -> bool
{
CHECKED_GET_SPECIFIC_VARIANT(s_e, const cryptonote::txin_to_key, in, false);
key_image_list.key_images.push_back(epee::string_tools::pod_to_hex(in.k_image));
return true;
});
THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, ptx.tx);
fill(spent_key_images, key_image_list);
}
if (m_w2->multisig())
{
multisig_txset = epee::string_tools::buff_to_hex_nodelimer(m_w2->save_multisig_tx(ptx_vector));
if (multisig_txset.empty())
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
er.message = "Failed to save multisig tx set after creation";
return false;
}
}
else
{
if (m_w2->watch_only()){
unsigned_txset = epee::string_tools::buff_to_hex_nodelimer(m_w2->dump_tx_to_str(ptx_vector));
if (unsigned_txset.empty())
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
er.message = "Failed to save unsigned tx set after creation";
return false;
}
}
else if (!do_not_relay)
m_w2->commit_tx(ptx_vector);
// populate response with tx hashes
for (auto & ptx : ptx_vector)
{
bool r = fill(tx_hash, epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx)));
r = r && (!get_tx_hex || fill(tx_blob, epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(ptx.tx))));
r = r && (!get_tx_metadata || fill(tx_metadata, ptx_to_string(ptx)));
if (!r)
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
er.message = "Failed to save tx info";
return false;
}
}
}
return true;
}
// ----------------------------- WALLET LISTENER ----------------------------
/**
* Listens to wallet2 notifications in order to notify external wallet listeners.
*/
struct wallet2_listener : public tools::i_wallet2_callback {
public:
/**
* Constructs the listener.
*
* @param wallet provides context to notify external listeners
* @param wallet2 provides source notifications which this listener propagates to external listeners
*/
wallet2_listener(monero_wallet_full& wallet, tools::wallet2& wallet2) : m_wallet(wallet), m_w2(wallet2) {
this->m_sync_start_height = boost::none;
this->m_sync_end_height = boost::none;
m_prev_balance = wallet.get_balance();
m_prev_unlocked_balance = wallet.get_unlocked_balance();
m_notification_pool = std::unique_ptr<tools::threadpool>(tools::threadpool::getNewForUnitTests(1)); // TODO (monero-project): utility can be for general use
}
~wallet2_listener() {
MTRACE("~wallet2_listener()");
m_w2.callback(nullptr);
m_notification_pool->recycle();
}
void update_listening() {
boost::lock_guard<boost::mutex> guarg(m_listener_mutex);
// if starting to listen, cache locked txs for later comparison
if (!m_wallet.get_listeners().empty() && m_w2.callback() == nullptr) check_for_changed_unlocked_txs();
// update callback
m_w2.callback(m_wallet.get_listeners().empty() ? nullptr : this);
}
void on_sync_start(uint64_t start_height) {
tools::threadpool::waiter waiter(*m_notification_pool);
m_notification_pool->submit(&waiter, [this, start_height]() {
if (m_sync_start_height != boost::none || m_sync_end_height != boost::none) throw std::runtime_error("Sync start or end height should not already be allocated, is previous sync in progress?");
m_sync_start_height = start_height;
m_sync_end_height = m_wallet.get_daemon_height();
});
waiter.wait(); // TODO: this processes notification on thread, process off thread
}
void on_sync_end() {
tools::threadpool::waiter waiter(*m_notification_pool);
m_notification_pool->submit(&waiter, [this]() {
check_for_changed_balances();
if (m_prev_locked_tx_hashes.size() > 0) check_for_changed_unlocked_txs();
m_sync_start_height = boost::none;
m_sync_end_height = boost::none;
});
m_notification_pool->recycle();
waiter.wait();
}
void on_new_block(uint64_t height, const cryptonote::block& cn_block) override {
if (m_wallet.get_listeners().empty()) return;
// ignore notifications before sync start height, irrelevant to clients
if (m_sync_start_height == boost::none || height < *m_sync_start_height) return;
// queue notification processing off main thread
tools::threadpool::waiter waiter(*m_notification_pool);
m_notification_pool->submit(&waiter, [this, height]() {
// notify listeners of new block
for (monero_wallet_listener* listener : m_wallet.get_listeners()) {
listener->on_new_block(height);
}
// notify listeners of sync progress
if (height >= *m_sync_end_height) m_sync_end_height = height + 1; // increase end height if necessary
double percent_done = (double) (height - *m_sync_start_height + 1) / (double) (*m_sync_end_height - *m_sync_start_height);
std::string message = std::string("Synchronizing");
for (monero_wallet_listener* listener : m_wallet.get_listeners()) {
listener->on_sync_progress(height, *m_sync_start_height, *m_sync_end_height, percent_done, message);
}
// notify if balances change
bool balances_changed = check_for_changed_balances();
// notify when txs unlock after wallet is synced
if (balances_changed && m_wallet.is_synced()) check_for_changed_unlocked_txs();
});
waiter.wait();
}
void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cn_tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) override {
if (m_wallet.get_listeners().empty()) return;
// queue notification processing off main thread
tools::threadpool::waiter waiter(*m_notification_pool);
m_notification_pool->submit(&waiter, [this, height, txid, cn_tx, amount, subaddr_index]() {
try {
// create library tx
std::shared_ptr<monero_tx_wallet> tx = std::static_pointer_cast<monero_tx_wallet>(monero_utils::cn_tx_to_tx(cn_tx, true));
tx->m_hash = epee::string_tools::pod_to_hex(txid);
tx->m_is_confirmed = false;
tx->m_is_locked = true;
std::shared_ptr<monero_output_wallet> output = std::make_shared<monero_output_wallet>();
tx->m_outputs.push_back(output);
output->m_tx = tx;
output->m_amount = amount;
output->m_account_index = subaddr_index.major;
output->m_subaddress_index = subaddr_index.minor;
// notify listeners of output
for (monero_wallet_listener* listener : m_wallet.get_listeners()) {
listener->on_output_received(*output);
}
// notify if balances changed
check_for_changed_balances();
// watch for unlock
m_prev_locked_tx_hashes.insert(tx->m_hash.get());
// free memory
monero_utils::free(tx);
} catch (std::exception& e) {
std::cout << "Error processing unconfirmed output received: " << std::string(e.what()) << std::endl;
}
});
waiter.wait();
}
void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cn_tx, uint64_t amount, uint64_t burnt, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time) override {
if (m_wallet.get_listeners().empty()) return;
// queue notification processing off main thread
tools::threadpool::waiter waiter(*m_notification_pool);
m_notification_pool->submit(&waiter, [this, height, txid, cn_tx, amount, burnt, subaddr_index, is_change, unlock_time]() {
try {
// create native library tx
std::shared_ptr<monero_block> block = std::make_shared<monero_block>();
block->m_height = height;
std::shared_ptr<monero_tx_wallet> tx = std::static_pointer_cast<monero_tx_wallet>(monero_utils::cn_tx_to_tx(cn_tx, true));
block->m_txs.push_back(tx);
tx->m_block = block;
tx->m_hash = epee::string_tools::pod_to_hex(txid);
tx->m_is_confirmed = true;
tx->m_is_locked = true;
tx->m_unlock_time = unlock_time;
std::shared_ptr<monero_output_wallet> output = std::make_shared<monero_output_wallet>();
tx->m_outputs.push_back(output);
output->m_tx = tx;
output->m_amount = amount - burnt;
output->m_account_index = subaddr_index.major;
output->m_subaddress_index = subaddr_index.minor;
// notify listeners of output
for (monero_wallet_listener* listener : m_wallet.get_listeners()) {
listener->on_output_received(*output);
}
// watch for unlock
m_prev_locked_tx_hashes.insert(tx->m_hash.get());
// free memory
monero_utils::free(block);
} catch (std::exception& e) {
std::cout << "Error processing confirmed output received: " << std::string(e.what()) << std::endl;
}
});
waiter.wait();
}
void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& cn_tx_in, uint64_t amount, const cryptonote::transaction& cn_tx_out, const cryptonote::subaddress_index& subaddr_index) override {
if (m_wallet.get_listeners().empty()) return;
if (&cn_tx_in != &cn_tx_out) throw std::runtime_error("on_money_spent() in tx is different than out tx");
// queue notification processing off main thread
tools::threadpool::waiter waiter(*m_notification_pool);
m_notification_pool->submit(&waiter, [this, height, txid, cn_tx_in, amount, cn_tx_out, subaddr_index]() {
try {
// create native library tx
std::shared_ptr<monero_block> block = std::make_shared<monero_block>();
block->m_height = height;
std::shared_ptr<monero_tx_wallet> tx = std::static_pointer_cast<monero_tx_wallet>(monero_utils::cn_tx_to_tx(cn_tx_in, true));
block->m_txs.push_back(tx);
tx->m_block = block;
tx->m_hash = epee::string_tools::pod_to_hex(txid);
tx->m_is_confirmed = true;
tx->m_is_locked = true;
std::shared_ptr<monero_output_wallet> output = std::make_shared<monero_output_wallet>();
tx->m_inputs.push_back(output);
output->m_tx = tx;
output->m_amount = amount;
output->m_account_index = subaddr_index.major;
output->m_subaddress_index = subaddr_index.minor;
// notify listeners of output
for (monero_wallet_listener* listener : m_wallet.get_listeners()) {
listener->on_output_spent(*output);
}
// watch for unlock
m_prev_locked_tx_hashes.insert(tx->m_hash.get());
// free memory
monero_utils::free(block);
} catch (std::exception& e) {
std::cout << "Error processing confirmed output spent: " << std::string(e.what()) << std::endl;
}
});
waiter.wait();
}
void on_spend_tx_hashes(const std::vector<std::string>& tx_hashes) {
if (m_wallet.get_listeners().empty()) return;
monero_tx_query tx_query;
tx_query.m_hashes = tx_hashes;
tx_query.m_include_outputs = true;
tx_query.m_is_locked = true;
on_spend_txs(m_wallet.get_txs(tx_query));
}
void on_spend_txs(const std::vector<std::shared_ptr<monero_tx_wallet>>& txs) {
if (m_wallet.get_listeners().empty()) return;
tools::threadpool::waiter waiter(*m_notification_pool);
m_notification_pool->submit(&waiter, [this, txs]() {
check_for_changed_balances();
for (const std::shared_ptr<monero_tx_wallet>& tx : txs) notify_outputs(tx);
});
waiter.wait();
}
private:
monero_wallet_full& m_wallet; // wallet to provide context for notifications
tools::wallet2& m_w2; // internal wallet implementation to listen to
boost::optional<uint64_t> m_sync_start_height;
boost::optional<uint64_t> m_sync_end_height;
boost::mutex m_listener_mutex;
uint64_t m_prev_balance;
uint64_t m_prev_unlocked_balance;
std::set<std::string> m_prev_locked_tx_hashes;
std::unique_ptr<tools::threadpool> m_notification_pool; // threadpool of size 1 to queue notifications for external announcement
bool check_for_changed_balances() {
uint64_t balance = m_wallet.get_balance();
uint64_t unlocked_balance = m_wallet.get_unlocked_balance();
if (balance != m_prev_balance || unlocked_balance != m_prev_unlocked_balance) {
m_prev_balance = balance;
m_prev_unlocked_balance = unlocked_balance;
for (monero_wallet_listener* listener : m_wallet.get_listeners()) {
listener->on_balances_changed(balance, unlocked_balance);
}
return true;
}
return false;
}
// TODO: this can probably be optimized using e.g. wallet2.get_num_rct_outputs() or wallet2.get_num_transfer_details(), or by retaining confirmed block height and only checking on or after unlock height, etc
void check_for_changed_unlocked_txs() {
// get confirmed and locked txs
monero_tx_query query = monero_tx_query();
query.m_is_locked = true;
query.m_is_confirmed = true;
query.m_min_height = m_wallet.get_height() - 70; // only monitor recent txs
std::vector<std::shared_ptr<monero_tx_wallet>> locked_txs = m_wallet.get_txs(query);
// collect hashes of txs no longer locked
std::vector<std::string> tx_hashes_no_longer_locked;
for (const std::string prev_locked_tx_hash : m_prev_locked_tx_hashes) {
bool found = false;
for (const std::shared_ptr<monero_tx_wallet>& locked_tx : locked_txs) {
if (locked_tx->m_hash.get() == prev_locked_tx_hash) {
found = true;
break;
}
}
if (!found) tx_hashes_no_longer_locked.push_back(prev_locked_tx_hash);
}
// fetch txs that are no longer locked
std::vector<std::shared_ptr<monero_tx_wallet>> txs_no_longer_locked;
if (!tx_hashes_no_longer_locked.empty()) {
query.m_hashes = tx_hashes_no_longer_locked;
query.m_is_locked = false;
query.m_include_outputs = true;
txs_no_longer_locked = m_wallet.get_txs(query);
}
// notify listeners of newly unlocked inputs and outputs
for (const std::shared_ptr<monero_tx_wallet>& unlocked_tx : txs_no_longer_locked) {
notify_outputs(unlocked_tx);
}
// re-assign currently locked tx hashes // TODO: needs mutex for thread safety?
m_prev_locked_tx_hashes.clear();
for (const std::shared_ptr<monero_tx_wallet>& locked_tx : locked_txs) {