BitShares-Core  4.0.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 typedef uint16_t transaction_handle_type;
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 
70  signed_transaction trx;
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.get_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  signed_block_with_info( const signed_block& block );
232  signed_block_with_info( const signed_block_with_info& block ) = default;
233 
236  vector< transaction_id_type > transaction_ids;
237 };
238 
240 {
243 
248 
253 };
254 
256  string account;
258  uint32_t block;
259  string time;
260 };
261 
263 public:
264  string message;
267 
268  fc::sha256 digest()const;
269 };
270 
271 namespace detail {
272 class wallet_api_impl;
273 }
274 
275 /***
276  * A utility class for performing various state-less actions that are related to wallets
277  */
278 class utility {
279  public:
292  static vector<brain_key_info> derive_owner_keys_from_brain_key( string brain_key,
293  int number_of_desired_keys = 1 );
294 
302  static brain_key_info suggest_brain_key();
303 };
304 
306  string memo;
307  string description;
309 };
310 
312  string memo;
313  string description;
316 };
317 
319  uint32_t total_count = 0;
320  uint32_t result_count = 0;
321  vector<operation_detail_ex> details;
322 };
323 
324 }} // namespace graphene::wallet
325 
327 FC_REFLECT( graphene::wallet::blind_balance, (amount)(from)(to)(one_time_key)(blinding_factor)(commitment)(used) )
328 FC_REFLECT( graphene::wallet::blind_confirmation::output,
329  (label)(pub_key)(decrypted_memo)(confirmation)(auth)(confirmation_receipt) )
330 FC_REFLECT( graphene::wallet::blind_confirmation, (trx)(outputs) )
331 
332 FC_REFLECT( graphene::wallet::plain_keys, (keys)(checksum) )
333 
335  (chain_id)
336  (my_accounts)
337  (cipher_keys)
338  (extra_keys)
339  (pending_account_registrations)(pending_witness_registrations)
340  (labeled_keys)
341  (blind_receipts)
342  (ws_server)
343  (ws_user)
344  (ws_password)
345  )
346 
348  (brain_priv_key)
349  (wif_priv_key)
350  (pub_key)
351  )
352 
353 FC_REFLECT( graphene::wallet::exported_account_keys, (account_name)(encrypted_private_keys)(public_keys) )
354 
355 FC_REFLECT( graphene::wallet::exported_keys, (password_checksum)(account_keys) )
356 
358  (date)(from_key)(from_label)(to_key)(to_label)(amount)(memo)(control_authority)(data)(used)(conf) )
359 
361  (active_approvals_to_add)
362  (active_approvals_to_remove)
363  (owner_approvals_to_add)
364  (owner_approvals_to_remove)
365  (key_approvals_to_add)
366  (key_approvals_to_remove)
367 )
368 
370  (vote_for)
371  (vote_against)
372  (vote_abstain)
373 )
374 
376  (block_id)(signing_key)(transaction_ids) )
377 
379  (allowed_withdraw)(allowed_withdraw_time) )
380 
382  (memo)(description)(op) )
383 
385  (memo)(description)(op)(transaction_id))
386 
388  (total_count)(result_count)(details))
389 
390 FC_REFLECT( graphene::wallet::signed_message_meta, (account)(memo_key)(block)(time) )
391 FC_REFLECT( graphene::wallet::signed_message, (message)(meta)(signature) )
std::pair< public_key_type, fc::time_point > from_date() const
map< string, vector< string > > pending_account_registrations
fc::sha256 chain_id_type
Definition: types.hpp:132
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
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:386
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:56
blind_receipt_index_type blind_receipts
fc::optional< fc::ecc::compact_signature > signature
vector< object_id_type > my_account_ids() const
key_label_index_type labeled_keys
std::tuple< public_key_type, asset_id_type, bool > to_asset_used() const
map< string, string > pending_witness_registrations
vector< exported_account_keys > account_keys
FC_REFLECT_DERIVED(graphene::app::extended_asset_object,(graphene::chain::asset_object),(total_in_collateral)(total_backing_collateral))
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
account_id_type get_id() const
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
account_multi_index_type my_accounts
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
uint16_t transaction_handle_type
std::pair< public_key_type, fc::time_point > to_date() const
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
const commitment_type & commitment() const
map< account_id_type, set< public_key_type > > extra_keys
map< public_key_type, string > keys