Progress on #144 - refactoring fee schedule

This commit is contained in:
Daniel Larimer 2015-07-08 18:45:53 -04:00
parent baf5531238
commit fdcf821c41
42 changed files with 270 additions and 227 deletions

2
docs

@ -1 +1 @@
Subproject commit d0d1fd5b5e7eaab29d94b6b0388c5d6673f1a134
Subproject commit f3012a7328227e90da6ded944c3c4bf2a4ab94a0

View file

@ -19,6 +19,7 @@
#include <graphene/app/application.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/utilities/key_conversion.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/crypto/hex.hpp>

View file

@ -24,6 +24,8 @@
#include <graphene/time/time.hpp>
#include <graphene/utilities/key_conversion.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/smart_ref_impl.hpp>
#include <fc/rpc/api_connection.hpp>
#include <fc/rpc/websocket_api.hpp>
@ -58,7 +60,7 @@ namespace detail {
auto nathan_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
dlog("Allocating all stake to ${key}", ("key", utilities::key_to_wif(nathan_key)));
genesis_state_type initial_state;
initial_state.initial_parameters.current_fees.set_all_fees(GRAPHENE_BLOCKCHAIN_PRECISION);
initial_state.initial_parameters.current_fees = fee_schedule::get_default();//->set_all_fees(GRAPHENE_BLOCKCHAIN_PRECISION);
initial_state.initial_active_witnesses = 10;
for( int i = 0; i < initial_state.initial_active_witnesses; ++i )
{

View file

@ -16,13 +16,12 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <graphene/chain/types.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/proposal_object.hpp>

View file

@ -17,6 +17,7 @@
*/
#include <graphene/app/plugin.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
namespace graphene { namespace app {

View file

@ -5,6 +5,7 @@ add_library( graphene_chain
protocol/types.cpp
protocol/address.cpp
protocol/asset.cpp
protocol/assert.cpp
protocol/account.cpp
protocol/transfer.cpp
protocol/delegate.cpp
@ -19,6 +20,7 @@ add_library( graphene_chain
protocol/operations.cpp
protocol/transaction.cpp
protocol/block.cpp
protocol/fee_schedule.cpp
pts_address.cpp

View file

@ -1,4 +1,5 @@
/// This file combines these sources to perform a partial unity build
#include <fc/smart_ref_impl.hpp>
#include "db_balance.cpp"
#include "db_block.cpp"
#include "db_debug.cpp"

View file

@ -297,7 +297,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
p.parameters = genesis_state.initial_parameters;
// Set fees to zero initially, so that genesis initialization needs not pay them
// We'll fix it at the end of the function
p.parameters.current_fees->set_all_fees(0);
p.parameters.current_fees->zero_all_fees();
});
create<dynamic_global_property_object>( [&](dynamic_global_property_object& p) {

View file

@ -17,7 +17,6 @@
*/
#pragma once
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/protocol/block.hpp>
#include <graphene/chain/global_property_object.hpp>
#include <graphene/chain/node_property_object.hpp>
#include <graphene/chain/account_object.hpp>
@ -31,6 +30,8 @@
#include <graphene/db/simple_index.hpp>
#include <fc/signals.hpp>
#include <graphene/chain/protocol/protocol.hpp>
#include <fc/log/logger.hpp>
#include <map>

View file

@ -60,6 +60,14 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return registrar; }
void validate()const;
share_type calculate_fee(const fee_parameters_type& )const;
void get_impacted_accounts( flat_set<account_id_type>& i )const
{
i.insert(registrar);
i.insert(referrer);
add_authority_accounts( i, owner );
add_authority_accounts( i, active );
}
};
/**
@ -91,6 +99,16 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return account; }
void validate()const;
share_type calculate_fee( const fee_parameters_type& k )const;
void get_required_owner_authorities( flat_set<account_id_type>& a )const
{ if( owner || active ) a.insert( account ); }
void get_impacted_accounts( flat_set<account_id_type>& i )const
{
i.insert(account);
if( owner ) add_authority_accounts( i, *owner );
if( active ) add_authority_accounts( i, *active );
}
};
@ -135,6 +153,10 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return authorizing_account; }
void validate()const { FC_ASSERT( fee.amount >= 0 ); FC_ASSERT(new_listing < 0x4); }
void get_impacted_accounts( flat_set<account_id_type>& i )const
{ i.insert(account_to_list); }
};
@ -193,6 +215,11 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return account_id; }
void validate()const;
void get_impacted_accounts( flat_set<account_id_type>& i )const
{
i.insert(new_owner);
}
};
} }

View file

@ -53,7 +53,7 @@ namespace graphene { namespace chain {
*/
struct assert_operation : public base_operation
{
struct fee_parameters_type { share_type fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
asset fee;
account_id_type fee_paying_account;
@ -62,6 +62,7 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return fee_paying_account; }
void validate()const;
share_type calculate_fee(const fee_parameters_type& k)const;
};
} } // graphene::chain

View file

@ -239,6 +239,8 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return issuer; }
void validate()const;
share_type calculate_fee(const fee_parameters_type& k)const;
void get_impacted_accounts( flat_set<account_id_type>& i)const
{ if( new_issuer ) i.insert( *new_issuer ); }
};
/**
@ -349,6 +351,8 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return issuer; }
void validate()const;
share_type calculate_fee(const fee_parameters_type& k)const;
void get_impacted_accounts( flat_set<account_id_type>& i)const
{ i.insert( issue_to_account ); }
};
/**

View file

@ -74,6 +74,11 @@ namespace graphene { namespace chain {
void validate()const{}
static uint64_t calculate_data_fee( uint64_t bytes, uint64_t price_per_kbyte );
static void add_authority_accounts( flat_set<account_id_type>& i, const authority& a )
{
for( auto& item : a.account_auths )
i.insert( item.first );
}
};
///@}

View file

@ -25,9 +25,9 @@ namespace graphene { namespace chain {
* and then calculates the appropriate fee.
*/
asset calculate_fee( const operation& op, const price& core_exchange_rate = price::unit_price() )const;
void set_fee( operation& op, const price& core_exchange_rate = price::unit_price() )const;
asset set_fee( operation& op, const price& core_exchange_rate = price::unit_price() )const;
void set_all_fees( uint64_t fee_amount );
void zero_all_fees();
/**
* Validates all of the parameters are present and accounted for.

View file

@ -130,6 +130,8 @@ namespace graphene { namespace chain {
/// This is a virtual operation; there is no fee
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
void get_impacted_accounts( flat_set<account_id_type>& i)const
{ i.insert( account_id ); }
};
} } // graphene::chain

View file

@ -63,6 +63,8 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return fee_paying_account; }
void validate()const;
share_type calculate_fee(const fee_parameters_type& k)const;
void get_impacted_accounts( flat_set<account_id_type>& )const;
};
/**

View file

@ -0,0 +1,3 @@
#pragma once
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <graphene/chain/protocol/block.hpp>

View file

@ -39,6 +39,8 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return from; }
void validate()const;
share_type calculate_fee(const fee_parameters_type& k)const;
void get_impacted_accounts( flat_set<account_id_type>& i )const
{ i.insert(to); }
};
/**
@ -71,6 +73,12 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return issuer; }
void validate()const;
share_type calculate_fee(const fee_parameters_type& k)const;
void get_impacted_accounts( flat_set<account_id_type>& i )const
{
i.insert(to);
i.insert(from);
i.insert(issuer);
}
};
}} // graphene::chain

View file

@ -56,6 +56,9 @@ namespace graphene { namespace chain {
FC_ASSERT( fee.amount >= 0 );
FC_ASSERT( amount.amount > 0 );
}
void get_impacted_accounts( flat_set<account_id_type>& i )const
{ i.insert(owner); }
};
/**

View file

@ -43,6 +43,9 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return withdraw_from_account; }
void validate()const;
void get_impacted_accounts( flat_set<account_id_type>& i)const
{ i.insert( authorized_account ); }
};
/**
@ -78,6 +81,8 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return withdraw_from_account; }
void validate()const;
void get_impacted_accounts( flat_set<account_id_type>& i)const
{ i.insert( authorized_account ); }
};
/**
@ -116,6 +121,8 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return withdraw_to_account; }
void validate()const;
share_type calculate_fee(const fee_parameters_type& k)const;
void get_impacted_accounts( flat_set<account_id_type>& i)const
{ i.insert( withdraw_from_account ); }
};
/**
@ -140,6 +147,8 @@ namespace graphene { namespace chain {
account_id_type fee_payer()const { return withdraw_from_account; }
void validate()const;
void get_impacted_accounts( flat_set<account_id_type>& i)const
{ i.insert( authorized_account ); }
};
} } // graphene::chain

View file

@ -1,32 +1,17 @@
#include <graphene/chain/protocol/protocol.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/predicate.hpp>
namespace graphene { namespace chain {
namespace graphene { namespace chain { namespace pred {
bool account_name_eq_lit::validate()const
bool account_name_eq_lit_predicate::validate()const
{
return is_valid_name( name );
}
bool account_name_eq_lit::evaluate( const database& db )const
{
return account_id(db).name == name;
}
bool asset_symbol_eq_lit::validate()const
bool asset_symbol_eq_lit_predicate::validate()const
{
return is_valid_symbol( symbol );
}
bool asset_symbol_eq_lit::evaluate( const database& db )const
{
return asset_id(db).symbol == symbol;
}
struct predicate_validator
{
typedef void result_type;
@ -55,4 +40,4 @@ share_type assert_operation::calculate_fee(const fee_parameters_type& k)const
}
} } }
} } // namespace graphene::chain

View file

@ -42,6 +42,10 @@ bool is_valid_symbol( const string& symbol )
return true;
}
share_type asset_issue_operation::calculate_fee(const fee_parameters_type& k)const
{
return k.fee + calculate_data_fee( fc::raw::pack_size(memo), k.price_per_kbyte );
}
share_type asset_create_operation::calculate_fee(const asset_create_operation::fee_parameters_type& param)const
{

View file

@ -1,7 +1,10 @@
#include <graphene/chain/fee_schedule.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/smart_ref_impl.hpp>
namespace graphene { namespace chain {
typedef fc::smart_ref<fee_schedule> smart_fee_schedule;
fee_schedule::fee_schedule()
{
}
@ -9,7 +12,7 @@ namespace graphene { namespace chain {
fee_schedule fee_schedule::get_default()
{
fee_schedule result;
for( uint32_t i = 0; i < fee_parameters.count(); ++i )
for( uint32_t i = 0; i < fee_parameters().count(); ++i )
{
fee_parameters x; x.set_which(i);
result.parameters.insert(x);
@ -19,12 +22,12 @@ namespace graphene { namespace chain {
struct fee_schedule_validate_visitor
{
typedef result_type void;
typedef void result_type;
template<typename T>
void operator()( const T& p )const
{
p.validate();
//p.validate();
}
};
@ -36,25 +39,57 @@ namespace graphene { namespace chain {
struct calc_fee_visitor
{
typedef result_type asset;
typedef uint64_t result_type;
const fee_parameters& param;
calc_fee_visitor( const fee_parameters& p ):param(p){}
template<typename OpType>
asset operator()( const OpType& op )const
result_type operator()( const OpType& op )const
{
return op.calculate_fee( param.get<typename OpType::fee_parameters_type>() );
return op.calculate_fee( param.get<typename OpType::fee_parameters_type>() ).value;
}
};
struct set_fee_visitor
{
typedef void result_type;
asset _fee;
set_fee_visitor( asset f ):_fee(f){}
template<typename OpType>
void operator()( OpType& op )const
{
op.fee = _fee;
}
};
struct zero_fee_visitor
{
typedef void result_type;
template<typename ParamType>
result_type operator()( ParamType& op )const
{
memset( (char*)&op, sizeof(op), 0 );
}
};
void fee_schedule::zero_all_fees()
{
*this = get_default();
for( auto& i : parameters )
i.visit( zero_fee_visitor() );
}
asset fee_schedule::calculate_fee( const operation& op, const price& core_exchange_rate )const
{
fee_parameters params; params.set_which(op.which());
auto itr = parameters.find(params);
if( itr != parameters.end() ) params = *itr;
share_type base_value op.visit( calc_fee_visitor( params ) );
auto scaled = fc::uint128(base_value.value) * scale_factor;
auto base_value = op.visit( calc_fee_visitor( params ) );
auto scaled = fc::uint128(base_value) * scale;
scaled /= GRAPHENE_100_PERCENT;
FC_ASSERT( scaled <= GRAPHENE_MAX_SHARE_SUPPLY );
auto result = asset( scaled.to_uint64(), 0 ) * core_exchange_rate;
@ -62,4 +97,11 @@ namespace graphene { namespace chain {
return result;
}
asset fee_schedule::set_fee( operation& op, const price& core_exchange_rate )const
{
auto f = calculate_fee( op, core_exchange_rate );
op.visit( set_fee_visitor( f ) );
return f;
}
} } // graphene::chain

View file

@ -156,10 +156,40 @@ struct operation_validator
void operator()( const T& v )const { v.validate(); }
};
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 );
}
};
void operation_validate( const operation& op )
{
op.visit( operation_validator() );
}
void operation_get_required_authorities( const operation& op,
flat_set<account_id_type>& active,
flat_set<account_id_type>& owner,
vector<authority>& other )
{
}
} } // namespace graphene::chain

View file

@ -55,5 +55,12 @@ share_type proposal_update_operation::calculate_fee(const fee_parameters_type& k
{
return k.fee + calculate_data_fee( fc::raw::pack_size(*this), k.price_per_kbyte );
}
void proposal_create_operation::get_impacted_accounts( flat_set<account_id_type>& i )const
{
vector<authority> other;
for( const auto& op : proposed_ops )
operation_get_required_authorities( op.op, i, i, other );
for( auto& o : other )
add_authority_accounts( i, o );
}
} } // graphene::chain

@ -1 +1 @@
Subproject commit 1ce9f4c37e6d3b7672ca9cfb152d236085f31f74
Subproject commit 8d13f292b8ad47d4055bba8721731d73acd0561f

View file

@ -18,7 +18,7 @@
#pragma once
#include <graphene/net/config.hpp>
#include <graphene/chain/block.hpp>
#include <graphene/chain/protocol/block.hpp>
#include <fc/crypto/ripemd160.hpp>
#include <fc/crypto/elliptic.hpp>

View file

@ -21,7 +21,7 @@
#include <graphene/net/message.hpp>
#include <graphene/net/peer_database.hpp>
#include <graphene/chain/types.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <list>

View file

@ -71,6 +71,7 @@
#include <graphene/net/exceptions.hpp>
#include <graphene/chain/config.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/git_revision.hpp>

View file

@ -19,6 +19,7 @@
#include <graphene/net/exceptions.hpp>
#include <graphene/net/config.hpp>
#include <graphene/chain/config.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/thread/thread.hpp>

View file

@ -73,117 +73,15 @@ struct operation_get_impacted_accounts
_impacted.insert( item.first );
}
void operator()( const transfer_operation& o )const {
_impacted.insert( o.to );
}
void operator()( const limit_order_create_operation& o )const { }
void operator()( const limit_order_cancel_operation& o )const { }
void operator()( const call_order_update_operation& o )const { }
void operator()( const custom_operation& o )const { }
void operator()( const account_create_operation& o )const {
_impacted.insert( _op_history.result.get<object_id_type>() );
}
void operator()( const account_update_operation& o )const {
if( o.owner )
{
add_authority( *o.owner );
}
if( o.active )
{
add_authority( *o.active );
}
}
void operator()( const account_upgrade_operation& )const {}
void operator()( const account_transfer_operation& o )const
template<typename T>
void operator()( const T& o )const
{
_impacted.insert( o.new_owner );
o.get_impacted_accounts( _impacted );
}
void operator()( const account_whitelist_operation& o )const {
_impacted.insert( o.account_to_list );
}
void operator()( const asset_create_operation& o )const { }
void operator()( const asset_update_operation& o )const {
if( o.new_issuer )
_impacted.insert(*o.new_issuer);
}
void operator()( const asset_update_bitasset_operation& o )const {
}
void operator()( const asset_update_feed_producers_operation& o )const {
for( auto id : o.new_feed_producers )
_impacted.insert(id);
}
void operator()( const asset_issue_operation& o )const {
_impacted.insert( o.issue_to_account );
}
void operator()( const asset_reserve_operation& o )const { }
void operator()( const asset_global_settle_operation& o )const { }
void operator()( const asset_settle_operation& o )const { }
void operator()( const asset_fund_fee_pool_operation& o )const { }
void operator()( const asset_publish_feed_operation& o )const { }
void operator()( const delegate_create_operation& o )const { }
void operator()( const withdraw_permission_create_operation& o )const{
_impacted.insert(o.authorized_account);
}
void operator()( const withdraw_permission_claim_operation& o )const{
_impacted.insert( o.withdraw_from_account );
}
void operator()( const withdraw_permission_update_operation& o )const{
_impacted.insert( o.authorized_account );
}
void operator()( const withdraw_permission_delete_operation& o )const{
_impacted.insert( o.authorized_account );
}
void operator()( const witness_create_operation& o )const {
_impacted.insert(o.witness_account);
}
void operator()( const witness_withdraw_pay_operation& o )const { }
void operator()( const proposal_create_operation& o )const {
for( auto op : o.proposed_ops )
{
operation_get_required_active_authorities( op.op, _impacted );
operation_get_required_owner_authorities( op.op, _impacted );
}
}
void operator()( const proposal_update_operation& o )const { }
void operator()( const proposal_delete_operation& o )const { }
void operator()( const fill_order_operation& o )const {
_impacted.insert( o.account_id );
}
void operator()(const global_parameters_update_operation& )const {
_impacted.insert( account_id_type() );
}
void operator()( const vesting_balance_create_operation& o )const
{
_impacted.insert( o.creator );
_impacted.insert( o.owner );
}
void operator()( const vesting_balance_withdraw_operation& o )const
{
_impacted.insert( o.owner );
}
void operator()( const worker_create_operation& )const {}
void operator()( const assert_operation& )const {}
void operator()( const balance_claim_operation& )const {}
void operator()( const override_transfer_operation& )const {}
};
@ -207,10 +105,14 @@ void account_history_plugin_impl::update_account_histories( const signed_block&
// get the set of accounts this operation applies to
flat_set<account_id_type> impacted;
operation_get_required_active_authorities( op.op, impacted );
operation_get_required_owner_authorities( op.op, impacted );
vector<authority> other;
operation_get_required_authorities( op.op, impacted, impacted, other );
op.op.visit( operation_get_impacted_accounts( oho, _self, impacted ) );
for( auto& a : other )
for( auto& item : a.account_auths )
impacted.insert( item.first );
// for each operation this account applies to that is in the config link it into the history
if( _tracked_accounts.size() == 0 )
{

View file

@ -25,6 +25,7 @@
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/transaction_evaluation_state.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/thread/thread.hpp>

View file

@ -20,8 +20,7 @@
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>

View file

@ -18,7 +18,6 @@
#pragma once
#include <graphene/app/api.hpp>
#include <graphene/chain/address.hpp>
#include <graphene/utilities/key_conversion.hpp>
using namespace graphene::app;
@ -606,8 +605,8 @@ class wallet_api
signed_transaction create_asset(string issuer,
string symbol,
uint8_t precision,
asset_object::asset_options common,
fc::optional<asset_object::bitasset_options> bitasset_opts,
asset_options common,
fc::optional<bitasset_options> bitasset_opts,
bool broadcast = false);
/** Issue new shares of an asset.
@ -642,7 +641,7 @@ class wallet_api
*/
signed_transaction update_asset(string symbol,
optional<string> new_issuer,
asset_object::asset_options new_options,
asset_options new_options,
bool broadcast = false);
/** Update the options specific to a BitAsset.
@ -659,7 +658,7 @@ class wallet_api
* @returns the signed transaction updating the bitasset
*/
signed_transaction update_bitasset(string symbol,
asset_object::bitasset_options new_options,
bitasset_options new_options,
bool broadcast = false);
/** Update the set of feed-producing accounts for a BitAsset.

View file

@ -41,11 +41,11 @@
#include <fc/thread/scoped_lock.hpp>
#include <graphene/app/api.hpp>
#include <graphene/chain/address.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/utilities/key_conversion.hpp>
#include <graphene/wallet/wallet.hpp>
#include <graphene/wallet/api_documentation.hpp>
#include <fc/smart_ref_impl.hpp>
#ifndef WIN32
# include <sys/types.h>
@ -76,13 +76,13 @@ public:
template<typename T>
void operator()(const T& op)const
{
balance_accumulator acc;
op.get_balance_delta( acc, result );
//balance_accumulator acc;
//op.get_balance_delta( acc, result );
string op_name = fc::get_typename<T>::name();
if( op_name.find_last_of(':') != string::npos )
op_name.erase(0, op_name.find_last_of(':')+1);
out << op_name <<" ";
out << "balance delta: " << fc::json::to_string(acc.balance) <<" ";
// out << "balance delta: " << fc::json::to_string(acc.balance) <<" ";
out << fc::json::to_string(op.fee_payer()) << " fee: " << fc::json::to_string(op.fee);
}
void operator()(const transfer_operation& op)const;
@ -378,6 +378,12 @@ public:
return ob.template as<T>();
}
void set_operation_fees( signed_transaction& tx, const fee_schedule& s )
{
for( auto& op : tx.operations )
s.set_fee(op);
}
variant info() const
{
auto global_props = get_global_properties();
@ -612,12 +618,12 @@ public:
_builder_transactions[transaction_handle].operations.emplace_back(op);
}
void replace_operation_in_builder_transaction(transaction_handle_type handle,
unsigned operation_index,
uint32_t operation_index,
const operation& new_op)
{
FC_ASSERT(_builder_transactions.count(handle));
signed_transaction& trx = _builder_transactions[handle];
FC_ASSERT(operation_index >= 0 && operation_index < trx.operations.size());
FC_ASSERT( operation_index < trx.operations.size());
trx.operations[operation_index] = new_op;
}
asset set_fees_on_builder_transaction(transaction_handle_type handle, string fee_asset = GRAPHENE_SYMBOL)
@ -626,24 +632,20 @@ public:
auto fee_asset_obj = get_asset(fee_asset);
asset total_fee = fee_asset_obj.amount(0);
auto gprops = _remote_db->get_global_properties().parameters;
if( fee_asset_obj.get_id() != asset_id_type() )
{
_builder_transactions[handle].visit(
operation_set_fee(_remote_db->get_global_properties().parameters.current_fees,
fee_asset_obj.options.core_exchange_rate,
&total_fee.amount)
);
for( auto& op : _builder_transactions[handle].operations )
total_fee += gprops.current_fees->set_fee( op, fee_asset_obj.options.core_exchange_rate );
FC_ASSERT((total_fee * fee_asset_obj.options.core_exchange_rate).amount <=
get_object<asset_dynamic_data_object>(fee_asset_obj.dynamic_asset_data_id).fee_pool,
"Cannot pay fees in ${asset}, as this asset's fee pool is insufficiently funded.",
("asset", fee_asset_obj.symbol));
} else {
_builder_transactions[handle].visit(
operation_set_fee(_remote_db->get_global_properties().parameters.current_fees,
price::unit_price(),
&total_fee.amount)
);
for( auto& op : _builder_transactions[handle].operations )
total_fee += gprops.current_fees->set_fee( op );
}
return total_fee;
@ -671,8 +673,8 @@ public:
[](const operation& op) -> op_wrapper { return op; });
if( review_period_seconds )
op.review_period_seconds = review_period_seconds;
op.fee = op.calculate_fee(_remote_db->get_global_properties().parameters.current_fees);
trx.operations = {op};
_remote_db->get_global_properties().parameters.current_fees->set_fee( trx.operations.front() );
return trx = sign_transaction(trx, broadcast);
}
@ -681,6 +683,7 @@ public:
_builder_transactions.erase(handle);
}
signed_transaction register_account(string name,
public_key_type owner,
public_key_type active,
@ -716,7 +719,8 @@ public:
tx.operations.push_back( account_create_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
auto current_fees = _remote_db->get_global_properties().parameters.current_fees;
set_operation_fees( tx, current_fees );
vector<public_key_type> paying_keys = registrar_account_object.active.get_keys();
@ -741,6 +745,7 @@ public:
return tx;
} FC_CAPTURE_AND_RETHROW( (name)(owner)(active)(registrar_account)(referrer_account)(referrer_percent)(broadcast) ) }
signed_transaction upgrade_account(string name, bool broadcast)
{ try {
FC_ASSERT( !self.is_locked() );
@ -752,7 +757,7 @@ public:
op.account_to_upgrade = account_obj.get_id();
op.upgrade_to_lifetime_member = true;
tx.operations = {op};
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees );
tx.validate();
return sign_transaction( tx, broadcast );
@ -838,7 +843,7 @@ public:
tx.operations.push_back( account_create_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
vector<public_key_type> paying_keys = registrar_account_object.active.get_keys();
@ -884,8 +889,8 @@ public:
signed_transaction create_asset(string issuer,
string symbol,
uint8_t precision,
asset_object::asset_options common,
fc::optional<asset_object::bitasset_options> bitasset_opts,
asset_options common,
fc::optional<bitasset_options> bitasset_opts,
bool broadcast = false)
{ try {
account_object issuer_account = get_account( issuer );
@ -900,7 +905,7 @@ public:
signed_transaction tx;
tx.operations.push_back( create_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -908,7 +913,7 @@ public:
signed_transaction update_asset(string symbol,
optional<string> new_issuer,
asset_object::asset_options new_options,
asset_options new_options,
bool broadcast /* = false */)
{ try {
optional<asset_object> asset_to_update = find_asset(symbol);
@ -929,14 +934,14 @@ public:
signed_transaction tx;
tx.operations.push_back( update_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (symbol)(new_issuer)(new_options)(broadcast) ) }
signed_transaction update_bitasset(string symbol,
asset_object::bitasset_options new_options,
bitasset_options new_options,
bool broadcast /* = false */)
{ try {
optional<asset_object> asset_to_update = find_asset(symbol);
@ -950,7 +955,7 @@ public:
signed_transaction tx;
tx.operations.push_back( update_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -974,7 +979,7 @@ public:
signed_transaction tx;
tx.operations.push_back( update_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -996,7 +1001,7 @@ public:
signed_transaction tx;
tx.operations.push_back( publish_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1020,7 +1025,7 @@ public:
signed_transaction tx;
tx.operations.push_back( fund_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1042,7 +1047,7 @@ public:
signed_transaction tx;
tx.operations.push_back( reserve_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1063,7 +1068,7 @@ public:
signed_transaction tx;
tx.operations.push_back( settle_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1084,7 +1089,7 @@ public:
signed_transaction tx;
tx.operations.push_back( settle_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1102,7 +1107,7 @@ public:
signed_transaction tx;
tx.operations.push_back( whitelist_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1120,7 +1125,7 @@ public:
signed_transaction tx;
tx.operations.push_back( delegate_create_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1221,7 +1226,7 @@ public:
signed_transaction tx;
tx.operations.push_back( witness_create_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
_wallet.pending_witness_registrations[owner_account] = key_to_wif(witness_private_key);
@ -1257,7 +1262,7 @@ public:
signed_transaction tx;
tx.operations.push_back( account_update_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1291,7 +1296,7 @@ public:
signed_transaction tx;
tx.operations.push_back( account_update_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1322,7 +1327,7 @@ public:
signed_transaction tx;
tx.operations.push_back( account_update_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1348,7 +1353,7 @@ public:
signed_transaction tx;
tx.operations.push_back( account_update_op );
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1472,7 +1477,7 @@ public:
signed_transaction tx;
tx.operations.push_back(op);
tx.visit( operation_set_fee( _remote_db->get_global_properties().parameters.current_fees ) );
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction( tx, broadcast );
@ -1493,7 +1498,7 @@ public:
signed_transaction trx;
trx.operations = {op};
trx.visit(operation_set_fee(_remote_db->get_global_properties().parameters.current_fees));
set_operation_fees( trx, _remote_db->get_global_properties().parameters.current_fees);
trx.validate();
idump((broadcast));
@ -1509,7 +1514,7 @@ public:
limit_order_cancel_operation op;
op.fee_paying_account = get_object<limit_order_object>(order_id).seller;
op.order = order_id;
op.fee = op.calculate_fee(_remote_db->get_global_properties().parameters.current_fees);
set_operation_fees( trx, _remote_db->get_global_properties().parameters.current_fees);
trx.operations = {op};
trx.validate();
@ -1545,7 +1550,7 @@ public:
signed_transaction tx;
tx.operations.push_back(xfer_op);
tx.visit(operation_set_fee(_remote_db->get_global_properties().parameters.current_fees));
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction(tx, broadcast);
@ -1575,7 +1580,7 @@ public:
signed_transaction tx;
tx.operations.push_back(issue_op);
tx.visit(operation_set_fee(_remote_db->get_global_properties().parameters.current_fees));
set_operation_fees(tx,_remote_db->get_global_properties().parameters.current_fees);
tx.validate();
return sign_transaction(tx, broadcast);
@ -1631,7 +1636,7 @@ public:
void dbg_make_uia(string creator, string symbol)
{
asset_object::asset_options opts;
asset_options opts;
opts.flags &= ~(white_list | disable_force_settle | global_settle);
opts.issuer_permissions = opts.flags;
opts.core_exchange_rate = price(asset(1), asset(1,1));
@ -1640,11 +1645,11 @@ public:
void dbg_make_mia(string creator, string symbol)
{
asset_object::asset_options opts;
asset_options opts;
opts.flags &= ~white_list;
opts.issuer_permissions = opts.flags;
opts.core_exchange_rate = price(asset(1), asset(1,1));
asset_object::bitasset_options bopts;
bitasset_options bopts;
create_asset(get_account(creator).name, symbol, 2, opts, bopts, true);
}
@ -1984,8 +1989,8 @@ signed_transaction wallet_api::transfer(string from, string to, string amount,
signed_transaction wallet_api::create_asset(string issuer,
string symbol,
uint8_t precision,
asset_object::asset_options common,
fc::optional<asset_object::bitasset_options> bitasset_opts,
asset_options common,
fc::optional<bitasset_options> bitasset_opts,
bool broadcast)
{
@ -1994,14 +1999,14 @@ signed_transaction wallet_api::create_asset(string issuer,
signed_transaction wallet_api::update_asset(string symbol,
optional<string> new_issuer,
asset_object::asset_options new_options,
asset_options new_options,
bool broadcast /* = false */)
{
return my->update_asset(symbol, new_issuer, new_options, broadcast);
}
signed_transaction wallet_api::update_bitasset(string symbol,
asset_object::bitasset_options new_options,
bitasset_options new_options,
bool broadcast /* = false */)
{
return my->update_bitasset(symbol, new_options, broadcast);
@ -2158,8 +2163,8 @@ operation wallet_api::get_prototype_operation(string operation_name)
return graphene::chain::witness_create_operation();
if (operation_name == "witness_withdraw_pay_operation")
return graphene::chain::witness_withdraw_pay_operation();
if (operation_name == "global_parameters_update_operation")
return graphene::chain::global_parameters_update_operation();
if (operation_name == "delegate_update_global_parameters_operation")
return graphene::chain::delegate_update_global_parameters_operation();
if (operation_name == "transfer_operation")
return graphene::chain::transfer_operation();
if (operation_name == "override_transfer_operation")
@ -2304,9 +2309,9 @@ string wallet_api::gethelp(const string& method)const
ss << "usage: ISSUER SYMBOL PRECISION_DIGITS OPTIONS BITASSET_OPTIONS BROADCAST\n\n";
ss << "PRECISION_DIGITS: the number of digits after the decimal point\n\n";
ss << "Example value of OPTIONS: \n";
ss << fc::json::to_pretty_string( graphene::chain::asset_object::asset_options() );
ss << fc::json::to_pretty_string( graphene::chain::asset_options() );
ss << "\nExample value of BITASSET_OPTIONS: \n";
ss << fc::json::to_pretty_string( graphene::chain::asset_object::bitasset_options() );
ss << fc::json::to_pretty_string( graphene::chain::bitasset_options() );
ss << "\nBITASSET_OPTIONS may be null\n";
}
else
@ -2423,7 +2428,7 @@ signed_transaction wallet_api::import_balance( string name_or_id, const vector<s
}
}
trx.visit( operation_set_fee( my->_remote_db->get_global_properties().parameters.current_fees ) );
my->set_operation_fees( trx, my->_remote_db->get_global_properties().parameters.current_fees );
trx.validate();
auto tx = sign_transaction( trx, false );

View file

@ -1,5 +1,4 @@
add_subdirectory( cli_wallet )
add_subdirectory( cli_full_wallet )
add_subdirectory( witness_node )
add_subdirectory( js_operation_serializer )
add_subdirectory( size_checker )

View file

@ -30,7 +30,7 @@
#include <fc/rpc/websocket_api.hpp>
#include <graphene/app/api.hpp>
#include <graphene/chain/address.hpp>
#include <graphene/chain/protocol/protocol.hpp>
#include <graphene/utilities/key_conversion.hpp>
#include <graphene/wallet/wallet.hpp>

View file

@ -15,16 +15,14 @@
* 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.
*/
#include <graphene/chain/operations.hpp>
#include <graphene/chain/protocol/protocol.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/balance_object.hpp>
#include <graphene/chain/block.hpp>
#include <iostream>
using namespace graphene::chain;
@ -368,7 +366,6 @@ int main( int argc, char** argv )
detail_ns::js_name<operation_result>::name("operation_result");
detail_ns::js_name<header_extension>::name("header_extension");
detail_ns::js_name<parameter_extension>::name("parameter_extension");
detail_ns::js_name<static_variant<refund_worker_type::initializer, vesting_balance_worker_type::initializer,burn_worker_type::initializer>>::name("worker_initializer");
detail_ns::js_name<static_variant<linear_vesting_policy_initializer,cdd_vesting_policy_initializer>>::name("vesting_policy_initializer");
detail_ns::serializer<signed_block>::init();
detail_ns::serializer<block_header>::init();

View file

@ -20,7 +20,7 @@
#include <fc/variant.hpp>
#include <fc/variant_object.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/protocol/protocol.hpp>
#include <algorithm>
#include <iostream>

View file

@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE( two_node_network )
assert_operation op;
op.fee_paying_account = GRAPHENE_TEMP_ACCOUNT;
op.predicates.push_back( fc::raw::pack( graphene::chain::pred::asset_symbol_eq_lit{ asset_id_type(), "CORE" } ) );
op.predicates.push_back( graphene::chain::asset_symbol_eq_lit_predicate{ asset_id_type(), "CORE" } );
trx.operations.push_back( std::move( op ) );

View file

@ -16,7 +16,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <graphene/chain/database.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/time/time.hpp>
@ -88,15 +87,17 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench )
auto b = db.generate_block( db.get_slot_time( 1 ), db.get_scheduled_witness( 1 ).first, delegate_priv_key, ~0 );
start_time = fc::time_point::now();
/* TODO: get this buliding again
for( int i = 0; i < blocks_to_produce; ++i )
{
signed_transaction trx;
trx.operations.emplace_back(transfer_operation({asset(1), account_id_type(i + 11), account_id_type(), asset(1), memo_data()}));
trx.operations.emplace_back(transfer_operation(asset(1), account_id_type(i + 11), account_id_type(), asset(1), memo_data()));
db.push_transaction(trx, ~0);
aw = db.get_global_properties().active_witnesses;
b = db.generate_block( db.get_slot_time( 1 ), db.get_scheduled_witness( 1 ).first, delegate_priv_key, ~0 );
}
*/
ilog("Pushed ${c} blocks (1 op each, no validation) in ${t} milliseconds.",
("c", blocks_out)("t", (fc::time_point::now() - start_time).count() / 1000));

View file

@ -26,8 +26,7 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/delegate_object.hpp>
#include <graphene/chain/limit_order_object.hpp>
#include <graphene/chain/call_order_object.hpp>
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/witness_object.hpp>