BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
wallet_structs.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <vector>
28 
29 using namespace graphene::app;
30 using namespace graphene::chain;
31 using namespace graphene::utilities;
32 using std::string;
33 using std::vector;
34 
35 namespace graphene { namespace wallet {
36 
37 using transaction_handle_type = uint32_t;
38 
39 struct plain_keys
40 {
41  map<public_key_type, string> keys;
43 };
44 
46 {
48  string wif_priv_key;
50 };
51 
52 
59 {
60  struct output
61  {
62  string label;
63  public_key_type pub_key;
64  stealth_confirmation::memo_data decrypted_memo;
65  stealth_confirmation confirmation;
66  authority auth;
68  };
69 
71  vector<output> outputs;
72 };
73 
75 {
76  asset amount;
82  bool used = false;
83 };
84 
86 {
87  std::pair<public_key_type,fc::time_point> from_date()const { return std::make_pair(from_key,date); }
88  std::pair<public_key_type,fc::time_point> to_date()const { return std::make_pair(to_key,date); }
89  std::tuple<public_key_type,asset_id_type,bool> to_asset_used()const
90  { return std::make_tuple(to_key,amount.asset_id,used); }
91 
92  const commitment_type& commitment()const { return data.commitment; }
93 
95  public_key_type from_key;
96  string from_label;
97  public_key_type to_key;
98  string to_label;
100  string memo;
102  stealth_confirmation::memo_data data;
103  bool used = false;
105 };
106 
107 struct by_from;
108 struct by_to;
109 struct by_to_asset_used;
110 struct by_commitment;
111 
112 typedef multi_index_container< blind_receipt,
113  indexed_by<
114  ordered_unique< tag<by_commitment>,
115  const_mem_fun< blind_receipt, const commitment_type&, &blind_receipt::commitment > >,
116  ordered_unique< tag<by_to>,
117  const_mem_fun< blind_receipt,
118  std::pair<public_key_type,fc::time_point>,
119  &blind_receipt::to_date > >,
120  ordered_non_unique< tag<by_to_asset_used>,
121  const_mem_fun< blind_receipt,
122  std::tuple<public_key_type,asset_id_type,bool>,
123  &blind_receipt::to_asset_used > >,
124  ordered_unique< tag<by_from>,
125  const_mem_fun< blind_receipt,
126  std::pair<public_key_type,fc::time_point>,
127  &blind_receipt::from_date > >
128  >
130 
131 
132 struct key_label
133 {
134  string label;
136 };
137 
138 
139 struct by_label;
140 struct by_key;
141 typedef multi_index_container<
142  key_label,
143  indexed_by<
144  ordered_unique< tag<by_label>, member< key_label, string, &key_label::label > >,
145  ordered_unique< tag<by_key>, member< key_label, public_key_type, &key_label::key > >
146  >
148 
149 
151 {
156  vector<object_id_type> my_account_ids()const
157  {
158  vector<object_id_type> ids;
159  ids.reserve(my_accounts.size());
160  std::transform(my_accounts.begin(), my_accounts.end(), std::back_inserter(ids),
161  [](const account_object& ao) { return ao.id; });
162  return ids;
163  }
166  bool update_account(const account_object& acct)
167  {
168  auto& idx = my_accounts.get<by_id>();
169  auto itr = idx.find(acct.id);
170  if( itr != idx.end() )
171  {
172  idx.replace(itr, acct);
173  return false;
174  } else {
175  idx.insert(acct);
176  return true;
177  }
178  }
179 
181  vector<char> cipher_keys;
182 
184  map<account_id_type, set<public_key_type> > extra_keys;
185 
186  // map of account_name -> base58_private_key for
187  // incomplete account regs
188  map<string, vector<string> > pending_account_registrations;
189  map<string, string> pending_witness_registrations;
190 
193 
194  string ws_server = "ws://localhost:8090";
195  string ws_user;
196  string ws_password;
197 };
198 
200 {
201  string account_name;
202  vector<vector<char>> encrypted_private_keys;
203  vector<public_key_type> public_keys;
204 };
205 
207 {
209  vector<exported_account_keys> account_keys;
210 };
211 
213 {
214  vector<string> active_approvals_to_add;
216  vector<string> owner_approvals_to_add;
218  vector<string> key_approvals_to_add;
219  vector<string> key_approvals_to_remove;
220 };
221 
223 {
224  flat_set<worker_id_type> vote_for;
225  flat_set<worker_id_type> vote_against;
226  flat_set<worker_id_type> vote_abstain;
227 };
228 
229 struct signed_block_with_info : public signed_block
230 {
231  explicit signed_block_with_info( const signed_block& block );
232 
234  public_key_type signing_key;
235  vector< transaction_id_type > transaction_ids;
236 };
237 
239 {
241 
246 
251 };
252 
254  string account;
256  uint32_t block;
257  string time;
258 };
259 
261 public:
262  string message;
265 
266  fc::sha256 digest()const;
267 };
268 
269 namespace detail {
270 class wallet_api_impl;
271 }
272 
273 /***
274  * A utility class for performing various state-less actions that are related to wallets
275  */
276 class utility {
277  public:
290  static vector<brain_key_info> derive_owner_keys_from_brain_key( const string& brain_key,
291  uint32_t number_of_desired_keys = 1 );
292 
300  static brain_key_info suggest_brain_key();
301 };
302 
304  string memo;
305  string description;
307 };
308 
310  string memo;
311  string description;
314 };
315 
317  uint32_t total_count = 0;
318  uint32_t result_count = 0;
319  vector<operation_detail_ex> details;
320 };
321 
322 }} // namespace graphene::wallet
323 
325 FC_REFLECT( graphene::wallet::blind_balance, (amount)(from)(to)(one_time_key)(blinding_factor)(commitment)(used) )
327  (label)(pub_key)(decrypted_memo)(confirmation)(auth)(confirmation_receipt) )
329 
330 FC_REFLECT( graphene::wallet::plain_keys, (keys)(checksum) )
331 
333  (chain_id)
334  (my_accounts)
335  (cipher_keys)
336  (extra_keys)
337  (pending_account_registrations)(pending_witness_registrations)
338  (labeled_keys)
339  (blind_receipts)
340  (ws_server)
341  (ws_user)
342  (ws_password)
343  )
344 
346  (brain_priv_key)
347  (wif_priv_key)
348  (pub_key)
349  )
350 
351 FC_REFLECT( graphene::wallet::exported_account_keys, (account_name)(encrypted_private_keys)(public_keys) )
352 
353 FC_REFLECT( graphene::wallet::exported_keys, (password_checksum)(account_keys) )
354 
356  (date)(from_key)(from_label)(to_key)(to_label)(amount)(memo)(control_authority)(data)(used)(conf) )
357 
359  (active_approvals_to_add)
360  (active_approvals_to_remove)
361  (owner_approvals_to_add)
362  (owner_approvals_to_remove)
363  (key_approvals_to_add)
364  (key_approvals_to_remove)
365 )
366 
368  (vote_for)
369  (vote_against)
370  (vote_abstain)
371 )
372 
374  (block_id)(signing_key)(transaction_ids) )
375 
377  (allowed_withdraw)(allowed_withdraw_time) )
378 
380  (memo)(description)(op) )
381 
383  (memo)(description)(op)(transaction_id))
384 
386  (total_count)(result_count)(details))
387 
388 FC_REFLECT( graphene::wallet::signed_message_meta, (account)(memo_key)(block)(time) )
graphene::wallet::signed_message_meta::time
string time
Definition: wallet_structs.hpp:257
graphene::wallet::signed_block_with_info::block_id
block_id_type block_id
Definition: wallet_structs.hpp:233
graphene::wallet::account_history_operation_detail
Definition: wallet_structs.hpp:316
graphene::wallet::blind_confirmation::output::pub_key
public_key_type pub_key
Definition: wallet_structs.hpp:63
graphene::db::object::id
object_id_type id
Definition: object.hpp:69
graphene::wallet::vesting_balance_object_with_info::allowed_withdraw
asset allowed_withdraw
Definition: wallet_structs.hpp:245
graphene::wallet::operation_detail::op
operation_history_object op
Definition: wallet_structs.hpp:306
graphene::wallet::operation_detail::description
string description
Definition: wallet_structs.hpp:305
fc::digest
fc::sha256 digest(const T &value)
Definition: digest.hpp:9
graphene::wallet::exported_account_keys::encrypted_private_keys
vector< vector< char > > encrypted_private_keys
Definition: wallet_structs.hpp:202
graphene::utilities
Definition: elasticsearch.cpp:37
graphene::wallet::blind_receipt::amount
asset amount
Definition: wallet_structs.hpp:99
graphene::wallet::blind_receipt::from_label
string from_label
Definition: wallet_structs.hpp:96
fc::ecc::signature
zero_initialized_array< unsigned char, 72 > signature
Definition: elliptic.hpp:26
graphene::wallet::account_history_operation_detail::details
vector< operation_detail_ex > details
Definition: wallet_structs.hpp:319
graphene::wallet::signed_message_meta
Definition: wallet_structs.hpp:253
graphene::wallet::key_label::key
public_key_type key
Definition: wallet_structs.hpp:135
graphene::wallet::blind_receipt_index_type
multi_index_container< blind_receipt, indexed_by< ordered_unique< tag< by_commitment >, const_mem_fun< blind_receipt, const commitment_type &, &blind_receipt::commitment > >, ordered_unique< tag< by_to >, const_mem_fun< blind_receipt, std::pair< public_key_type, fc::time_point >, &blind_receipt::to_date > >, ordered_non_unique< tag< by_to_asset_used >, const_mem_fun< blind_receipt, std::tuple< public_key_type, asset_id_type, bool >, &blind_receipt::to_asset_used > >, ordered_unique< tag< by_from >, const_mem_fun< blind_receipt, std::pair< public_key_type, fc::time_point >, &blind_receipt::from_date > > >> blind_receipt_index_type
Definition: wallet_structs.hpp:110
graphene::net::message
Definition: message.hpp:58
graphene::wallet::wallet_data::ws_user
string ws_user
Definition: wallet_structs.hpp:195
graphene::wallet::approval_delta::active_approvals_to_add
vector< string > active_approvals_to_add
Definition: wallet_structs.hpp:214
fc::sha256
Definition: sha256.hpp:10
graphene::wallet::exported_account_keys::account_name
string account_name
Definition: wallet_structs.hpp:201
graphene::wallet::operation_detail_ex::transaction_id
transaction_id_type transaction_id
Definition: wallet_structs.hpp:313
fc::zero_initialized_array< unsigned char, 33 >
graphene::wallet::wallet_data::blind_receipts
blind_receipt_index_type blind_receipts
Definition: wallet_structs.hpp:192
graphene::wallet::blind_receipt::control_authority
authority control_authority
Definition: wallet_structs.hpp:101
graphene::wallet::wallet_data::chain_id
chain_id_type chain_id
Definition: wallet_structs.hpp:153
graphene::wallet::operation_detail_ex::op
operation_history_object op
Definition: wallet_structs.hpp:312
graphene::wallet::plain_keys::checksum
fc::sha512 checksum
Definition: wallet_structs.hpp:42
graphene::wallet::blind_receipt::data
stealth_confirmation::memo_data data
Definition: wallet_structs.hpp:102
graphene::wallet::operation_detail_ex::description
string description
Definition: wallet_structs.hpp:311
graphene::protocol::public_key_type
Definition: types.hpp:312
graphene::wallet::signed_block_with_info
Definition: wallet_structs.hpp:229
graphene::wallet::wallet_data::labeled_keys
key_label_index_type labeled_keys
Definition: wallet_structs.hpp:191
graphene::wallet::brain_key_info::brain_priv_key
string brain_priv_key
Definition: wallet_structs.hpp:47
graphene::wallet::signed_block_with_info::signing_key
public_key_type signing_key
Definition: wallet_structs.hpp:234
graphene::wallet::approval_delta::key_approvals_to_add
vector< string > key_approvals_to_add
Definition: wallet_structs.hpp:218
graphene::wallet::blind_confirmation::output
Definition: wallet_structs.hpp:60
graphene::wallet::blind_balance
Definition: wallet_structs.hpp:74
graphene::wallet::wallet_data::ws_password
string ws_password
Definition: wallet_structs.hpp:196
graphene::wallet::wallet_data::pending_witness_registrations
map< string, string > pending_witness_registrations
Definition: wallet_structs.hpp:189
graphene::wallet::blind_balance::commitment
fc::ecc::commitment_type commitment
Definition: wallet_structs.hpp:81
graphene::wallet::exported_keys
Definition: wallet_structs.hpp:206
graphene::chain::vesting_balance_object
Definition: vesting_balance_object.hpp:151
graphene::protocol::signed_transaction
adds a signature to a transaction
Definition: transaction.hpp:134
fc::sha512
Definition: sha512.hpp:9
graphene::wallet::blind_balance::blinding_factor
fc::sha256 blinding_factor
Definition: wallet_structs.hpp:80
graphene::wallet::blind_receipt::to_date
std::pair< public_key_type, fc::time_point > to_date() const
Definition: wallet_structs.hpp:88
graphene::wallet::approval_delta
Definition: wallet_structs.hpp:212
graphene::wallet::blind_balance::one_time_key
public_key_type one_time_key
used to derive the authority key and blinding factor
Definition: wallet_structs.hpp:79
graphene::wallet::signed_message_meta::block
uint32_t block
Definition: wallet_structs.hpp:256
graphene::wallet::utility
Definition: wallet_structs.hpp:276
graphene::wallet::blind_balance::amount
asset amount
Definition: wallet_structs.hpp:76
graphene::wallet::blind_balance::to
public_key_type to
the account this balance is logically associated with
Definition: wallet_structs.hpp:78
graphene::wallet::blind_receipt::conf
stealth_confirmation conf
Definition: wallet_structs.hpp:104
graphene::wallet::plain_keys
Definition: wallet_structs.hpp:39
FC_REFLECT_DERIVED
#define FC_REFLECT_DERIVED(TYPE, INHERITS, MEMBERS)
Specializes fc::reflector for TYPE where type inherits other reflected classes.
Definition: reflect.hpp:305
graphene::wallet::signed_message::signature
fc::optional< fc::ecc::compact_signature > signature
Definition: wallet_structs.hpp:264
graphene::wallet::exported_keys::account_keys
vector< exported_account_keys > account_keys
Definition: wallet_structs.hpp:209
graphene::chain::account_object
This class represents an account on the object graph.
Definition: account_object.hpp:180
graphene::wallet::blind_receipt::from_key
public_key_type from_key
Definition: wallet_structs.hpp:95
graphene::wallet::signed_message::meta
signed_message_meta meta
Definition: wallet_structs.hpp:263
graphene::wallet::signed_block_with_info::transaction_ids
vector< transaction_id_type > transaction_ids
Definition: wallet_structs.hpp:235
fc::time_point_sec
Definition: time.hpp:74
fc::ecc::commitment_type
zero_initialized_array< unsigned char, 33 > commitment_type
Definition: elliptic.hpp:22
graphene::wallet::wallet_data::my_account_ids
vector< object_id_type > my_account_ids() const
Definition: wallet_structs.hpp:156
graphene::wallet::wallet_data::update_account
bool update_account(const account_object &acct)
Definition: wallet_structs.hpp:166
fc::ripemd160
Definition: ripemd160.hpp:11
graphene::wallet::blind_receipt::date
fc::time_point date
Definition: wallet_structs.hpp:94
graphene::wallet::exported_keys::password_checksum
fc::sha512 password_checksum
Definition: wallet_structs.hpp:208
graphene::wallet::operation_detail
Definition: wallet_structs.hpp:303
graphene::wallet::key_label
Definition: wallet_structs.hpp:132
graphene::wallet::blind_receipt::to_asset_used
std::tuple< public_key_type, asset_id_type, bool > to_asset_used() const
Definition: wallet_structs.hpp:89
graphene::app
Definition: api.cpp:48
graphene::wallet::wallet_data::my_accounts
account_multi_index_type my_accounts
Definition: wallet_structs.hpp:154
graphene::wallet::approval_delta::key_approvals_to_remove
vector< string > key_approvals_to_remove
Definition: wallet_structs.hpp:219
graphene::wallet::vesting_balance_object_with_info::allowed_withdraw_time
fc::time_point_sec allowed_withdraw_time
Definition: wallet_structs.hpp:250
graphene::wallet::key_label_index_type
multi_index_container< key_label, indexed_by< ordered_unique< tag< by_label >, member< key_label, string, &key_label::label > >, ordered_unique< tag< by_key >, member< key_label, public_key_type, &key_label::key > > >> key_label_index_type
Definition: wallet_structs.hpp:140
graphene::wallet::transaction_handle_type
uint32_t transaction_handle_type
Definition: wallet_structs.hpp:37
graphene::wallet::blind_receipt::memo
string memo
Definition: wallet_structs.hpp:100
graphene::wallet::brain_key_info::wif_priv_key
string wif_priv_key
Definition: wallet_structs.hpp:48
graphene::wallet::operation_detail_ex::memo
string memo
Definition: wallet_structs.hpp:310
graphene::wallet::blind_receipt::from_date
std::pair< public_key_type, fc::time_point > from_date() const
Definition: wallet_structs.hpp:87
graphene::wallet::approval_delta::owner_approvals_to_add
vector< string > owner_approvals_to_add
Definition: wallet_structs.hpp:216
graphene::wallet::blind_confirmation::output::confirmation_receipt
string confirmation_receipt
Definition: wallet_structs.hpp:67
fc::typelist::transform
typename impl::transform< List, Transformer >::type transform
Transform elements of a typelist.
Definition: typelist.hpp:170
graphene::wallet::blind_confirmation::output::confirmation
stealth_confirmation confirmation
Definition: wallet_structs.hpp:65
graphene::wallet::signed_message_meta::memo_key
public_key_type memo_key
Definition: wallet_structs.hpp:255
graphene::wallet::brain_key_info
Definition: wallet_structs.hpp:45
graphene::wallet::blind_confirmation::output::label
string label
Definition: wallet_structs.hpp:62
graphene::wallet::operation_detail::memo
string memo
Definition: wallet_structs.hpp:304
fc::time_point
Definition: time.hpp:44
graphene::wallet::blind_receipt
Definition: wallet_structs.hpp:85
graphene::chain::account_multi_index_type
multi_index_container< account_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_name >, member< account_object, string, &account_object::name > > > > account_multi_index_type
Definition: account_object.hpp:415
graphene::wallet::blind_receipt::to_key
public_key_type to_key
Definition: wallet_structs.hpp:97
graphene::wallet::blind_receipt::commitment
const commitment_type & commitment() const
Definition: wallet_structs.hpp:92
graphene::wallet::wallet_data::cipher_keys
vector< char > cipher_keys
Definition: wallet_structs.hpp:181
graphene::wallet::brain_key_info::pub_key
public_key_type pub_key
Definition: wallet_structs.hpp:49
graphene::wallet::plain_keys::keys
map< public_key_type, string > keys
Definition: wallet_structs.hpp:41
graphene::wallet::approval_delta::owner_approvals_to_remove
vector< string > owner_approvals_to_remove
Definition: wallet_structs.hpp:217
graphene::wallet::wallet_data
Definition: wallet_structs.hpp:150
FC_REFLECT
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
graphene::wallet::worker_vote_delta::vote_for
flat_set< worker_id_type > vote_for
Definition: wallet_structs.hpp:224
graphene::wallet::signed_message_meta::account
string account
Definition: wallet_structs.hpp:254
graphene::protocol::authority
Identifies a weighted set of keys and accounts that must approve operations.
Definition: authority.hpp:34
graphene::wallet::worker_vote_delta::vote_against
flat_set< worker_id_type > vote_against
Definition: wallet_structs.hpp:225
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::protocol::asset
Definition: asset.hpp:31
graphene::protocol::signed_block
Definition: block.hpp:64
graphene::wallet::signed_message
Definition: wallet_structs.hpp:260
graphene::wallet::blind_balance::from
public_key_type from
the account this balance came from
Definition: wallet_structs.hpp:77
graphene::wallet::vesting_balance_object_with_info
Definition: wallet_structs.hpp:238
graphene::wallet::blind_receipt::to_label
string to_label
Definition: wallet_structs.hpp:98
graphene::wallet::approval_delta::active_approvals_to_remove
vector< string > active_approvals_to_remove
Definition: wallet_structs.hpp:215
graphene::wallet::worker_vote_delta
Definition: wallet_structs.hpp:222
graphene::wallet::operation_detail_ex
Definition: wallet_structs.hpp:309
graphene::wallet::signed_message::message
string message
Definition: wallet_structs.hpp:262
graphene::wallet::blind_confirmation::output::decrypted_memo
stealth_confirmation::memo_data decrypted_memo
Definition: wallet_structs.hpp:64
graphene::chain
Definition: util.hpp:32
graphene::wallet::wallet_data::extra_keys
map< account_id_type, set< public_key_type > > extra_keys
Definition: wallet_structs.hpp:184
graphene::wallet::key_label::label
string label
Definition: wallet_structs.hpp:134
graphene::wallet::wallet_data::pending_account_registrations
map< string, vector< string > > pending_account_registrations
Definition: wallet_structs.hpp:188
graphene::wallet::blind_confirmation::output::auth
authority auth
Definition: wallet_structs.hpp:66
graphene
Definition: api.cpp:48
graphene::wallet::exported_account_keys
Definition: wallet_structs.hpp:199
graphene::wallet::blind_confirmation
Definition: wallet_structs.hpp:58
graphene::wallet::blind_confirmation::trx
signed_transaction trx
Definition: wallet_structs.hpp:70
graphene::chain::operation_history_object
tracks the history of all logical operations on blockchain state
Definition: operation_history_object.hpp:48
graphene::wallet::blind_confirmation::outputs
vector< output > outputs
Definition: wallet_structs.hpp:71
graphene::wallet::exported_account_keys::public_keys
vector< public_key_type > public_keys
Definition: wallet_structs.hpp:203
graphene::protocol::stealth_confirmation
Definition: confidential.hpp:102
graphene::wallet::worker_vote_delta::vote_abstain
flat_set< worker_id_type > vote_abstain
Definition: wallet_structs.hpp:226