-
Notifications
You must be signed in to change notification settings - Fork 656
Expand file tree
/
Copy pathwallet.hpp
More file actions
1975 lines (1830 loc) · 97.9 KB
/
Copy pathwallet.hpp
File metadata and controls
1975 lines (1830 loc) · 97.9 KB
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) 2017 Cryptonomex, Inc., and contributors.
*
* The MIT License
*
* 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.
*/
#pragma once
#include <fc/optional.hpp>
#include <graphene/chain/htlc_object.hpp>
#include <graphene/app/api.hpp>
#include <graphene/utilities/key_conversion.hpp>
#include "wallet_structs.hpp"
namespace fc
{
void to_variant( const account_multi_index_type& accts, variant& vo, uint32_t max_depth );
void from_variant( const variant &var, account_multi_index_type &vo, uint32_t max_depth );
}
namespace graphene { namespace wallet {
/**
* This class takes a variant and turns it into an object
* of the given type, with the new operator.
*/
object* create_object( const variant& v );
/**
* This wallet assumes it is connected to the database server with a high-bandwidth, low-latency connection and
* performs minimal caching. This API could be provided locally to be used by a web interface.
*/
class wallet_api
{
public:
// Variables
fc::signal<void(bool)> lock_changed;
std::shared_ptr<detail::wallet_api_impl> my;
// Methods
wallet_api( const wallet_data& initial_data, const fc::api<login_api>& rapi );
virtual ~wallet_api();
bool copy_wallet_file( const string& destination_filename )const;
fc::ecc::private_key derive_private_key( const string& prefix_string, uint32_t sequence_number ) const;
/** Returns info about head block, chain_id, maintenance, participation, current active witnesses and
* committee members.
* @returns runtime info about the blockchain
*/
variant info()const;
/** Returns info such as client version, git version of graphene/fc, version of boost, openssl.
* @returns compile time info and client and dependencies versions
*/
variant_object about() const;
/** Returns info about a specified block.
* @param num height of the block to retrieve
* @returns info about the block, or null if not found
*/
optional<signed_block_with_info> get_block( uint32_t num )const;
/** Returns the number of accounts registered on the blockchain
* @returns the number of registered accounts
*/
uint64_t get_account_count()const;
/** Lists all accounts controlled by this wallet.
* This returns a list of the full account objects for all accounts whose private keys
* we possess.
* @returns a list of account objects
*/
vector<account_object> list_my_accounts()const;
/** Lists all accounts registered in the blockchain.
* This returns a list of all account names and their account ids, sorted by account name.
*
* Use the \c lowerbound and limit parameters to page through the list. To retrieve all accounts,
* start by setting \c lowerbound to the empty string \c "", and then each iteration, pass
* the last account name returned as the \c lowerbound for the next \c list_accounts() call.
*
* @param lowerbound the name of the first account to return. If the named account does not exist,
* the list will start at the account that comes after \c lowerbound
* @param limit the maximum number of accounts to return (max: 1000)
* @returns a list of accounts mapping account names to account ids
*/
map<string, account_id_type, std::less<>> list_accounts( const string& lowerbound, uint32_t limit )const;
/** List the balances of an account.
* Each account can have multiple balances, one for each type of asset owned by that
* account. The returned list will only contain assets for which the account has a
* nonzero balance
* @param account_name_or_id the name or id of the account whose balances you want
* @returns a list of the given account's balances
*/
vector<asset> list_account_balances( const string& account_name_or_id )const;
/** Lists all assets registered on the blockchain.
*
* To list all assets, pass the empty string \c "" for the lowerbound to start
* at the beginning of the list, and iterate as necessary.
*
* @param lowerbound the symbol of the first asset to include in the list.
* @param limit the maximum number of assets to return (max: 100)
* @returns the list of asset objects, ordered by symbol
*/
vector<extended_asset_object> list_assets( const string& lowerbound, uint32_t limit )const;
/** Returns assets count registered on the blockchain.
*
* @returns assets count
*/
uint64_t get_asset_count()const;
/** Returns the most recent operations on the named account.
*
* This returns a list of operation history objects, which describe activity on the account.
*
* @param account_name_or_id the name or id of the account
* @param limit the number of entries to return (starting from the most recent)
* @returns a list of \c operation_history_objects
*/
vector<operation_detail> get_account_history( const string& account_name_or_id, uint32_t limit )const;
/** Returns the relative operations on the named account from start number.
*
* @param account_name_or_id the name or id of the account
* @param stop Sequence number of earliest operation.
* @param limit the number of entries to return
* @param start the sequence number where to start looping back throw the history
* @returns a list of \c operation_history_objects
*/
vector<operation_detail> get_relative_account_history( const string& account_name_or_id, uint32_t stop,
uint32_t limit, uint32_t start )const;
/**
* @brief Fetch all objects relevant to the specified account
* @param name_or_id Must be the name or ID of an account to retrieve
* @return All info about the specified account
*
* This function fetches all relevant objects for the given account. If the string
* of \c name_or_id cannot be tied to an account, that input will be ignored.
*
*/
full_account get_full_account( const string& name_or_id )const;
/**
* @brief Get OHLCV data of a trading pair in a time range
* @param symbol symbol or ID of the base asset
* @param symbol2 symbol or ID of the quote asset
* @param bucket length of each time bucket in seconds.
* @param start the start of a time range, E.G. "2018-01-01T00:00:00"
* @param end the end of the time range
* @return A list of OHLCV data, in "least recent first" order.
*/
vector<bucket_object> get_market_history( const string& symbol, const string& symbol2, uint32_t bucket,
const time_point_sec& start, const time_point_sec& end )const;
/**
* @brief Fetch all orders relevant to the specified account sorted descendingly by price
*
* @param name_or_id The name or ID of an account to retrieve
* @param base Base asset
* @param quote Quote asset
* @param limit The limitation of items each query can fetch (max: 101)
* @param ostart_id Start order id, fetch orders which price are lower than or equal to this order
* @param ostart_price Fetch orders with price lower than or equal to this price
*
* @return List of orders from \c name_or_id to the corresponding account
*
* @note
* 1. if \c name_or_id cannot be tied to an account, empty result will be returned
* 2. \c ostart_id and \c ostart_price can be \c null, if so the api will return the "first page" of orders.
* if \c ostart_id is specified and valid, its price will be used to do page query preferentially,
* otherwise the \c ostart_price will be used
*/
vector<limit_order_object> get_account_limit_orders( const string& name_or_id,
const string& base,
const string& quote,
uint32_t limit = 101,
const optional<limit_order_id_type>& ostart_id = {},
const optional<price>& ostart_price = optional<price>() )const;
/**
* @brief Get limit orders in a given market
* @param a symbol or ID of asset being sold
* @param b symbol or ID of asset being purchased
* @param limit Maximum number of orders to retrieve
* @return The limit orders, ordered from least price to greatest
*/
vector<limit_order_object> get_limit_orders( const string& a, const string& b, uint32_t limit )const;
/**
* @brief Get call orders (aka margin positions) for a given asset
* @param asset_symbol_or_id symbol or ID of the debt asset
* @param limit Maximum number of orders to retrieve
* @return The call orders, ordered from earliest to be called to latest
*/
vector<call_order_object> get_call_orders( const string& asset_symbol_or_id, uint32_t limit )const;
/**
* @brief Get forced settlement orders in a given asset
* @param a Symbol or ID of asset being settled
* @param limit Maximum number of orders to retrieve
* @return The settle orders, ordered from earliest settlement date to latest
*/
vector<force_settlement_object> get_settle_orders( const string& a, uint32_t limit )const;
/** Returns the collateral_bid object for the given MPA
*
* @param asset_symbol_or_id the symbol or id of the asset
* @param limit the number of entries to return
* @param start the sequence number where to start looping back throw the history
* @returns a list of \c collateral_bid_objects
*/
vector<collateral_bid_object> get_collateral_bids( const string& asset_symbol_or_id, uint32_t limit = 100,
uint32_t start = 0 )const;
/** Returns the block chain's slowly-changing settings.
* This object contains all of the properties of the blockchain that are fixed
* or that change only once per maintenance interval (daily) such as the
* current list of witnesses, committee_members, block interval, etc.
* @see \c get_dynamic_global_properties() for frequently changing properties
* @returns the global properties
*/
global_property_object get_global_properties() const;
/**
* Get operations relevant to the specified account filtering by operation type, with transaction id
*
* @param account_name_or_id the name or id of the account, whose history shoulde be queried
* @param operation_types The IDs of the operation we want to get operations in the account
* ( 0 = transfer , 1 = limit order create, ...)
* @param start the sequence number where to start looping back throw the history
* @param limit the max number of entries to return (from start number)
* @returns account_history_operation_detail
*/
account_history_operation_detail get_account_history_by_operations( const string& account_name_or_id,
const flat_set<uint16_t>& operation_types,
uint32_t start, uint32_t limit )const;
/** Returns the block chain's rapidly-changing properties.
* The returned object contains information that changes every block interval
* such as the head block number, the next witness, etc.
* @see \c get_global_properties() for less-frequently changing properties
* @returns the dynamic global properties
*/
dynamic_global_property_object get_dynamic_global_properties() const;
/** Returns information about the given account.
*
* @param account_name_or_id the name or ID of the account to provide information about
* @returns the public account data stored in the blockchain
*/
account_object get_account( const string& account_name_or_id ) const;
/** Returns information about the given asset.
* @param asset_symbol_or_id the symbol or id of the asset in question
* @returns the information about the asset stored in the block chain
*/
extended_asset_object get_asset( const string& asset_symbol_or_id ) const;
/** Returns the BitAsset-specific data for a given asset.
* Market-issued assets's behavior are determined both by their "BitAsset Data" and
* their basic asset data, as returned by \c get_asset().
* @param asset_symbol_or_id the symbol or id of the BitAsset in question
* @returns the BitAsset-specific data for this asset
*/
asset_bitasset_data_object get_bitasset_data( const string& asset_symbol_or_id )const;
/**
* Returns information about the given HTLC object.
* @param htlc_id the id of the HTLC object.
* @returns the information about the HTLC object
*/
optional<variant> get_htlc( const htlc_id_type& htlc_id ) const;
/** Lookup the id of a named account.
* @param account_name_or_id the name or ID of the account to look up
* @returns the id of the named account
*/
account_id_type get_account_id( const string& account_name_or_id ) const;
/** Lookup the name of an account.
* @param account_name_or_id the name or ID of the account to look up
* @returns the name of the account
*/
string get_account_name( const string& account_name_or_id ) const
{ return get_account( account_name_or_id ).name; }
/**
* Lookup the id of an asset.
* @param asset_symbol_or_id the symbol or ID of an asset to look up
* @returns the id of the given asset
*/
asset_id_type get_asset_id( const string& asset_symbol_or_id ) const;
/**
* Lookup the symbol of an asset.
* @param asset_symbol_or_id the symbol or ID of an asset to look up
* @returns the symbol of the given asset
*/
string get_asset_symbol( const string& asset_symbol_or_id ) const
{ return get_asset( asset_symbol_or_id ).symbol; }
/**
* Lookup the symbol of an asset. Synonym of @ref get_asset_symbol.
* @param asset_symbol_or_id the symbol or ID of an asset to look up
* @returns the symbol of the given asset
*/
string get_asset_name( const string& asset_symbol_or_id ) const
{ return get_asset_symbol( asset_symbol_or_id ); }
/**
* Returns the blockchain object corresponding to the given id.
*
* This generic function can be used to retrieve any object from the blockchain
* that is assigned an ID. Certain types of objects have specialized convenience
* functions to return their objects -- e.g., assets have \c get_asset(), accounts
* have \c get_account(), but this function will work for any object.
*
* @param id the id of the object to return
* @returns the requested object
*/
variant get_object( const object_id_type& id ) const;
/** Returns the current wallet filename.
*
* This is the filename that will be used when automatically saving the wallet.
*
* @see set_wallet_filename()
* @return the wallet filename
*/
string get_wallet_filename() const;
/**
* Get the WIF private key corresponding to a public key. The
* private key must already be in the wallet.
* @param pubkey a public key in Base58 format
* @return the WIF private key
*/
string get_private_key( const public_key_type& pubkey )const;
/**
* @ingroup Transaction Builder API
*
* Create a new transaction builder.
* @return handle of the new transaction builder
*/
transaction_handle_type begin_builder_transaction()const;
/**
* @ingroup Transaction Builder API
*
* Append a new operation to a transaction builder.
* @param transaction_handle handle of the transaction builder
* @param op the operation in JSON format
*/
void add_operation_to_builder_transaction( transaction_handle_type transaction_handle,
const operation& op )const;
/**
* @ingroup Transaction Builder API
*
* Replace an operation in a transaction builder with a new operation.
* @param handle handle of the transaction builder
* @param operation_index the index of the old operation in the builder to be replaced
* @param new_op the new operation in JSON format
*/
void replace_operation_in_builder_transaction( transaction_handle_type handle,
uint32_t operation_index,
const operation& new_op )const;
/**
* @ingroup Transaction Builder API
*
* Calculate and update fees for the operations in a transaction builder.
* @param handle handle of the transaction builder
* @param fee_asset symbol or ID of an asset that to be used to pay fees
* @return total fees
*/
asset set_fees_on_builder_transaction( transaction_handle_type handle,
const string& fee_asset = GRAPHENE_SYMBOL )const;
/**
* @ingroup Transaction Builder API
*
* Show content of a transaction builder.
* @param handle handle of the transaction builder
* @return a transaction
*/
transaction preview_builder_transaction( transaction_handle_type handle )const;
/**
* @ingroup Transaction Builder API
*
* Sign the transaction in a transaction builder and optionally broadcast to the network.
* @param transaction_handle handle of the transaction builder
* @param broadcast whether to broadcast the signed transaction to the network
* @return a signed transaction
*/
signed_transaction sign_builder_transaction( transaction_handle_type transaction_handle,
bool broadcast = true )const;
/**
* @ingroup Transaction Builder API
*
* Sign the transaction in a transaction builder and optionally broadcast to the network.
* @param transaction_handle handle of the transaction builder
* @param signing_keys Keys that must be used when signing the transaction
* @param broadcast whether to broadcast the signed transaction to the network
* @return a signed transaction
*/
signed_transaction sign_builder_transaction2( transaction_handle_type transaction_handle,
const vector<public_key_type>& signing_keys = vector<public_key_type>(),
bool broadcast = true )const;
/** Broadcast signed transaction
* @param tx signed transaction
* @returns the transaction ID along with the signed transaction.
*/
pair<transaction_id_type,signed_transaction> broadcast_transaction( const signed_transaction& tx )const;
/**
* @ingroup Transaction Builder API
*
* Create a proposal containing the operations in a transaction builder (create a new proposal_create
* operation, then replace the transaction builder with the new operation), then sign the transaction
* and optionally broadcast to the network.
*
* Note: this command is buggy because unable to specify proposer. It will be deprecated in a future release.
* Please use \c propose_builder_transaction2() instead.
*
* @param handle handle of the transaction builder
* @param expiration when the proposal will expire
* @param review_period_seconds review period of the proposal in seconds
* @param broadcast whether to broadcast the signed transaction to the network
* @return a signed transaction
*/
signed_transaction propose_builder_transaction(
transaction_handle_type handle,
const time_point_sec& expiration = time_point::now() + fc::minutes(1),
uint32_t review_period_seconds = 0,
bool broadcast = true
)const;
/**
* @ingroup Transaction Builder API
*
* Create a proposal containing the operations in a transaction builder (create a new proposal_create
* operation, then replace the transaction builder with the new operation), then sign the transaction
* and optionally broadcast to the network.
*
* @param handle handle of the transaction builder
* @param account_name_or_id name or ID of the account who would pay fees for creating the proposal
* @param expiration when the proposal will expire
* @param review_period_seconds review period of the proposal in seconds
* @param broadcast whether to broadcast the signed transaction to the network
* @return a signed transaction
*/
signed_transaction propose_builder_transaction2(
transaction_handle_type handle,
const string& account_name_or_id,
const time_point_sec& expiration = time_point::now() + fc::minutes(1),
uint32_t review_period_seconds = 0,
bool broadcast = true
)const;
/**
* @ingroup Transaction Builder API
*
* Destroy a transaction builder.
* @param handle handle of the transaction builder
*/
void remove_builder_transaction(transaction_handle_type handle)const;
/** Checks whether the wallet has just been created and has not yet had a password set.
*
* Calling \c set_password will transition the wallet to the locked state.
* @return true if the wallet is new
* @ingroup Wallet Management
*/
bool is_new()const;
/** Checks whether the wallet is locked (is unable to use its private keys).
*
* This state can be changed by calling \c lock() or \c unlock().
* @return true if the wallet is locked
* @ingroup Wallet Management
*/
bool is_locked()const;
/** Locks the wallet immediately.
* @ingroup Wallet Management
*/
void lock()const;
/** Unlocks the wallet.
*
* The wallet remain unlocked until the \c lock is called
* or the program exits.
*
* When used in command line, if typed "unlock" without a password followed, the user will be prompted
* to input a password without echo.
*
* @param password the password previously set with \c set_password()
* @ingroup Wallet Management
*/
void unlock( const string& password )const;
/** Sets a new password on the wallet.
*
* The wallet must be either 'new' or 'unlocked' to
* execute this command.
*
* When used in command line, if typed "set_password" without a password followed, the user will be prompted
* to input a password without echo.
*
* @param password a new password
* @ingroup Wallet Management
*/
void set_password( const string& password )const;
/** Dumps all private keys owned by the wallet.
*
* The keys are printed in WIF format. You can import these keys into another wallet
* using \c import_key()
* @returns a map containing the private keys, indexed by their public key
*/
map<public_key_type, string> dump_private_keys()const;
/** Returns a list of all commands supported by the wallet API.
*
* This lists each command, along with its arguments and return types.
* For more detailed help on a single command, use \c gethelp()
*
* @returns a multi-line string suitable for displaying on a terminal
*/
string help()const;
/** Returns detailed help on a single API command.
* @param method the name of the API command you want help with
* @returns a multi-line string suitable for displaying on a terminal
*/
string gethelp( const string& method )const;
/** Loads a specified BitShares wallet.
*
* The current wallet is closed before the new wallet is loaded.
*
* @warning This does not change the filename that will be used for future
* wallet writes, so this may cause you to overwrite your original
* wallet unless you also call \c set_wallet_filename()
*
* @param wallet_filename the filename of the wallet JSON file to load.
* If \c wallet_filename is empty, it reloads the
* existing wallet file
* @returns true if the specified wallet is loaded
*/
bool load_wallet_file( const string& wallet_filename = "" )const;
/** Quit from the wallet.
*
* The current wallet will be closed and saved.
*/
void quit()const;
/** Saves the current wallet to the given filename.
*
* @warning This does not change the wallet filename that will be used for future
* writes, so think of this function as 'Save a Copy As...' instead of
* 'Save As...'. Use \c set_wallet_filename() to make the filename
* persist.
* @param wallet_filename the filename of the new wallet JSON file to create
* or overwrite. If \c wallet_filename is empty,
* save to the current filename.
*/
void save_wallet_file( const string& wallet_filename = "" )const;
/** Sets the wallet filename used for future writes.
*
* This does not trigger a save, it only changes the default filename
* that will be used the next time a save is triggered.
*
* @param wallet_filename the new filename to use for future saves
*/
void set_wallet_filename( const string& wallet_filename )const;
/** Suggests a safe brain key to use for creating your account.
* \c create_account_with_brain_key() requires you to specify a 'brain key',
* a long passphrase that provides enough entropy to generate cyrptographic
* keys. This function will suggest a suitably random string that should
* be easy to write down (and, with effort, memorize).
* @returns a suggested brain_key
*/
brain_key_info suggest_brain_key()const;
/**
* Derive any number of *possible* owner keys from a given brain key.
*
* NOTE: These keys may or may not match with the owner keys of any account.
* This function is merely intended to assist with account or key recovery.
*
* @see suggest_brain_key()
*
* @param brain_key Brain key
* @param number_of_desired_keys Number of desired keys
* @return A list of keys that are deterministically derived from the brainkey
*/
vector<brain_key_info> derive_owner_keys_from_brain_key( const string& brain_key,
uint32_t number_of_desired_keys = 1 ) const;
/**
* Determine whether a textual representation of a public key
* (in Base-58 format) is *currently* linked
* to any *registered* (i.e. non-stealth) account on the blockchain
* @param public_key Public key
* @return Whether a public key is known
*/
bool is_public_key_registered( const string& public_key ) const;
/** Converts a signed_transaction in JSON form to its binary representation.
*
* @param tx the transaction to serialize
* @returns the binary form of the transaction, hex encoded.
*/
string serialize_transaction( const signed_transaction& tx ) const;
/** Imports the private key for an existing account.
*
* The private key must match either an owner key or an active key for the
* named account.
*
* @see dump_private_keys()
*
* @param account_name_or_id the account owning the key
* @param wif_key the private key in WIF format
* @returns true if the key was imported
*/
bool import_key( const string& account_name_or_id, const string& wif_key )const;
/** Imports accounts from a BitShares 0.x wallet file.
* Current wallet file must be unlocked to perform the import.
*
* @param filename the BitShares 0.x wallet file to import
* @param password the password to encrypt the BitShares 0.x wallet file
* @returns a map containing the accounts found and whether imported
*/
map<string, bool, std::less<>> import_accounts( const string& filename, const string& password )const;
/** Imports from a BitShares 0.x wallet file, find keys that were bound to a given account name on the
* BitShares 0.x chain, rebind them to an account name on the 2.0 chain.
* Current wallet file must be unlocked to perform the import.
*
* @param filename the BitShares 0.x wallet file to import
* @param password the password to encrypt the BitShares 0.x wallet file
* @param src_account_name name of the account on BitShares 0.x chain
* @param dest_account_name name of the account on BitShares 2.0 chain,
* can be same or different to \c src_account_name
* @returns whether the import has succeeded
*/
bool import_account_keys( const string& filename, const string& password,
const string& src_account_name, const string& dest_account_name )const;
/**
* This call will construct transaction(s) that will claim all balances controled
* by wif_keys and deposit them into the given account.
*
* @param account_name_or_id name or ID of an account that to claim balances to
* @param wif_keys private WIF keys of balance objects to claim balances from
* @param broadcast true to broadcast the transaction on the network
*/
vector< signed_transaction > import_balance( const string& account_name_or_id, const vector<string>& wif_keys,
bool broadcast )const;
/** Transforms a brain key to reduce the chance of errors when re-entering the key from memory.
*
* This takes a user-supplied brain key and normalizes it into the form used
* for generating private keys. In particular, this upper-cases all ASCII characters
* and collapses multiple spaces into one.
* @param s the brain key as supplied by the user
* @returns the brain key in its normalized form
*/
string normalize_brain_key( const string& s ) const;
/** Registers a third party's account on the blockckain.
*
* This function is used to register an account for which you do not own the private keys.
* When acting as a registrar, an end user will generate their own private keys and send
* you the public keys. The registrar will use this function to register the account
* on behalf of the end user.
*
* @see create_account_with_brain_key()
*
* @param name the name of the account, must be unique on the blockchain. Shorter names
* are more expensive to register. The rules are still in flux, but in general
* names of more than 8 characters with at least one digit will be cheap.
* @param owner the owner key for the new account
* @param active the active key for the new account
* @param registrar_account the account which will pay the fee to register the user
* @param referrer_account the account who is acting as a referrer, and may receive a
* portion of the user's transaction fees. This can be the
* same as the registrar_account if there is no referrer.
* @param referrer_percent the percentage (0 - 100) of the new user's transaction fees
* not claimed by the blockchain that will be distributed to the
* referrer, the rest will be sent to the registrar. Will be
* multiplied by GRAPHENE_1_PERCENT when constructing the transaction.
* @param broadcast true to broadcast the transaction on the network
* @returns the signed transaction registering the account
*/
signed_transaction register_account( const string& name,
const public_key_type& owner,
const public_key_type& active,
const string& registrar_account,
const string& referrer_account,
uint32_t referrer_percent,
bool broadcast = false )const;
/**
* Upgrades an account to prime status.
* This makes the account holder a 'lifetime member'.
*
* @param account_name_or_id the name or id of the account to upgrade
* @param broadcast true to broadcast the transaction on the network
* @returns the signed transaction upgrading the account
*/
signed_transaction upgrade_account( const string& account_name_or_id, bool broadcast )const;
/** Creates a new account and registers it on the blockchain.
*
* @todo why no referrer_percent here?
*
* @see suggest_brain_key()
* @see register_account()
*
* @param brain_key the brain key used for generating the account's private keys
* @param account_name the name of the account, must be unique on the blockchain.
* Names with only latin letters and at least one vowel are
* premium names and expensive to register.
* Names with only consonants, or at least with a digit, a dot or
* a minus sign are cheap.
* @param registrar_account the account which will pay the fee to register the user
* @param referrer_account the account who is acting as a referrer, and may receive a
* portion of the user's transaction fees. This can be the
* same as the registrar_account if there is no referrer.
* @param broadcast true to broadcast the transaction on the network
* @returns the signed transaction registering the account
*/
signed_transaction create_account_with_brain_key( const string& brain_key,
const string& account_name,
const string& registrar_account,
const string& referrer_account,
bool broadcast = false )const;
/** Transfer an amount from one account to another.
* @param from the name or id of the account sending the funds
* @param to the name or id of the account receiving the funds
* @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5)
* @param asset_symbol_or_id the symbol or id of the asset to send
* @param memo a memo to attach to the transaction. The memo will be encrypted in the
* transaction and readable for the receiver. There is no length limit
* other than the limit imposed by maximum transaction size, but transaction
* increase with transaction size
* @param broadcast true to broadcast the transaction on the network
* @returns the signed transaction transferring funds
*/
signed_transaction transfer( const string& from,
const string& to,
const string& amount,
const string& asset_symbol_or_id,
const string& memo,
bool broadcast = false )const;
/**
* This method works just like transfer, except it always broadcasts and
* returns the transaction ID (hash) along with the signed transaction.
* @param from the name or id of the account sending the funds
* @param to the name or id of the account receiving the funds
* @param amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5)
* @param asset_symbol_or_id the symbol or id of the asset to send
* @param memo a memo to attach to the transaction. The memo will be encrypted in the
* transaction and readable for the receiver. There is no length limit
* other than the limit imposed by maximum transaction size, but transaction
* increase with transaction size
* @returns the transaction ID (hash) along with the signed transaction transferring funds
*/
pair<transaction_id_type,signed_transaction> transfer2( const string& from,
const string& to,
const string& amount,
const string& asset_symbol_or_id,
const string& memo ) const {
auto trx = transfer( from, to, amount, asset_symbol_or_id, memo, true );
return std::make_pair(trx.id(),trx);
}
/**
* This method is used to convert a JSON transaction to its transactin ID.
* @param trx a JSON transaction
* @return the ID (hash) of the transaction
*/
transaction_id_type get_transaction_id( const signed_transaction& trx )const { return trx.id(); }
/** Sign a memo message.
*
* @param from the name or id of signing account, or a public key, or a label of a public key
* @param to the name or id of receiving account, or a public key, or a label of a public key
* @param memo text to sign
* @return the signed memo data
*/
memo_data sign_memo( const string& from, const string& to, const string& memo )const;
/** Read a memo.
*
* @param memo JSON-encoded memo.
* @returns string with decrypted message.
*/
string read_memo( const memo_data& memo )const;
/** Sign a message using an account's memo key. The signature is generated as in
* https://github.com/xeroc/python-graphenelib/blob/d9634d74/graphenecommon/message.py#L64 .
*
* @param signer the name or id of signing account
* @param message text to sign
* @return the signed message in an abstract format
*/
signed_message sign_message( const string& signer, const string& message )const;
/** Verify a message signed with sign_message using the given account's memo key.
*
* @param message the message text
* @param account the account name of the message
* @param block the block number of the message
* @param msg_time the timestamp of the message
* @param sig the message signature
* @return true if signature matches
*/
bool verify_message( const string& message, const string& account, int32_t block, const string& msg_time,
const fc::ecc::compact_signature& sig )const;
/** Verify a message signed with sign_message
*
* @param message the signed_message structure containing message, meta data and signature
* @return true if signature matches
*/
bool verify_signed_message( const signed_message& message )const;
/** Verify a message signed with sign_message, in its encapsulated form.
*
* @param message the complete encapsulated message string including separators and line feeds
* @return true if signature matches
*/
bool verify_encapsulated_message( const string& message )const;
/** These methods are used for stealth transfers */
///@{
/**
* This method can be used to set a label for a public key
*
* @note No two keys can have the same label.
* @param key a public key
* @param label a user-defined string as label
* @return true if the label was set, otherwise false
*/
bool set_key_label( const public_key_type& key, const string& label )const;
/**
* Get label of a public key.
* @param key a public key
* @return the label if already set by \c set_key_label(), or an empty string if not set
*/
string get_key_label( const public_key_type& key )const;
/**
* Generates a new blind account for the given brain key and assigns it the given label.
* @param label a label
* @param brain_key the brain key to be used to generate a new blind account
* @return the public key of the new account
*/
public_key_type create_blind_account( const string& label, const string& brain_key )const;
/**
* Return the total balances of all blinded commitments that can be claimed by the
* given account key or label.
* @param key_or_label a public key in Base58 format or a label
* @return the total balances of all blinded commitments that can be claimed by the
* given account key or label
*/
vector<asset> get_blind_balances( const string& key_or_label )const;
/**
* Get all blind accounts.
* @return all blind accounts
*/
map<string, public_key_type, std::less<>> get_blind_accounts()const;
/**
* Get all blind accounts for which this wallet has the private key.
* @return all blind accounts for which this wallet has the private key
*/
map<string, public_key_type, std::less<>> get_my_blind_accounts()const;
/**
* Get the public key associated with a given label.
* @param label a label
* @return the public key associated with the given label
*/
public_key_type get_public_key( const string& label )const;
///@}
/**
* Get all blind receipts to/form a particular account
* @param key_or_account a public key in Base58 format or an account
* @return all blind receipts to/form the account
*/
vector<blind_receipt> blind_history( const string& key_or_account )const;
/**
* Given a confirmation receipt, this method will parse it for a blinded balance and confirm
* that it exists in the blockchain. If it exists then it will report the amount received and
* who sent it.
*
* @param confirmation_receipt a base58 encoded stealth confirmation
* @param opt_from if not empty and the sender is a unknown public key,
* then the unknown public key will be given the label \c opt_from
* @param opt_memo a self-defined label for this transfer to be saved in local wallet file
* @return a blind receipt
*/
blind_receipt receive_blind_transfer( const string& confirmation_receipt,
const string& opt_from,
const string& opt_memo )const;
/**
* Transfers a public balance from \c from_account_name_or_id to one or more blinded balances using a
* stealth transfer.
* @param from_account_name_or_id name or ID of an account to transfer from
* @param asset_symbol_or_id symbol or ID of the asset to be transferred
* @param to_amounts map from key or label to amount
* @param broadcast true to broadcast the transaction on the network
* @return a blind confirmation
*/
blind_confirmation transfer_to_blind( const string& from_account_name_or_id,
const string& asset_symbol_or_id,
const vector<pair<string, string>>& to_amounts,
bool broadcast = false )const;
/**
* Transfers funds from a set of blinded balances to a public account balance.
* @param from_blind_account_key_or_label a public key in Base58 format or a label to transfer from
* @param to_account_name_or_id name or ID of an account to transfer to
* @param amount the amount to be transferred
* @param asset_symbol_or_id symbol or ID of the asset to be transferred
* @param broadcast true to broadcast the transaction on the network
* @return a blind confirmation
*/
blind_confirmation transfer_from_blind( const string& from_blind_account_key_or_label,
const string& to_account_name_or_id,
const string& amount,
const string& asset_symbol_or_id,
bool broadcast = false )const;
/**
* Transfer from one set of blinded balances to another.
* @param from_key_or_label a public key in Base58 format or a label to transfer from
* @param to_key_or_label a public key in Base58 format or a label to transfer to
* @param amount the amount to be transferred
* @param symbol_or_id symbol or ID of the asset to be transferred
* @param broadcast true to broadcast the transaction on the network
* @return a blind confirmation
*/
blind_confirmation blind_transfer( const string& from_key_or_label,
const string& to_key_or_label,
const string& amount,
const string& symbol_or_id,
bool broadcast = false )const;
/** Place a limit order attempting to sell one asset for another.
*
* Buying and selling are the same operation on BitShares. If you want to buy BTS
* with USD, you should sell USD for BTS.
*
* The blockchain will attempt to sell the \c symbol_or_id_to_sell for as
* much \c symbol_or_id_to_receive as possible, as long as the price is at
* least \c min_to_receive / \c amount_to_sell.
*
* In addition to the transaction fees, market fees will apply as specified
* by the issuer of both the selling asset and the receiving asset as
* a percentage of the amount exchanged.
*
* If either the selling asset or the receiving asset is whitelist
* restricted, the order will only be created if the seller is on
* the whitelist of the restricted asset type.
*
* Market orders are matched in the order they are included
* in the block chain.