BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
confidential_evaluator.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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  */
30 #include <graphene/chain/hardfork.hpp>
31 
32 namespace graphene { namespace chain {
33 
35 { try {
36  const auto& d = db();
37 
38  const auto& atype = o.amount.asset_id(db());
39  FC_ASSERT( atype.allow_confidential() );
40  FC_ASSERT( !atype.is_transfer_restricted() );
41  FC_ASSERT( !(atype.options.flags & white_list) );
42 
43  for( const auto& out : o.outputs )
44  {
45  for( const auto& a : out.owner.account_auths )
46  a.first(d); // verify all accounts exist and are valid
47  }
48  return void_result();
49 } FC_CAPTURE_AND_RETHROW( (o) ) }
50 
51 
53 { try {
54  db().adjust_balance( o.from, -o.amount );
55 
56  const auto& add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); // verify fee is a legit asset
57  db().modify( add, [&]( asset_dynamic_data_object& obj ){
59  FC_ASSERT( obj.confidential_supply >= 0 );
60  });
61  for( const auto& out : o.outputs )
62  {
64  obj.asset_id = o.amount.asset_id;
65  obj.owner = out.owner;
66  obj.commitment = out.commitment;
67  });
68  }
69  return void_result();
70 } FC_CAPTURE_AND_RETHROW( (o) ) }
71 
73 {
74  if( db().head_block_time() >= HARDFORK_563_TIME )
76  else
78 }
79 
81 { try {
82  const auto& d = db();
83  o.fee.asset_id(d); // verify fee is a legit asset
84  const auto& bbi = d.get_index_type<blinded_balance_index>();
85  const auto& cidx = bbi.indices().get<by_commitment>();
86  for( const auto& in : o.inputs )
87  {
88  auto itr = cidx.find( in.commitment );
89  FC_ASSERT( itr != cidx.end() );
90  FC_ASSERT( itr->asset_id == o.fee.asset_id );
91  FC_ASSERT( itr->owner == in.owner );
92  }
93  return void_result();
94 } FC_CAPTURE_AND_RETHROW( (o) ) }
95 
97 { try {
98  db().adjust_balance( o.fee_payer(), o.fee );
99  db().adjust_balance( o.to, o.amount );
100  const auto& bbi = db().get_index_type<blinded_balance_index>();
101  const auto& cidx = bbi.indices().get<by_commitment>();
102  for( const auto& in : o.inputs )
103  {
104  auto itr = cidx.find( in.commitment );
105  FC_ASSERT( itr != cidx.end() );
106  db().remove( *itr );
107  }
108  const auto& add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); // verify fee is a legit asset
109  db().modify( add, [&]( asset_dynamic_data_object& obj ){
111  FC_ASSERT( obj.confidential_supply >= 0 );
112  });
113  return void_result();
114 } FC_CAPTURE_AND_RETHROW( (o) ) }
115 
117 {
118  if( db().head_block_time() >= HARDFORK_563_TIME )
120  else
122 }
123 
125 { try {
126  const auto& d = db();
127  o.fee.asset_id(db()); // verify fee is a legit asset
128  const auto& bbi = db().get_index_type<blinded_balance_index>();
129  const auto& cidx = bbi.indices().get<by_commitment>();
130  for( const auto& out : o.outputs )
131  {
132  for( const auto& a : out.owner.account_auths )
133  a.first(d); // verify all accounts exist and are valid
134  }
135  for( const auto& in : o.inputs )
136  {
137  auto itr = cidx.find( in.commitment );
138  GRAPHENE_ASSERT( itr != cidx.end(), blind_transfer_unknown_commitment, "", ("commitment",in.commitment) );
139  FC_ASSERT( itr->asset_id == o.fee.asset_id );
140  FC_ASSERT( itr->owner == in.owner );
141  }
142  return void_result();
143 } FC_CAPTURE_AND_RETHROW( (o) ) }
144 
146 { try {
147  db().adjust_balance( o.fee_payer(), o.fee ); // deposit the fee to the temp account
148  const auto& bbi = db().get_index_type<blinded_balance_index>();
149  const auto& cidx = bbi.indices().get<by_commitment>();
150  for( const auto& in : o.inputs )
151  {
152  auto itr = cidx.find( in.commitment );
153  GRAPHENE_ASSERT( itr != cidx.end(), blind_transfer_unknown_commitment, "", ("commitment",in.commitment) );
154  db().remove( *itr );
155  }
156  for( const auto& out : o.outputs )
157  {
159  obj.asset_id = o.fee.asset_id;
160  obj.owner = out.owner;
161  obj.commitment = out.commitment;
162  });
163  }
164  const auto& add = o.fee.asset_id(db()).dynamic_asset_data_id(db());
165  db().modify( add, [&]( asset_dynamic_data_object& obj ){
166  obj.confidential_supply -= o.fee.amount;
167  FC_ASSERT( obj.confidential_supply >= 0 );
168  });
169 
170  return void_result();
171 } FC_CAPTURE_AND_RETHROW( (o) ) }
172 
174 {
175  if( db().head_block_time() >= HARDFORK_563_TIME )
177  else
179 }
180 
181 } } // graphene::chain
void modify(const T &obj, const Lambda &m)
void adjust_balance(account_id_type account, asset delta)
Adjust a particular account&#39;s balance in a given asset by a delta.
Definition: db_balance.cpp:54
const object * find(object_id_type id) const override
const index_type & indices() const
const IndexType & get_index_type() const
tracks a blinded balance commitment
Definition: api.cpp:48
void_result do_apply(const transfer_from_blind_operation &o)
void_result do_apply(const transfer_to_blind_operation &o)
void_result do_evaluate(const transfer_from_blind_operation &o)
void_result do_apply(const blind_transfer_operation &o)
Converts blinded/stealth balance to a public account balance.
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
void pay_fba_fee(uint64_t fba_id)
Definition: evaluator.cpp:105
tracks the asset information that changes frequentlyBecause the asset_object is very large it doesn&#39;t...
accounts must be whitelisted in order to hold or transact this asset
Definition: types.hpp:195
asset_id_type asset_id
Definition: asset.hpp:37
share_type confidential_supply
total asset held in confidential balances
void remove(const object &obj)
#define GRAPHENE_ASSERT(expr, exc_type, FORMAT,...)
Definition: exceptions.hpp:28
void_result do_evaluate(const transfer_to_blind_operation &o)
Transfers from blind to blind.
const T & create(F &&constructor)
Converts public account balance to a blinded or stealth balance.
void_result do_evaluate(const blind_transfer_operation &o)