-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathwallet2.h
2646 lines (2424 loc) · 121 KB
/
wallet2.h
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) 2014-2024, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this 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
#pragma once
#include <memory>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#if BOOST_VERSION >= 107400
#include <boost/serialization/library_version_type.hpp>
#endif
#include <boost/serialization/list.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/deque.hpp>
#include <boost/thread/lock_guard.hpp>
#include <atomic>
#include <random>
#include "include_base_utils.h"
#include "cryptonote_basic/account.h"
#include "cryptonote_basic/account_boost_serialization.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "net/http.h"
#include "storages/http_abstract_invoke.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_core/cryptonote_tx_utils.h"
#include "common/unordered_containers_boost_serialization.h"
#include "common/util.h"
#include "crypto/chacha.h"
#include "crypto/hash.h"
#include "multisig/multisig_account.h"
#include "ringct/rctTypes.h"
#include "ringct/rctOps.h"
#include "checkpoints/checkpoints.h"
#include "serialization/crypto.h"
#include "serialization/string.h"
#include "serialization/pair.h"
#include "serialization/tuple.h"
#include "serialization/containers.h"
#include "wallet_errors.h"
#include "common/password.h"
#include "node_rpc_proxy.h"
#include "message_store.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
class Serialization_portability_wallet_Test;
class wallet_accessor_test;
namespace multisig { class multisig_account; }
namespace tools
{
class ringdb;
class wallet2;
class Notify;
class gamma_picker
{
public:
uint64_t pick();
gamma_picker(const std::vector<uint64_t> &rct_offsets);
gamma_picker(const std::vector<uint64_t> &rct_offsets, double shape, double scale);
uint64_t get_num_rct_outs() const { return num_rct_outputs; }
private:
struct gamma_engine
{
typedef uint64_t result_type;
static constexpr result_type min() { return 0; }
static constexpr result_type max() { return std::numeric_limits<result_type>::max(); }
result_type operator()() { return crypto::rand<result_type>(); }
} engine;
private:
std::gamma_distribution<double> gamma;
const std::vector<uint64_t> &rct_offsets;
const uint64_t *begin, *end;
uint64_t num_rct_outputs;
double average_output_time;
};
class wallet_keys_unlocker
{
public:
wallet_keys_unlocker(wallet2 &w, const boost::optional<tools::password_container> &password);
wallet_keys_unlocker(wallet2 &w, bool locked, const epee::wipeable_string &password);
~wallet_keys_unlocker();
private:
wallet2 &w;
bool locked;
crypto::chacha_key key;
static boost::mutex lockers_lock;
static unsigned int lockers;
};
class i_wallet2_callback
{
public:
// Full wallet callbacks
virtual void on_new_block(uint64_t height, const cryptonote::block& block) {}
virtual void on_reorg(uint64_t height, uint64_t blocks_detached, size_t transfers_detached) {}
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, uint64_t burnt, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time) {}
virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) {}
virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index) {}
virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {}
virtual boost::optional<epee::wipeable_string> on_get_password(const char *reason) { return boost::none; }
// Device callbacks
virtual void on_device_button_request(uint64_t code) {}
virtual void on_device_button_pressed() {}
virtual boost::optional<epee::wipeable_string> on_device_pin_request() { return boost::none; }
virtual boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device) { on_device = true; return boost::none; }
virtual void on_device_progress(const hw::device_progress& event) {};
// Common callbacks
virtual void on_pool_tx_removed(const crypto::hash &txid) {}
virtual ~i_wallet2_callback() {}
};
class wallet_device_callback : public hw::i_device_callback
{
public:
wallet_device_callback(wallet2 * wallet): wallet(wallet) {};
void on_button_request(uint64_t code=0) override;
void on_button_pressed() override;
boost::optional<epee::wipeable_string> on_pin_request() override;
boost::optional<epee::wipeable_string> on_passphrase_request(bool & on_device) override;
void on_progress(const hw::device_progress& event) override;
private:
wallet2 * wallet;
};
struct tx_dust_policy
{
uint64_t dust_threshold;
bool add_to_fee;
cryptonote::account_public_address addr_for_dust;
tx_dust_policy(uint64_t a_dust_threshold = 0, bool an_add_to_fee = true, cryptonote::account_public_address an_addr_for_dust = cryptonote::account_public_address())
: dust_threshold(a_dust_threshold)
, add_to_fee(an_add_to_fee)
, addr_for_dust(an_addr_for_dust)
{
}
};
class hashchain
{
public:
hashchain(): m_genesis(crypto::null_hash), m_offset(0) {}
size_t size() const { return m_blockchain.size() + m_offset; }
size_t offset() const { return m_offset; }
const crypto::hash &genesis() const { return m_genesis; }
void push_back(const crypto::hash &hash) { if (m_offset == 0 && m_blockchain.empty()) m_genesis = hash; m_blockchain.push_back(hash); }
bool is_in_bounds(size_t idx) const { return idx >= m_offset && idx < size(); }
const crypto::hash &operator[](size_t idx) const { return m_blockchain[idx - m_offset]; }
crypto::hash &operator[](size_t idx) { return m_blockchain[idx - m_offset]; }
void crop(size_t height) { m_blockchain.resize(height - m_offset); }
void clear() { m_offset = 0; m_blockchain.clear(); }
bool empty() const { return m_blockchain.empty() && m_offset == 0; }
void trim(size_t height) { while (height > m_offset && m_blockchain.size() > 1) { m_blockchain.pop_front(); ++m_offset; } m_blockchain.shrink_to_fit(); }
void refill(const crypto::hash &hash) { m_blockchain.push_back(hash); --m_offset; }
template <class t_archive>
inline void serialize(t_archive &a, const unsigned int ver)
{
a & m_offset;
a & m_genesis;
a & m_blockchain;
}
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(m_offset)
FIELD(m_genesis)
FIELD(m_blockchain)
END_SERIALIZE()
private:
size_t m_offset;
crypto::hash m_genesis;
std::deque<crypto::hash> m_blockchain;
};
class wallet_keys_unlocker;
class wallet2
{
friend class ::Serialization_portability_wallet_Test;
friend class ::wallet_accessor_test;
friend class wallet_keys_unlocker;
friend class wallet_device_callback;
public:
static constexpr const std::chrono::seconds rpc_timeout = std::chrono::minutes(3) + std::chrono::seconds(30);
enum RefreshType {
RefreshFull,
RefreshOptimizeCoinbase,
RefreshNoCoinbase,
RefreshDefault = RefreshOptimizeCoinbase,
};
enum AskPasswordType {
AskPasswordNever = 0,
AskPasswordOnAction = 1,
AskPasswordToDecrypt = 2,
};
enum BackgroundMiningSetupType {
BackgroundMiningMaybe = 0,
BackgroundMiningYes = 1,
BackgroundMiningNo = 2,
};
enum BackgroundSyncType {
BackgroundSyncOff = 0,
BackgroundSyncReusePassword = 1,
BackgroundSyncCustomPassword = 2,
};
static BackgroundSyncType background_sync_type_from_str(const std::string &background_sync_type_str)
{
if (background_sync_type_str == "off") return BackgroundSyncOff;
if (background_sync_type_str == "reuse-wallet-password") return BackgroundSyncReusePassword;
if (background_sync_type_str == "custom-background-password") return BackgroundSyncCustomPassword;
throw std::logic_error("Unknown background sync type");
};
enum ExportFormat {
Binary = 0,
Ascii,
};
static const char* tr(const char* str);
static bool has_testnet_option(const boost::program_options::variables_map& vm);
static bool has_stagenet_option(const boost::program_options::variables_map& vm);
static std::string device_name_option(const boost::program_options::variables_map& vm);
static std::string device_derivation_path_option(const boost::program_options::variables_map &vm);
static void init_options(boost::program_options::options_description& desc_params);
//! Uses stdin and stdout. Returns a wallet2 if no errors.
static std::pair<std::unique_ptr<wallet2>, password_container> make_from_json(const boost::program_options::variables_map& vm, bool unattended, const std::string& json_file, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
//! Uses stdin and stdout. Returns a wallet2 and password for `wallet_file` if no errors.
static std::pair<std::unique_ptr<wallet2>, password_container>
make_from_file(const boost::program_options::variables_map& vm, bool unattended, const std::string& wallet_file, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
//! Uses stdin and stdout. Returns a wallet2 and password for wallet with no file if no errors.
static std::pair<std::unique_ptr<wallet2>, password_container> make_new(const boost::program_options::variables_map& vm, bool unattended, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
//! Just parses variables.
static std::unique_ptr<wallet2> make_dummy(const boost::program_options::variables_map& vm, bool unattended, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
static bool verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds)
{
crypto::secret_key spend_key = crypto::null_skey;
return verify_password(keys_file_name, password, no_spend_key, hwdev, kdf_rounds, spend_key);
};
static bool verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds, crypto::secret_key &spend_key_out);
static bool query_device(hw::device::device_type& device_type, const std::string& keys_file_name, const epee::wipeable_string& password, uint64_t kdf_rounds = 1);
wallet2(cryptonote::network_type nettype = cryptonote::MAINNET, uint64_t kdf_rounds = 1, bool unattended = false, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = std::unique_ptr<epee::net_utils::http::http_client_factory>(new net::http::client_factory()));
~wallet2();
struct multisig_info
{
struct LR
{
rct::key m_L;
rct::key m_R;
BEGIN_SERIALIZE_OBJECT()
FIELD(m_L)
FIELD(m_R)
END_SERIALIZE()
};
crypto::public_key m_signer;
std::vector<LR> m_LR;
std::vector<crypto::key_image> m_partial_key_images; // one per key the participant has
BEGIN_SERIALIZE_OBJECT()
FIELD(m_signer)
FIELD(m_LR)
FIELD(m_partial_key_images)
END_SERIALIZE()
};
struct tx_scan_info_t
{
cryptonote::keypair in_ephemeral;
crypto::key_image ki;
rct::key mask;
uint64_t amount;
uint64_t money_transfered;
bool error;
boost::optional<cryptonote::subaddress_receive_info> received;
tx_scan_info_t(): amount(0), money_transfered(0), error(true) {}
};
struct transfer_details
{
uint64_t m_block_height;
cryptonote::transaction_prefix m_tx;
crypto::hash m_txid;
uint64_t m_internal_output_index;
uint64_t m_global_output_index;
bool m_spent;
bool m_frozen;
uint64_t m_spent_height;
crypto::key_image m_key_image; //TODO: key_image stored twice :(
rct::key m_mask;
uint64_t m_amount;
bool m_rct;
bool m_key_image_known;
bool m_key_image_request; // view wallets: we want to request it; cold wallets: it was requested
uint64_t m_pk_index;
cryptonote::subaddress_index m_subaddr_index;
bool m_key_image_partial;
std::vector<rct::key> m_multisig_k;
std::vector<multisig_info> m_multisig_info; // one per other participant
std::vector<std::pair<uint64_t, crypto::hash>> m_uses;
bool is_rct() const { return m_rct; }
uint64_t amount() const { return m_amount; }
const crypto::public_key get_public_key() const {
crypto::public_key output_public_key;
THROW_WALLET_EXCEPTION_IF(m_tx.vout.size() <= m_internal_output_index,
error::wallet_internal_error, "Too few outputs, outputs may be corrupted");
THROW_WALLET_EXCEPTION_IF(!get_output_public_key(m_tx.vout[m_internal_output_index], output_public_key),
error::wallet_internal_error, "Unable to get output public key from output");
return output_public_key;
};
BEGIN_SERIALIZE_OBJECT()
FIELD(m_block_height)
FIELD(m_tx)
FIELD(m_txid)
FIELD(m_internal_output_index)
FIELD(m_global_output_index)
FIELD(m_spent)
FIELD(m_frozen)
FIELD(m_spent_height)
FIELD(m_key_image)
FIELD(m_mask)
FIELD(m_amount)
FIELD(m_rct)
FIELD(m_key_image_known)
FIELD(m_key_image_request)
FIELD(m_pk_index)
FIELD(m_subaddr_index)
FIELD(m_key_image_partial)
FIELD(m_multisig_k)
FIELD(m_multisig_info)
FIELD(m_uses)
END_SERIALIZE()
};
struct exported_transfer_details
{
crypto::public_key m_pubkey;
uint64_t m_internal_output_index;
uint64_t m_global_output_index;
crypto::public_key m_tx_pubkey;
union
{
struct
{
uint8_t m_spent: 1;
uint8_t m_frozen: 1;
uint8_t m_rct: 1;
uint8_t m_key_image_known: 1;
uint8_t m_key_image_request: 1; // view wallets: we want to request it; cold wallets: it was requested
uint8_t m_key_image_partial: 1;
};
uint8_t flags;
} m_flags;
uint64_t m_amount;
std::vector<crypto::public_key> m_additional_tx_keys;
uint32_t m_subaddr_index_major;
uint32_t m_subaddr_index_minor;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(1)
if (version < 1)
return false;
FIELD(m_pubkey)
VARINT_FIELD(m_internal_output_index)
VARINT_FIELD(m_global_output_index)
FIELD(m_tx_pubkey)
FIELD(m_flags.flags)
VARINT_FIELD(m_amount)
FIELD(m_additional_tx_keys)
VARINT_FIELD(m_subaddr_index_major)
VARINT_FIELD(m_subaddr_index_minor)
END_SERIALIZE()
};
typedef std::vector<uint64_t> amounts_container;
struct payment_details
{
crypto::hash m_tx_hash;
uint64_t m_amount;
amounts_container m_amounts;
uint64_t m_fee;
uint64_t m_block_height;
uint64_t m_unlock_time;
uint64_t m_timestamp;
bool m_coinbase;
cryptonote::subaddress_index m_subaddr_index;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(m_tx_hash)
VARINT_FIELD(m_amount)
FIELD(m_amounts)
VARINT_FIELD(m_fee)
VARINT_FIELD(m_block_height)
VARINT_FIELD(m_unlock_time)
VARINT_FIELD(m_timestamp)
FIELD(m_coinbase)
FIELD(m_subaddr_index)
END_SERIALIZE()
};
struct address_tx : payment_details
{
bool m_mempool;
bool m_incoming;
};
struct pool_payment_details
{
payment_details m_pd;
bool m_double_spend_seen;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(m_pd)
FIELD(m_double_spend_seen)
END_SERIALIZE()
};
struct unconfirmed_transfer_details
{
cryptonote::transaction_prefix m_tx;
uint64_t m_amount_in;
uint64_t m_amount_out;
uint64_t m_change;
time_t m_sent_time;
std::vector<cryptonote::tx_destination_entry> m_dests;
crypto::hash m_payment_id;
enum { pending, pending_in_pool, failed } m_state;
uint64_t m_timestamp;
uint32_t m_subaddr_account; // subaddress account of your wallet to be used in this transfer
std::set<uint32_t> m_subaddr_indices; // set of address indices used as inputs in this transfer
std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> m_rings; // relative
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(1)
FIELD(m_tx)
VARINT_FIELD(m_amount_in)
VARINT_FIELD(m_amount_out)
VARINT_FIELD(m_change)
VARINT_FIELD(m_sent_time)
FIELD(m_dests)
FIELD(m_payment_id)
if (version >= 1)
VARINT_FIELD(m_state)
VARINT_FIELD(m_timestamp)
VARINT_FIELD(m_subaddr_account)
FIELD(m_subaddr_indices)
FIELD(m_rings)
END_SERIALIZE()
};
struct confirmed_transfer_details
{
cryptonote::transaction_prefix m_tx;
uint64_t m_amount_in;
uint64_t m_amount_out;
uint64_t m_change;
uint64_t m_block_height;
std::vector<cryptonote::tx_destination_entry> m_dests;
crypto::hash m_payment_id;
uint64_t m_timestamp;
uint64_t m_unlock_time;
uint32_t m_subaddr_account; // subaddress account of your wallet to be used in this transfer
std::set<uint32_t> m_subaddr_indices; // set of address indices used as inputs in this transfer
std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> m_rings; // relative
confirmed_transfer_details(): m_amount_in(0), m_amount_out(0), m_change((uint64_t)-1), m_block_height(0), m_payment_id(crypto::null_hash), m_timestamp(0), m_unlock_time(0), m_subaddr_account((uint32_t)-1) {}
confirmed_transfer_details(const unconfirmed_transfer_details &utd, uint64_t height):
m_tx(utd.m_tx), m_amount_in(utd.m_amount_in), m_amount_out(utd.m_amount_out), m_change(utd.m_change), m_block_height(height), m_dests(utd.m_dests), m_payment_id(utd.m_payment_id), m_timestamp(utd.m_timestamp), m_unlock_time(utd.m_tx.unlock_time), m_subaddr_account(utd.m_subaddr_account), m_subaddr_indices(utd.m_subaddr_indices), m_rings(utd.m_rings) {}
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(1)
if (version >= 1)
FIELD(m_tx)
VARINT_FIELD(m_amount_in)
VARINT_FIELD(m_amount_out)
VARINT_FIELD(m_change)
VARINT_FIELD(m_block_height)
FIELD(m_dests)
FIELD(m_payment_id)
VARINT_FIELD(m_timestamp)
VARINT_FIELD(m_unlock_time)
VARINT_FIELD(m_subaddr_account)
FIELD(m_subaddr_indices)
FIELD(m_rings)
END_SERIALIZE()
};
struct tx_construction_data
{
std::vector<cryptonote::tx_source_entry> sources;
cryptonote::tx_destination_entry change_dts;
std::vector<cryptonote::tx_destination_entry> splitted_dsts; // split, includes change
std::vector<size_t> selected_transfers;
std::vector<uint8_t> extra;
uint64_t unlock_time;
bool use_rct;
rct::RCTConfig rct_config;
bool use_view_tags;
std::vector<cryptonote::tx_destination_entry> dests; // original setup, does not include change
uint32_t subaddr_account; // subaddress account of your wallet to be used in this transfer
std::set<uint32_t> subaddr_indices; // set of address indices used as inputs in this transfer
enum construction_flags_ : uint8_t
{
_use_rct = 1 << 0, // 00000001
_use_view_tags = 1 << 1 // 00000010
// next flag = 1 << 2 // 00000100
// ...
// final flag = 1 << 7 // 10000000
};
uint8_t construction_flags;
BEGIN_SERIALIZE_OBJECT()
FIELD(sources)
FIELD(change_dts)
FIELD(splitted_dsts)
FIELD(selected_transfers)
FIELD(extra)
FIELD(unlock_time)
// converted `use_rct` field into construction_flags when view tags
// were introduced to maintain backwards compatibility
if (!typename Archive<W>::is_saving())
{
FIELD_N("use_rct", construction_flags)
use_rct = (construction_flags & _use_rct) > 0;
use_view_tags = (construction_flags & _use_view_tags) > 0;
}
else
{
construction_flags = 0;
if (use_rct)
construction_flags ^= _use_rct;
if (use_view_tags)
construction_flags ^= _use_view_tags;
FIELD_N("use_rct", construction_flags)
}
FIELD(rct_config)
FIELD(dests)
FIELD(subaddr_account)
FIELD(subaddr_indices)
END_SERIALIZE()
};
typedef std::vector<transfer_details> transfer_container;
typedef std::unordered_multimap<crypto::hash, payment_details> payment_container;
typedef std::set<uint32_t> unique_index_container;
struct multisig_sig
{
rct::rctSig sigs;
std::unordered_set<crypto::public_key> ignore;
std::unordered_set<rct::key> used_L;
std::unordered_set<crypto::public_key> signing_keys;
rct::multisig_out msout;
rct::keyM total_alpha_G;
rct::keyM total_alpha_H;
rct::keyV c_0;
rct::keyV s;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(1)
if (version < 1)
return false;
FIELD(sigs)
FIELD(ignore)
FIELD(used_L)
FIELD(signing_keys)
FIELD(msout)
FIELD(total_alpha_G)
FIELD(total_alpha_H)
FIELD(c_0)
FIELD(s)
END_SERIALIZE()
};
// The convention for destinations is:
// dests does not include change
// splitted_dsts (in construction_data) does
struct pending_tx
{
cryptonote::transaction tx;
uint64_t dust, fee;
bool dust_added_to_fee;
cryptonote::tx_destination_entry change_dts;
std::vector<size_t> selected_transfers;
std::string key_images;
crypto::secret_key tx_key;
std::vector<crypto::secret_key> additional_tx_keys;
std::vector<cryptonote::tx_destination_entry> dests;
std::vector<multisig_sig> multisig_sigs;
crypto::secret_key multisig_tx_key_entropy;
tx_construction_data construction_data;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(1)
FIELD(tx)
FIELD(dust)
FIELD(fee)
FIELD(dust_added_to_fee)
FIELD(change_dts)
FIELD(selected_transfers)
FIELD(key_images)
FIELD(tx_key)
FIELD(additional_tx_keys)
FIELD(dests)
FIELD(construction_data)
FIELD(multisig_sigs)
if (version < 1)
{
multisig_tx_key_entropy = crypto::null_skey;
return true;
}
FIELD(multisig_tx_key_entropy)
END_SERIALIZE()
};
// The term "Unsigned tx" is not really a tx since it's not signed yet.
// It doesnt have tx hash, key and the integrated address is not separated into addr + payment id.
struct unsigned_tx_set
{
std::vector<tx_construction_data> txes;
std::tuple<uint64_t, uint64_t, wallet2::transfer_container> transfers;
std::tuple<uint64_t, uint64_t, std::vector<wallet2::exported_transfer_details>> new_transfers;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(2)
FIELD(txes)
if (version == 0)
{
std::pair<size_t, wallet2::transfer_container> v0_transfers;
FIELD(v0_transfers);
std::get<0>(transfers) = std::get<0>(v0_transfers);
std::get<1>(transfers) = std::get<0>(v0_transfers) + std::get<1>(v0_transfers).size();
std::get<2>(transfers) = std::get<1>(v0_transfers);
return true;
}
if (version == 1)
{
std::pair<size_t, std::vector<wallet2::exported_transfer_details>> v1_transfers;
FIELD(v1_transfers);
std::get<0>(new_transfers) = std::get<0>(v1_transfers);
std::get<1>(new_transfers) = std::get<0>(v1_transfers) + std::get<1>(v1_transfers).size();
std::get<2>(new_transfers) = std::get<1>(v1_transfers);
return true;
}
FIELD(new_transfers)
END_SERIALIZE()
};
struct signed_tx_set
{
std::vector<pending_tx> ptx;
std::vector<crypto::key_image> key_images;
std::unordered_map<crypto::public_key, crypto::key_image> tx_key_images;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(ptx)
FIELD(key_images)
FIELD(tx_key_images)
END_SERIALIZE()
};
struct multisig_tx_set
{
std::vector<pending_tx> m_ptx;
std::unordered_set<crypto::public_key> m_signers;
BEGIN_SERIALIZE_OBJECT()
FIELD(m_ptx)
FIELD(m_signers)
END_SERIALIZE()
};
struct keys_file_data
{
crypto::chacha_iv iv;
std::string account_data;
BEGIN_SERIALIZE_OBJECT()
FIELD(iv)
FIELD(account_data)
END_SERIALIZE()
};
struct cache_file_data
{
crypto::chacha_iv iv;
std::string cache_data;
BEGIN_SERIALIZE_OBJECT()
FIELD(iv)
FIELD(cache_data)
END_SERIALIZE()
};
// GUI Address book
struct address_book_row
{
cryptonote::account_public_address m_address;
crypto::hash8 m_payment_id;
std::string m_description;
bool m_is_subaddress;
bool m_has_payment_id;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(m_address)
FIELD(m_payment_id)
FIELD(m_description)
FIELD(m_is_subaddress)
FIELD(m_has_payment_id)
END_SERIALIZE()
};
struct reserve_proof_entry
{
crypto::hash txid;
uint64_t index_in_tx;
crypto::public_key shared_secret;
crypto::key_image key_image;
crypto::signature shared_secret_sig;
crypto::signature key_image_sig;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(txid)
VARINT_FIELD(index_in_tx)
FIELD(shared_secret)
FIELD(key_image)
FIELD(shared_secret_sig)
FIELD(key_image_sig)
END_SERIALIZE()
};
struct background_synced_tx_t
{
uint64_t index_in_background_sync_data;
cryptonote::transaction tx;
std::vector<uint64_t> output_indices;
uint64_t height;
uint64_t block_timestamp;
bool double_spend_seen;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
VARINT_FIELD(index_in_background_sync_data)
// prune tx; don't need to keep signature data
if (!tx.serialize_base(ar))
return false;
FIELD(output_indices)
VARINT_FIELD(height)
VARINT_FIELD(block_timestamp)
FIELD(double_spend_seen)
END_SERIALIZE()
};
struct background_sync_data_t
{
bool first_refresh_done = false;
uint64_t start_height = 0;
std::unordered_map<crypto::hash, background_synced_tx_t> txs;
// Relevant wallet settings
uint64_t wallet_refresh_from_block_height;
size_t subaddress_lookahead_major;
size_t subaddress_lookahead_minor;
RefreshType wallet_refresh_type;
BEGIN_SERIALIZE_OBJECT()
VERSION_FIELD(0)
FIELD(first_refresh_done)
FIELD(start_height)
FIELD(txs)
FIELD(wallet_refresh_from_block_height)
VARINT_FIELD(subaddress_lookahead_major)
VARINT_FIELD(subaddress_lookahead_minor)
VARINT_FIELD(wallet_refresh_type)
END_SERIALIZE()
};
typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
struct parsed_block
{
crypto::hash hash;
cryptonote::block block;
std::vector<cryptonote::transaction> txes;
cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices o_indices;
bool error;
};
struct is_out_data
{
crypto::public_key pkey;
crypto::key_derivation derivation;
std::vector<boost::optional<cryptonote::subaddress_receive_info>> received;
};
struct tx_cache_data
{
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
std::vector<is_out_data> primary;
std::vector<is_out_data> additional;
bool empty() const { return tx_extra_fields.empty() && primary.empty() && additional.empty(); }
};
struct detached_blockchain_data
{
hashchain detached_blockchain;
size_t original_chain_size;
std::unordered_set<crypto::hash> detached_tx_hashes;
std::unordered_map<crypto::hash, std::vector<cryptonote::tx_destination_entry>> detached_confirmed_txs_dests;
};
struct process_tx_entry_t
{
cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry tx_entry;
cryptonote::transaction tx;
crypto::hash tx_hash;
};
struct tx_entry_data
{
std::vector<process_tx_entry_t> tx_entries;
uint64_t lowest_height;
uint64_t highest_height;
tx_entry_data(): lowest_height((uint64_t)-1), highest_height(0) {}
};
/*!
* \brief Generates a wallet or restores one. Assumes the multisig setup
* has already completed for the provided multisig info.
* \param wallet_ Name of wallet file
* \param password Password of wallet file
* \param multisig_data The multisig restore info and keys
* \param create_address_file Whether to create an address file
*/
void generate(const std::string& wallet_, const epee::wipeable_string& password,
const epee::wipeable_string& multisig_data, bool create_address_file = false);
/*!
* \brief Generates a wallet or restores one.
* \param wallet_ Name of wallet file
* \param password Password of wallet file
* \param recovery_param If it is a restore, the recovery key
* \param recover Whether it is a restore
* \param two_random Whether it is a non-deterministic wallet
* \param create_address_file Whether to create an address file
* \return The secret key of the generated wallet
*/
crypto::secret_key generate(const std::string& wallet, const epee::wipeable_string& password,
const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false,
bool two_random = false, bool create_address_file = false);
/*!
* \brief Creates a wallet from a public address and a spend/view secret key pair.
* \param wallet_ Name of wallet file
* \param password Password of wallet file
* \param account_public_address The account's public address
* \param spendkey spend secret key
* \param viewkey view secret key
* \param create_address_file Whether to create an address file
*/
void generate(const std::string& wallet, const epee::wipeable_string& password,
const cryptonote::account_public_address &account_public_address,
const crypto::secret_key& spendkey, const crypto::secret_key& viewkey, bool create_address_file = false);
/*!
* \brief Creates a watch only wallet from a public address and a view secret key.
* \param wallet_ Name of wallet file
* \param password Password of wallet file
* \param account_public_address The account's public address
* \param viewkey view secret key
* \param create_address_file Whether to create an address file
*/
void generate(const std::string& wallet, const epee::wipeable_string& password,
const cryptonote::account_public_address &account_public_address,
const crypto::secret_key& viewkey = crypto::secret_key(), bool create_address_file = false);
/*!
* \brief Restore a wallet hold by an HW.
* \param wallet_ Name of wallet file
* \param password Password of wallet file
* \param device_name name of HW to use
* \param create_address_file Whether to create an address file
*/
void restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name, bool create_address_file = false);
private:
/*!
* \brief Decrypts the account keys
* \return an RAII reencryptor for the account keys
*/
epee::misc_utils::auto_scope_leave_caller decrypt_account_for_multisig(const epee::wipeable_string &password);
/*!
* \brief Creates an uninitialized multisig account
* \outparam: the uninitialized multisig account
*/
void get_uninitialized_multisig_account(multisig::multisig_account &account_out) const;
/*!
* \brief Reconstructs a multisig account from wallet2 state
* \outparam: the reconstructed multisig account
*/
void get_reconstructed_multisig_account(multisig::multisig_account &account_out) const;
public:
/*!
* \brief Creates a multisig wallet
* \return empty if done, non empty if we need to send another string
* to other participants
*/
std::string make_multisig(const epee::wipeable_string &password,
const std::vector<std::string> &kex_messages,
const std::uint32_t threshold);
/*!
* \brief Increment the multisig key exchange round
* \return empty if done, non empty if we need to send another string
* to other participants
*/
std::string exchange_multisig_keys(const epee::wipeable_string &password,
const std::vector<std::string> &kex_messages,
const bool force_update_use_with_caution = false);
/*!
* \brief Get initial message to start multisig key exchange (before 'make_multisig()' is called)
* \return string to send to other participants
*/
std::string get_multisig_first_kex_msg() const;
/*!
* \brief Use multisig kex messages for an in-progress kex round to 'boost' the following round for another group member
*/
std::string get_multisig_key_exchange_booster(const epee::wipeable_string &password,
const std::vector<std::string> &kex_messages,
const std::uint32_t threshold,
const std::uint32_t num_signers);
/*!
* Export multisig info