Issue #31: Add account_upgrade_evaluator
This commit is contained in:
parent
7f0d1ebbed
commit
4df4e8014a
5 changed files with 72 additions and 25 deletions
2
.gitmodules
vendored
2
.gitmodules
vendored
|
|
@ -1,6 +1,6 @@
|
||||||
[submodule "libraries/fc"]
|
[submodule "libraries/fc"]
|
||||||
path = libraries/fc
|
path = libraries/fc
|
||||||
url = https://github.com/cryptonomex/fc
|
url = git@github.com:cryptonomex/fc
|
||||||
ignore = dirty
|
ignore = dirty
|
||||||
[submodule "libraries/leveldb"]
|
[submodule "libraries/leveldb"]
|
||||||
path = libraries/leveldb
|
path = libraries/leveldb
|
||||||
|
|
|
||||||
|
|
@ -206,4 +206,39 @@ void_result account_whitelist_evaluator::do_apply(const account_whitelist_operat
|
||||||
return void_result();
|
return void_result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void_result account_upgrade_evaluator::do_evaluate(const account_upgrade_evaluator::operation_type& o)
|
||||||
|
{
|
||||||
|
database& d = db();
|
||||||
|
|
||||||
|
account = &d.get(o.account_to_upgrade);
|
||||||
|
FC_ASSERT(!account->is_lifetime_member());
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void_result account_upgrade_evaluator::do_apply(const account_upgrade_evaluator::operation_type& o)
|
||||||
|
{
|
||||||
|
database& d = db();
|
||||||
|
|
||||||
|
d.modify(*account, [&](account_object& a) {
|
||||||
|
if( o.upgrade_to_lifetime_member )
|
||||||
|
{
|
||||||
|
// Upgrade to lifetime member. I don't care what the account was before.
|
||||||
|
a.membership_expiration_date = time_point_sec::maximum();
|
||||||
|
a.referrer = a.registrar = a.lifetime_referrer = a.get_id();
|
||||||
|
} else if( a.is_annual_member(d.head_block_time()) ) {
|
||||||
|
// Renew an annual subscription that's still in effect.
|
||||||
|
FC_ASSERT(a.membership_expiration_date - d.head_block_time() < fc::days(3650),
|
||||||
|
"May not extend annual membership more than a decade into the future.");
|
||||||
|
a.membership_expiration_date += fc::days(365);
|
||||||
|
} else {
|
||||||
|
// Upgrade from basic account.
|
||||||
|
assert(a.is_basic_account(d.head_block_time()));
|
||||||
|
a.membership_expiration_date = d.head_block_time() + fc::days(365);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ void database::initialize_evaluators()
|
||||||
register_evaluator<key_create_evaluator>();
|
register_evaluator<key_create_evaluator>();
|
||||||
register_evaluator<account_create_evaluator>();
|
register_evaluator<account_create_evaluator>();
|
||||||
register_evaluator<account_update_evaluator>();
|
register_evaluator<account_update_evaluator>();
|
||||||
|
register_evaluator<account_upgrade_evaluator>();
|
||||||
register_evaluator<account_whitelist_evaluator>();
|
register_evaluator<account_whitelist_evaluator>();
|
||||||
register_evaluator<delegate_create_evaluator>();
|
register_evaluator<delegate_create_evaluator>();
|
||||||
register_evaluator<custom_evaluator>();
|
register_evaluator<custom_evaluator>();
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,17 @@ namespace graphene { namespace chain {
|
||||||
const account_object* acnt;
|
const account_object* acnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class account_upgrade_evaluator : public evaluator<account_upgrade_evaluator>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef account_upgrade_operation operation_type;
|
||||||
|
|
||||||
|
void_result do_evaluate(const operation_type& o);
|
||||||
|
void_result do_apply(const operation_type& o);
|
||||||
|
|
||||||
|
const account_object* account;
|
||||||
|
};
|
||||||
|
|
||||||
class account_whitelist_evaluator : public evaluator<account_whitelist_evaluator>
|
class account_whitelist_evaluator : public evaluator<account_whitelist_evaluator>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1bbb748c4ebbaaf42440cec220562c8c2027cb80
|
Subproject commit 80366e4346e85b550b58ce84d5112a1917f17e07
|
||||||
Loading…
Reference in a new issue