Issue #31: Add account_upgrade_evaluator

This commit is contained in:
Nathan Hourt 2015-06-10 10:36:01 -04:00
parent 7f0d1ebbed
commit 4df4e8014a
5 changed files with 72 additions and 25 deletions

2
.gitmodules vendored
View file

@ -1,6 +1,6 @@
[submodule "libraries/fc"]
path = libraries/fc
url = https://github.com/cryptonomex/fc
url = git@github.com:cryptonomex/fc
ignore = dirty
[submodule "libraries/leveldb"]
path = libraries/leveldb

View file

@ -206,4 +206,39 @@ void_result account_whitelist_evaluator::do_apply(const account_whitelist_operat
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

View file

@ -64,6 +64,7 @@ void database::initialize_evaluators()
register_evaluator<key_create_evaluator>();
register_evaluator<account_create_evaluator>();
register_evaluator<account_update_evaluator>();
register_evaluator<account_upgrade_evaluator>();
register_evaluator<account_whitelist_evaluator>();
register_evaluator<delegate_create_evaluator>();
register_evaluator<custom_evaluator>();

View file

@ -21,35 +21,46 @@
namespace graphene { namespace chain {
class account_create_evaluator : public evaluator<account_create_evaluator>
{
public:
typedef account_create_operation operation_type;
class account_create_evaluator : public evaluator<account_create_evaluator>
{
public:
typedef account_create_operation operation_type;
void_result do_evaluate( const account_create_operation& o );
object_id_type do_apply( const account_create_operation& o ) ;
};
void_result do_evaluate( const account_create_operation& o );
object_id_type do_apply( const account_create_operation& o ) ;
};
class account_update_evaluator : public evaluator<account_update_evaluator>
{
public:
typedef account_update_operation operation_type;
class account_update_evaluator : public evaluator<account_update_evaluator>
{
public:
typedef account_update_operation operation_type;
void_result do_evaluate( const account_update_operation& o );
void_result do_apply( const account_update_operation& o );
void_result do_evaluate( const account_update_operation& o );
void_result do_apply( const account_update_operation& o );
const account_object* acnt;
};
const account_object* acnt;
};
class account_whitelist_evaluator : public evaluator<account_whitelist_evaluator>
{
public:
typedef account_whitelist_operation operation_type;
class account_upgrade_evaluator : public evaluator<account_upgrade_evaluator>
{
public:
typedef account_upgrade_operation operation_type;
void_result do_evaluate( const account_whitelist_operation& o);
void_result do_apply( const account_whitelist_operation& o);
void_result do_evaluate(const operation_type& o);
void_result do_apply(const operation_type& o);
const account_object* listed_account;
};
const account_object* account;
};
class account_whitelist_evaluator : public evaluator<account_whitelist_evaluator>
{
public:
typedef account_whitelist_operation operation_type;
void_result do_evaluate( const account_whitelist_operation& o);
void_result do_apply( const account_whitelist_operation& o);
const account_object* listed_account;
};
} } // graphene::chain

@ -1 +1 @@
Subproject commit 1bbb748c4ebbaaf42440cec220562c8c2027cb80
Subproject commit 80366e4346e85b550b58ce84d5112a1917f17e07