BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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
graphene::chain::predicate_evaluator::operator()
void operator()(const account_name_eq_lit_predicate &p) const
Definition: assert_evaluator.cpp:40
graphene::protocol::block_id_predicate::id
block_id_type id
Definition: assert.hpp:71
FC_CAPTURE_AND_RETHROW
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
graphene::chain::database
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
graphene::protocol::assert_operation::predicates
vector< predicate > predicates
Definition: assert.hpp:99
graphene::protocol::account_name_eq_lit_predicate::name
string name
Definition: assert.hpp:37
graphene::chain::predicate_evaluator
Definition: assert_evaluator.cpp:33
database.hpp
graphene::chain::assert_evaluator::do_apply
void_result do_apply(const assert_operation &o)
Definition: assert_evaluator.cpp:72
graphene::chain::global_property_object::parameters
chain_parameters parameters
Definition: global_property_object.hpp:44
graphene::protocol::asset_symbol_eq_lit_predicate::symbol
string symbol
Definition: assert.hpp:52
graphene::protocol::account_name_eq_lit_predicate::account_id
account_id_type account_id
Definition: assert.hpp:36
graphene::chain::predicate_evaluator::operator()
void operator()(const asset_symbol_eq_lit_predicate &p) const
Definition: assert_evaluator.cpp:44
graphene::protocol::assert_operation
assert that some conditions are true.
Definition: assert.hpp:93
graphene::chain::assert_evaluator::do_evaluate
void_result do_evaluate(const assert_operation &o)
Definition: assert_evaluator.cpp:54
graphene::chain::database::get_node_properties
const node_property_object & get_node_properties() const
Definition: db_getter.cpp:92
graphene::protocol::account_name_eq_lit_predicate
Definition: assert.hpp:34
graphene::protocol::asset_symbol_eq_lit_predicate::asset_id
asset_id_type asset_id
Definition: assert.hpp:51
graphene::chain::generic_evaluator::db
database & db() const
Definition: evaluator.cpp:39
graphene::chain::predicate_evaluator::predicate_evaluator
predicate_evaluator(const database &d)
Definition: assert_evaluator.cpp:38
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
graphene::protocol::block_header::num_from_id
static uint32_t num_from_id(const block_id_type &id)
Definition: block.cpp:36
block_summary_object.hpp
graphene::chain::predicate_evaluator::result_type
void result_type
Definition: assert_evaluator.cpp:35
graphene::protocol::chain_parameters::max_predicate_opcode
uint16_t max_predicate_opcode
predicate_opcode must be less than this number
Definition: chain_parameters.hpp:76
graphene::chain::predicate_evaluator::db
const database & db
Definition: assert_evaluator.cpp:36
graphene::chain::database::get_global_properties
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:47
graphene::chain::node_property_object::skip_flags
uint32_t skip_flags
Definition: node_property_object.hpp:45
graphene::chain::database::skip_assert_evaluation
@ skip_assert_evaluation
used while reindexing
Definition: database.hpp:87
graphene::protocol::void_result
Definition: base.hpp:86
graphene::protocol::block_id_predicate
Definition: assert.hpp:69
graphene::chain::predicate_evaluator::operator()
void operator()(const block_id_predicate &p) const
Definition: assert_evaluator.cpp:48
graphene::protocol::asset_symbol_eq_lit_predicate
Definition: assert.hpp:49
assert_evaluator.hpp
graphene
Definition: api.cpp:48