2015-07-08 20:39:23 +00:00
|
|
|
/*
|
2015-10-12 17:48:40 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Any modified source or binaries are used only with the BitShares network.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
2015-07-08 20:39:23 +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-07-08 20:39:23 +00:00
|
|
|
*/
|
|
|
|
|
#include <graphene/chain/protocol/operations.hpp>
|
|
|
|
|
|
|
|
|
|
namespace graphene { namespace chain {
|
|
|
|
|
|
|
|
|
|
uint64_t base_operation::calculate_data_fee( uint64_t bytes, uint64_t price_per_kbyte )
|
|
|
|
|
{
|
|
|
|
|
auto result = (fc::uint128(bytes) * price_per_kbyte) / 1024;
|
|
|
|
|
FC_ASSERT( result <= GRAPHENE_MAX_SHARE_SUPPLY );
|
|
|
|
|
return result.to_uint64();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 16:19:20 +00:00
|
|
|
void balance_claim_operation::validate()const
|
2015-07-08 20:39:23 +00:00
|
|
|
{
|
|
|
|
|
FC_ASSERT( fee == asset() );
|
|
|
|
|
FC_ASSERT( balance_owner_key != public_key_type() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct required_auth_visitor
|
|
|
|
|
{
|
|
|
|
|
typedef void result_type;
|
|
|
|
|
|
|
|
|
|
vector<authority>& result;
|
|
|
|
|
|
|
|
|
|
required_auth_visitor( vector<authority>& r ):result(r){}
|
|
|
|
|
|
|
|
|
|
/** for most operations this is a no-op */
|
|
|
|
|
template<typename T>
|
|
|
|
|
void operator()(const T& )const {}
|
|
|
|
|
|
|
|
|
|
void operator()( const balance_claim_operation& o )const
|
|
|
|
|
{
|
|
|
|
|
result.push_back( authority( 1, o.balance_owner_key, 1 ) );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void operation_get_required_authorities( const operation& op, vector<authority>& result )
|
|
|
|
|
{
|
|
|
|
|
op.visit( required_auth_visitor( result ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Used to validate operations in a polymorphic manner
|
|
|
|
|
*/
|
|
|
|
|
struct operation_validator
|
|
|
|
|
{
|
|
|
|
|
typedef void result_type;
|
|
|
|
|
template<typename T>
|
|
|
|
|
void operator()( const T& v )const { v.validate(); }
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-08 22:45:53 +00:00
|
|
|
struct operation_get_required_auth
|
|
|
|
|
{
|
|
|
|
|
typedef void result_type;
|
|
|
|
|
|
|
|
|
|
flat_set<account_id_type>& active;
|
|
|
|
|
flat_set<account_id_type>& owner;
|
|
|
|
|
vector<authority>& other;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
operation_get_required_auth( flat_set<account_id_type>& a,
|
|
|
|
|
flat_set<account_id_type>& own,
|
|
|
|
|
vector<authority>& oth ):active(a),owner(own),other(oth){}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
void operator()( const T& v )const
|
|
|
|
|
{
|
|
|
|
|
active.insert( v.fee_payer() );
|
|
|
|
|
v.get_required_active_authorities( active );
|
|
|
|
|
v.get_required_owner_authorities( owner );
|
|
|
|
|
v.get_required_authorities( other );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-08 20:39:23 +00:00
|
|
|
void operation_validate( const operation& op )
|
|
|
|
|
{
|
|
|
|
|
op.visit( operation_validator() );
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 22:45:53 +00:00
|
|
|
void operation_get_required_authorities( const operation& op,
|
|
|
|
|
flat_set<account_id_type>& active,
|
|
|
|
|
flat_set<account_id_type>& owner,
|
|
|
|
|
vector<authority>& other )
|
|
|
|
|
{
|
2015-07-09 15:40:37 +00:00
|
|
|
op.visit( operation_get_required_auth( active, owner, other ) );
|
2015-07-08 22:45:53 +00:00
|
|
|
}
|
2015-07-08 20:39:23 +00:00
|
|
|
|
|
|
|
|
} } // namespace graphene::chain
|