2015-10-12 17:02:59 +00:00
|
|
|
/*
|
2015-10-12 17:48:40 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The MIT License
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
2015-10-12 17:02:59 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
2015-10-12 17:02:59 +00:00
|
|
|
*/
|
2019-04-14 04:38:56 +00:00
|
|
|
#include <graphene/protocol/operations.hpp>
|
|
|
|
|
#include <graphene/protocol/fee_schedule.hpp>
|
2015-07-08 20:39:23 +00:00
|
|
|
|
2019-05-11 10:39:15 +00:00
|
|
|
#include <fc/io/raw.hpp>
|
|
|
|
|
|
2019-04-14 04:38:56 +00:00
|
|
|
namespace graphene { namespace protocol {
|
2015-07-08 20:39:23 +00:00
|
|
|
|
2015-07-13 19:19:36 +00:00
|
|
|
proposal_create_operation proposal_create_operation::committee_proposal(const chain_parameters& global_params, fc::time_point_sec head_block_time )
|
2015-07-08 20:39:23 +00:00
|
|
|
{
|
2015-09-28 23:35:07 +00:00
|
|
|
// TODO move this method to unit tests as it is not useful
|
2015-07-08 20:39:23 +00:00
|
|
|
proposal_create_operation op;
|
|
|
|
|
op.expiration_time = head_block_time + global_params.maximum_proposal_lifetime;
|
2015-07-09 12:43:45 +00:00
|
|
|
op.review_period_seconds = global_params.committee_proposal_review_period;
|
2015-07-08 20:39:23 +00:00
|
|
|
return op;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void proposal_create_operation::validate() const
|
|
|
|
|
{
|
|
|
|
|
FC_ASSERT( !proposed_ops.empty() );
|
|
|
|
|
for( const auto& op : proposed_ops ) operation_validate( op.op );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
share_type proposal_create_operation::calculate_fee(const fee_parameters_type& k) const
|
|
|
|
|
{
|
|
|
|
|
return k.fee + calculate_data_fee( fc::raw::pack_size(*this), k.price_per_kbyte );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void proposal_update_operation::validate() const
|
|
|
|
|
{
|
|
|
|
|
FC_ASSERT(fee.amount >= 0);
|
|
|
|
|
FC_ASSERT(!(active_approvals_to_add.empty() && active_approvals_to_remove.empty() &&
|
|
|
|
|
owner_approvals_to_add.empty() && owner_approvals_to_remove.empty() &&
|
|
|
|
|
key_approvals_to_add.empty() && key_approvals_to_remove.empty()));
|
|
|
|
|
for( auto a : active_approvals_to_add )
|
|
|
|
|
{
|
|
|
|
|
FC_ASSERT(active_approvals_to_remove.find(a) == active_approvals_to_remove.end(),
|
|
|
|
|
"Cannot add and remove approval at the same time.");
|
|
|
|
|
}
|
|
|
|
|
for( auto a : owner_approvals_to_add )
|
|
|
|
|
{
|
|
|
|
|
FC_ASSERT(owner_approvals_to_remove.find(a) == owner_approvals_to_remove.end(),
|
|
|
|
|
"Cannot add and remove approval at the same time.");
|
|
|
|
|
}
|
|
|
|
|
for( auto a : key_approvals_to_add )
|
|
|
|
|
{
|
|
|
|
|
FC_ASSERT(key_approvals_to_remove.find(a) == key_approvals_to_remove.end(),
|
|
|
|
|
"Cannot add and remove approval at the same time.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void proposal_delete_operation::validate() const
|
|
|
|
|
{
|
|
|
|
|
FC_ASSERT( fee.amount >= 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
share_type proposal_update_operation::calculate_fee(const fee_parameters_type& k) const
|
|
|
|
|
{
|
|
|
|
|
return k.fee + calculate_data_fee( fc::raw::pack_size(*this), k.price_per_kbyte );
|
|
|
|
|
}
|
2015-07-09 19:14:44 +00:00
|
|
|
|
|
|
|
|
void proposal_update_operation::get_required_authorities( vector<authority>& o )const
|
|
|
|
|
{
|
|
|
|
|
authority auth;
|
|
|
|
|
for( const auto& k : key_approvals_to_add )
|
|
|
|
|
auth.key_auths[k] = 1;
|
|
|
|
|
for( const auto& k : key_approvals_to_remove )
|
|
|
|
|
auth.key_auths[k] = 1;
|
|
|
|
|
auth.weight_threshold = auth.key_auths.size();
|
|
|
|
|
|
|
|
|
|
o.emplace_back( std::move(auth) );
|
|
|
|
|
}
|
2015-07-30 16:38:59 +00:00
|
|
|
|
2015-07-09 19:14:44 +00:00
|
|
|
void proposal_update_operation::get_required_active_authorities( flat_set<account_id_type>& a )const
|
|
|
|
|
{
|
|
|
|
|
for( const auto& i : active_approvals_to_add ) a.insert(i);
|
|
|
|
|
for( const auto& i : active_approvals_to_remove ) a.insert(i);
|
|
|
|
|
}
|
2015-07-30 16:38:59 +00:00
|
|
|
|
2015-07-09 19:14:44 +00:00
|
|
|
void proposal_update_operation::get_required_owner_authorities( flat_set<account_id_type>& a )const
|
|
|
|
|
{
|
|
|
|
|
for( const auto& i : owner_approvals_to_add ) a.insert(i);
|
|
|
|
|
for( const auto& i : owner_approvals_to_remove ) a.insert(i);
|
|
|
|
|
}
|
2015-07-30 16:38:59 +00:00
|
|
|
|
2019-04-14 04:38:56 +00:00
|
|
|
} } // graphene::protocol
|
2019-05-19 09:38:40 +00:00
|
|
|
|
2019-04-14 04:38:56 +00:00
|
|
|
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::proposal_create_operation::fee_parameters_type )
|
|
|
|
|
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::proposal_update_operation::fee_parameters_type )
|
|
|
|
|
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::proposal_delete_operation::fee_parameters_type )
|
|
|
|
|
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::proposal_create_operation )
|
|
|
|
|
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::proposal_update_operation )
|
|
|
|
|
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::protocol::proposal_delete_operation )
|