BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
assert_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  */
24 
28 
29 #include <sstream>
30 
31 namespace graphene { namespace chain {
32 
34 {
35  typedef void result_type;
36  const database& db;
37 
38  predicate_evaluator( const database& d ):db(d){}
39 
41  {
42  FC_ASSERT( p.account_id(db).name == p.name );
43  }
45  {
46  FC_ASSERT( p.asset_id(db).symbol == p.symbol );
47  }
48  void operator()( const block_id_predicate& p )const
49  {
50  FC_ASSERT( block_summary_id_type( block_header::num_from_id( p.id ) & 0xffff )(db).block_id == p.id );
51  }
52 };
53 
55 { try {
56  const database& _db = db();
57  uint32_t skip = _db.get_node_properties().skip_flags;
58  auto max_predicate_opcode = _db.get_global_properties().parameters.max_predicate_opcode;
59 
61  return void_result();
62 
63  for( const auto& p : o.predicates )
64  {
65  FC_ASSERT( p.which() >= 0 );
66  FC_ASSERT( unsigned(p.which()) < max_predicate_opcode );
67  p.visit( predicate_evaluator( _db ) );
68  }
69  return void_result();
70 } FC_CAPTURE_AND_RETHROW( (o) ) }
71 
73 { try {
74  // assert_operation is always a no-op
75  return void_result();
76 } FC_CAPTURE_AND_RETHROW( (o) ) }
77 
78 } } // graphene::chain
static uint32_t num_from_id(const block_id_type &id)
Definition: block.cpp:36
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:48
void operator()(const block_id_predicate &p) const
void_result do_apply(const assert_operation &o)
void operator()(const account_name_eq_lit_predicate &p) const
assert that some conditions are true.This operation performs no changes to the database state...
Definition: assert.hpp:93
#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_result do_evaluate(const assert_operation &o)
const node_property_object & get_node_properties() const
Definition: db_getter.cpp:92
void operator()(const asset_symbol_eq_lit_predicate &p) const
uint16_t max_predicate_opcode
predicate_opcode must be less than this number
vector< predicate > predicates
Definition: assert.hpp:99
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:47