2015-06-19 19:48:00 +00:00
|
|
|
/*
|
2015-10-12 17:02:59 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors. All rights reserved.
|
2015-06-19 19:48:00 +00:00
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2015-10-12 17:02:59 +00:00
|
|
|
*
|
2015-06-19 19:48:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <graphene/chain/assert_evaluator.hpp>
|
2015-07-14 21:28:26 +00:00
|
|
|
#include <graphene/chain/block_summary_object.hpp>
|
2015-06-19 19:48:00 +00:00
|
|
|
#include <graphene/chain/database.hpp>
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
namespace graphene { namespace chain {
|
|
|
|
|
|
2015-06-23 18:32:18 +00:00
|
|
|
struct predicate_evaluator
|
2015-06-19 19:48:00 +00:00
|
|
|
{
|
2015-07-08 20:39:23 +00:00
|
|
|
typedef void result_type;
|
2015-06-23 13:08:34 +00:00
|
|
|
const database& db;
|
|
|
|
|
|
2015-06-23 18:32:18 +00:00
|
|
|
predicate_evaluator( const database& d ):db(d){}
|
2015-06-23 17:11:38 +00:00
|
|
|
|
2015-07-08 20:39:23 +00:00
|
|
|
void operator()( const account_name_eq_lit_predicate& p )const
|
2015-06-19 19:48:00 +00:00
|
|
|
{
|
2015-07-08 20:39:23 +00:00
|
|
|
FC_ASSERT( p.account_id(db).name == p.name );
|
|
|
|
|
}
|
|
|
|
|
void operator()( const asset_symbol_eq_lit_predicate& p )const
|
|
|
|
|
{
|
|
|
|
|
FC_ASSERT( p.asset_id(db).symbol == p.symbol );
|
2015-06-19 19:48:00 +00:00
|
|
|
}
|
2015-07-14 21:28:26 +00:00
|
|
|
void operator()( const block_id_predicate& p )const
|
|
|
|
|
{
|
2015-07-14 21:56:42 +00:00
|
|
|
FC_ASSERT( block_summary_id_type( block_header::num_from_id( p.id ) & 0xffff )(db).block_id == p.id );
|
2015-07-14 21:28:26 +00:00
|
|
|
}
|
2015-06-19 19:48:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void_result assert_evaluator::do_evaluate( const assert_operation& o )
|
2015-06-23 21:33:06 +00:00
|
|
|
{ try {
|
2015-06-19 19:48:00 +00:00
|
|
|
const database& _db = db();
|
|
|
|
|
uint32_t skip = _db.get_node_properties().skip_flags;
|
2015-06-23 17:11:38 +00:00
|
|
|
auto max_predicate_opcode = _db.get_global_properties().parameters.max_predicate_opcode;
|
2015-06-23 13:08:34 +00:00
|
|
|
|
2015-06-19 19:48:00 +00:00
|
|
|
if( skip & database::skip_assert_evaluation )
|
|
|
|
|
return void_result();
|
2015-06-23 13:08:34 +00:00
|
|
|
|
2015-07-08 20:39:23 +00:00
|
|
|
for( const auto& p : o.predicates )
|
2015-06-19 19:48:00 +00:00
|
|
|
{
|
2015-06-23 17:11:38 +00:00
|
|
|
FC_ASSERT( p.which() >= 0 );
|
|
|
|
|
FC_ASSERT( unsigned(p.which()) < max_predicate_opcode );
|
2015-07-08 20:39:23 +00:00
|
|
|
p.visit( predicate_evaluator( _db ) );
|
2015-06-19 19:48:00 +00:00
|
|
|
}
|
|
|
|
|
return void_result();
|
2015-06-23 21:33:06 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
2015-06-19 19:48:00 +00:00
|
|
|
|
|
|
|
|
void_result assert_evaluator::do_apply( const assert_operation& o )
|
2015-06-23 21:33:06 +00:00
|
|
|
{ try {
|
2015-06-19 19:48:00 +00:00
|
|
|
// assert_operation is always a no-op
|
|
|
|
|
return void_result();
|
2015-06-23 21:33:06 +00:00
|
|
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
2015-06-19 19:48:00 +00:00
|
|
|
|
|
|
|
|
} } // graphene::chain
|