Merge branch 'master' of https://github.com/cryptonomex/graphene
This commit is contained in:
commit
62d21be888
9 changed files with 181 additions and 173 deletions
|
|
@ -249,8 +249,6 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
create<block_summary_object>([&](block_summary_object&) {});
|
||||
|
||||
// Create initial accounts
|
||||
if( !genesis_state.initial_accounts.empty() )
|
||||
{
|
||||
for( const auto& account : genesis_state.initial_accounts )
|
||||
{
|
||||
/*
|
||||
|
|
@ -286,7 +284,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
apply_operation(genesis_eval_state, op);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto& accounts_by_name = get_index_type<account_index>().indices().get<by_name>();
|
||||
auto get_account_id = [&accounts_by_name](const string& name) {
|
||||
auto itr = accounts_by_name.find(name);
|
||||
|
|
@ -301,8 +299,7 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
FC_ASSERT(itr != assets_by_symbol.end());
|
||||
return itr->get_id();
|
||||
};
|
||||
if( !genesis_state.initial_assets.empty() )
|
||||
{
|
||||
|
||||
for( const genesis_state_type::initial_asset_type& asset : genesis_state.initial_assets )
|
||||
{
|
||||
asset_dynamic_data_id_type dynamic_data_id;
|
||||
|
|
@ -375,12 +372,9 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
a.bitasset_data_id = bitasset_data_id;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Create initial balances
|
||||
share_type total_allocation;
|
||||
if( !genesis_state.initial_balances.empty() )
|
||||
{
|
||||
for( const auto& handout : genesis_state.initial_balances )
|
||||
{
|
||||
create<balance_object>([&handout,&assets_by_symbol,total_allocation](balance_object& b) {
|
||||
|
|
@ -389,26 +383,24 @@ void database::init_genesis(const genesis_state_type& genesis_state)
|
|||
});
|
||||
total_allocation += handout.amount;
|
||||
}
|
||||
}
|
||||
|
||||
// Create initial vesting balances
|
||||
if( !genesis_state.initial_vesting_balances.empty() )
|
||||
{
|
||||
for( const genesis_state_type::initial_vesting_balance_type& vest : genesis_state.initial_vesting_balances )
|
||||
{
|
||||
create<balance_object>([&](balance_object& b) {
|
||||
b.balance = asset(vest.amount, assets_by_symbol.find(vest.asset_symbol)->get_id());
|
||||
b.owner = vest.owner;
|
||||
b.balance = asset( vest.amount, assets_by_symbol.find( vest.asset_symbol )->get_id() );
|
||||
|
||||
linear_vesting_policy policy;
|
||||
policy.earliest_withdraw_time = vest.earliest_withdrawal_date;
|
||||
policy.begin_date = vest.vesting_start_date;
|
||||
policy.vesting_seconds = (vest.vesting_end_date - vest.vesting_start_date).to_seconds();
|
||||
policy.begin_balance = b.balance.amount;
|
||||
b.vesting_policy = policy;
|
||||
policy.begin_timestamp = vest.begin_timestamp;
|
||||
policy.vesting_cliff_seconds = 0;
|
||||
policy.vesting_duration_seconds = vest.vesting_duration_seconds;
|
||||
policy.begin_balance = vest.begin_balance;
|
||||
|
||||
b.vesting_policy = std::move( policy );
|
||||
});
|
||||
total_allocation += vest.amount;
|
||||
}
|
||||
}
|
||||
|
||||
// Set current supply based on allocations, if they happened
|
||||
if( total_allocation > 0 )
|
||||
|
|
|
|||
|
|
@ -66,9 +66,9 @@ struct genesis_state_type {
|
|||
address owner;
|
||||
string asset_symbol;
|
||||
share_type amount;
|
||||
time_point_sec vesting_start_date;
|
||||
time_point_sec earliest_withdrawal_date;
|
||||
time_point_sec vesting_end_date;
|
||||
time_point_sec begin_timestamp;
|
||||
uint32_t vesting_duration_seconds = 0;
|
||||
share_type begin_balance;
|
||||
};
|
||||
struct initial_witness_type {
|
||||
/// Must correspond to one of the initial accounts
|
||||
|
|
@ -97,7 +97,7 @@ FC_REFLECT(graphene::chain::genesis_state_type::initial_account_type, (name)(own
|
|||
FC_REFLECT(graphene::chain::genesis_state_type::initial_balance_type,
|
||||
(owner)(asset_symbol)(amount))
|
||||
FC_REFLECT(graphene::chain::genesis_state_type::initial_vesting_balance_type,
|
||||
(owner)(asset_symbol)(amount)(vesting_start_date)(earliest_withdrawal_date)(vesting_end_date))
|
||||
(owner)(asset_symbol)(amount)(begin_timestamp)(vesting_duration_seconds)(begin_balance))
|
||||
FC_REFLECT(graphene::chain::genesis_state_type::initial_witness_type, (owner_name)(block_signing_key)(initial_secret))
|
||||
FC_REFLECT(graphene::chain::genesis_state_type::initial_committee_member_type, (owner_name))
|
||||
FC_REFLECT(graphene::chain::genesis_state_type::initial_asset_type::initial_bitasset_options::initial_collateral_position,
|
||||
|
|
|
|||
|
|
@ -1239,10 +1239,10 @@ namespace graphene { namespace chain {
|
|||
|
||||
struct linear_vesting_policy_initializer
|
||||
{
|
||||
/** while vesting begins on begin_date, none may be claimed before the start_claim time */
|
||||
fc::time_point_sec start_claim;
|
||||
fc::time_point_sec begin_date;
|
||||
uint32_t vesting_seconds = 0;
|
||||
/** while vesting begins on begin_timestamp, none may be claimed before vesting_cliff_seconds have passed */
|
||||
fc::time_point_sec begin_timestamp;
|
||||
uint32_t vesting_cliff_seconds = 0;
|
||||
uint32_t vesting_duration_seconds = 0;
|
||||
};
|
||||
|
||||
struct cdd_vesting_policy_initializer
|
||||
|
|
@ -1673,6 +1673,6 @@ FC_REFLECT( graphene::chain::balance_claim_operation,
|
|||
FC_REFLECT_TYPENAME( graphene::chain::operation )
|
||||
FC_REFLECT_TYPENAME( graphene::chain::operation_result )
|
||||
FC_REFLECT_TYPENAME( fc::flat_set<graphene::chain::vote_id_type> )
|
||||
FC_REFLECT(graphene::chain::linear_vesting_policy_initializer, (start_claim)(begin_date)(vesting_seconds) )
|
||||
FC_REFLECT(graphene::chain::linear_vesting_policy_initializer, (begin_timestamp)(vesting_cliff_seconds)(vesting_duration_seconds) )
|
||||
FC_REFLECT(graphene::chain::cdd_vesting_policy_initializer, (start_claim)(vesting_seconds) )
|
||||
FC_REFLECT_TYPENAME( graphene::chain::vesting_policy_initializer )
|
||||
|
|
|
|||
|
|
@ -54,17 +54,14 @@ namespace graphene { namespace chain {
|
|||
*/
|
||||
struct linear_vesting_policy
|
||||
{
|
||||
/// No amount may be withdrawn before this time, regardless of how much has vested.
|
||||
fc::time_point_sec earliest_withdraw_time;
|
||||
/// This is the time at which funds begin vesting.
|
||||
/// Note that withdrawals are still not available until @ref earliest_withdraw_time
|
||||
fc::time_point_sec begin_date;
|
||||
/// Duration of vesting period, in seconds. Must be greater than zero.
|
||||
uint32_t vesting_seconds = 0;
|
||||
/// The total amount of asset to vest
|
||||
fc::time_point_sec begin_timestamp;
|
||||
/// No amount may be withdrawn before this many seconds of the vesting period have elapsed.
|
||||
uint32_t vesting_cliff_seconds = 0;
|
||||
/// Duration of the vesting period, in seconds. Must be greater than 0 and greater than vesting_cliff_seconds.
|
||||
uint32_t vesting_duration_seconds = 0;
|
||||
/// The total amount of asset to vest.
|
||||
share_type begin_balance;
|
||||
/// The total amount of asset which has already been withdrawn
|
||||
share_type total_withdrawn;
|
||||
|
||||
asset get_allowed_withdraw(const vesting_policy_context& ctx)const;
|
||||
bool is_deposit_allowed(const vesting_policy_context& ctx)const;
|
||||
|
|
@ -174,11 +171,10 @@ namespace graphene { namespace chain {
|
|||
} } // graphene::chain
|
||||
|
||||
FC_REFLECT(graphene::chain::linear_vesting_policy,
|
||||
(earliest_withdraw_time)
|
||||
(begin_date)
|
||||
(vesting_seconds)
|
||||
(begin_timestamp)
|
||||
(vesting_cliff_seconds)
|
||||
(vesting_duration_seconds)
|
||||
(begin_balance)
|
||||
(total_withdrawn)
|
||||
)
|
||||
|
||||
FC_REFLECT(graphene::chain::cdd_vesting_policy,
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ graphene::chain::transaction_id_type graphene::chain::transaction::id() const
|
|||
memcpy(result._hash, hash._hash, std::min(sizeof(result), sizeof(hash)));
|
||||
return result;
|
||||
}
|
||||
|
||||
void graphene::chain::signed_transaction::sign(const private_key_type& key)
|
||||
{
|
||||
if( relative_expiration != 0 )
|
||||
|
|
@ -71,6 +72,15 @@ void graphene::chain::signed_transaction::sign(const private_key_type& key)
|
|||
signatures.push_back(key.sign_compact(digest()));
|
||||
}
|
||||
}
|
||||
|
||||
void transaction::set_expiration( fc::time_point_sec expiration_time )
|
||||
{
|
||||
ref_block_num = 0;
|
||||
relative_expiration = 0;
|
||||
ref_block_prefix = expiration_time.sec_since_epoch();
|
||||
block_id_cache.reset();
|
||||
}
|
||||
|
||||
void transaction::set_expiration( const block_id_type& reference_block, unsigned_int lifetime_intervals )
|
||||
{
|
||||
ref_block_num = boost::endian::endian_reverse(reference_block._hash[0]);
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ struct init_policy_visitor
|
|||
void operator()( const linear_vesting_policy_initializer& i )const
|
||||
{
|
||||
linear_vesting_policy policy;
|
||||
policy.vesting_seconds = i.vesting_seconds;
|
||||
policy.begin_date = i.begin_date;
|
||||
policy.earliest_withdraw_time = i.start_claim;
|
||||
policy.begin_timestamp = i.begin_timestamp;
|
||||
policy.vesting_cliff_seconds = i.vesting_cliff_seconds;
|
||||
policy.vesting_duration_seconds = i.vesting_duration_seconds;
|
||||
policy.begin_balance = init_balance;
|
||||
p = policy;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,30 +28,37 @@ inline bool sum_below_max_shares(const asset& a, const asset& b)
|
|||
&& ((a.amount + b.amount) <= GRAPHENE_MAX_SHARE_SUPPLY);
|
||||
}
|
||||
|
||||
asset linear_vesting_policy::get_allowed_withdraw(const vesting_policy_context& ctx) const
|
||||
asset linear_vesting_policy::get_allowed_withdraw( const vesting_policy_context& ctx )const
|
||||
{
|
||||
if(ctx.now <= earliest_withdraw_time)
|
||||
return asset(0, ctx.balance.asset_id);
|
||||
if(ctx.now <= begin_date)
|
||||
return asset(0, ctx.balance.asset_id);
|
||||
if(vesting_seconds == 0)
|
||||
return ctx.balance;
|
||||
share_type allowed_withdraw = 0;
|
||||
|
||||
int64_t elapsed_seconds = (ctx.now - begin_date).to_seconds();
|
||||
if( ctx.now > begin_timestamp )
|
||||
{
|
||||
const auto elapsed_seconds = (ctx.now - begin_timestamp).to_seconds();
|
||||
assert( elapsed_seconds > 0 );
|
||||
|
||||
// if elapsed_seconds <= 0, then ctx.now <= begin_date,
|
||||
// and we should have returned above.
|
||||
assert(elapsed_seconds > 0);
|
||||
if( elapsed_seconds >= vesting_cliff_seconds )
|
||||
{
|
||||
share_type total_vested = 0;
|
||||
if( elapsed_seconds < vesting_duration_seconds )
|
||||
{
|
||||
total_vested = (fc::uint128_t( begin_balance.value ) * elapsed_seconds / vesting_duration_seconds).to_uint64();
|
||||
}
|
||||
else
|
||||
{
|
||||
total_vested = begin_balance;
|
||||
}
|
||||
assert( total_vested >= 0 );
|
||||
|
||||
fc::uint128_t total_allowed = begin_balance.value;
|
||||
total_allowed *= uint64_t(elapsed_seconds);
|
||||
total_allowed /= vesting_seconds;
|
||||
const share_type withdrawn_already = begin_balance - ctx.balance.amount;
|
||||
assert( withdrawn_already >= 0 );
|
||||
|
||||
if(total_allowed <= total_withdrawn.value)
|
||||
return asset(0, ctx.balance.asset_id);
|
||||
total_allowed -= total_withdrawn.value;
|
||||
FC_ASSERT(total_allowed <= GRAPHENE_MAX_SHARE_SUPPLY);
|
||||
return asset(total_allowed.to_uint64(), ctx.balance.asset_id);
|
||||
allowed_withdraw = total_vested - withdrawn_already;
|
||||
assert( allowed_withdraw >= 0 );
|
||||
}
|
||||
}
|
||||
|
||||
return asset( allowed_withdraw, ctx.amount.asset_id );
|
||||
}
|
||||
|
||||
void linear_vesting_policy::on_deposit(const vesting_policy_context& ctx)
|
||||
|
|
@ -66,12 +73,12 @@ bool linear_vesting_policy::is_deposit_allowed(const vesting_policy_context& ctx
|
|||
|
||||
void linear_vesting_policy::on_withdraw(const vesting_policy_context& ctx)
|
||||
{
|
||||
total_withdrawn += ctx.amount.amount;
|
||||
}
|
||||
|
||||
bool linear_vesting_policy::is_withdraw_allowed(const vesting_policy_context& ctx)const
|
||||
{
|
||||
return (ctx.amount <= get_allowed_withdraw(ctx));
|
||||
return (ctx.amount.asset_id == ctx.balance.asset_id)
|
||||
&& (ctx.amount <= get_allowed_withdraw(ctx));
|
||||
}
|
||||
|
||||
fc::uint128_t cdd_vesting_policy::compute_coin_seconds_earned(const vesting_policy_context& ctx)const
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 7bd47af88eaba93711da58cf7ddfe866deb21948
|
||||
Subproject commit d462be0e92a576b93a83194e9649af528162bb4a
|
||||
|
|
@ -70,9 +70,12 @@ BOOST_AUTO_TEST_CASE( two_node_network )
|
|||
trx.set_expiration(now + fc::seconds(30));
|
||||
std::shared_ptr<chain::database> db2 = app2.chain_database();
|
||||
|
||||
trx.operations.push_back(assert_operation({asset(),
|
||||
GRAPHENE_TEMP_ACCOUNT,
|
||||
{ fc::raw::pack( graphene::chain::pred::asset_symbol_eq_lit{asset_id_type(),"CORE"} ) } }));
|
||||
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" } ) );
|
||||
|
||||
trx.operations.push_back( std::move( op ) );
|
||||
|
||||
trx.validate();
|
||||
processed_transaction ptrx = app1.chain_database()->push_transaction(trx);
|
||||
app1.p2p_node()->broadcast(graphene::net::trx_message(trx));
|
||||
|
|
|
|||
Loading…
Reference in a new issue