BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface 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 {
77  public_key_type from;
78  public_key_type to;
79  public_key_type one_time_key;
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 
191  key_label_index_type labeled_keys;
192  blind_receipt_index_type blind_receipts;
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) )
map< string, vector< string > > pending_account_registrations
flat_set< worker_id_type > vote_for
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
fc::ecc::commitment_type commitment
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
std::tuple< public_key_type, asset_id_type, bool > to_asset_used() const
Identifies a weighted set of keys and accounts that must approve operations.
Definition: authority.hpp:34
stealth_confirmation::memo_data decrypted_memo
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
public_key_type to
the account this balance is logically associated with
tracks the history of all logical operations on blockchain stateAll operations and virtual operations...
vector< transaction_id_type > transaction_ids
This class represents an account on the object graphAccounts are the primary unit of authority on the...
Definition: api.cpp:48
const commitment_type & commitment() const
blind_receipt_index_type blind_receipts
fc::optional< fc::ecc::compact_signature > signature
key_label_index_type labeled_keys
std::pair< public_key_type, fc::time_point > from_date() const
map< string, string > pending_witness_registrations
vector< exported_account_keys > account_keys
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
vector< string > owner_approvals_to_remove
flat_set< worker_id_type > vote_abstain
vector< string > active_approvals_to_remove
fc::sha256 digest(const T &value)
Definition: digest.hpp:9
vector< object_id_type > my_account_ids() const
object_id_type id
Definition: object.hpp:69
bool update_account(const account_object &acct)
flat_set< worker_id_type > vote_against
vector< vector< char > > encrypted_private_keys
stealth_confirmation::memo_data data
zero_initialized_array< unsigned char, 33 > commitment_type
Definition: elliptic.hpp:22
account_multi_index_type my_accounts
adds a signature to a transaction
public_key_type from
the account this balance came from
public_key_type one_time_key
used to derive the authority key and blinding factor
typename impl::transform< List, Transformer >::type transform
Transform elements of a typelist.
Definition: typelist.hpp:170
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
#define FC_REFLECT_DERIVED(TYPE, INHERITS, MEMBERS)
Specializes fc::reflector for TYPE where type inherits other reflected classes.
Definition: reflect.hpp:305
map< account_id_type, set< public_key_type > > extra_keys
uint32_t transaction_handle_type
std::pair< public_key_type, fc::time_point > to_date() const
zero_initialized_array< unsigned char, 72 > signature
Definition: elliptic.hpp:26
map< public_key_type, string > keys