From 19d10e462cfb59d41fadd98ade71436d6597192e Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Wed, 26 Aug 2015 15:35:36 -0400 Subject: [PATCH] Implement GRAPHENE_PROXY_TO_SELF_ACCOUNT #267 --- libraries/chain/db_init.cpp | 10 ++++++++++ libraries/chain/db_maint.cpp | 2 +- libraries/chain/include/graphene/chain/config.hpp | 2 ++ .../chain/include/graphene/chain/protocol/account.hpp | 5 +++-- libraries/wallet/wallet.cpp | 4 ++-- tests/common/database_fixture.cpp | 3 +++ tests/tests/operation_tests.cpp | 2 +- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 42aebdbd..c69e7b91 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -274,6 +274,16 @@ void database::init_genesis(const genesis_state_type& genesis_state) a.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; }).get_id() == GRAPHENE_TEMP_ACCOUNT); + FC_ASSERT(create([this](account_object& a) { + a.name = "proxy-to-self"; + a.statistics = create([&](account_statistics_object& s){s.owner = a.id;}).id; + a.owner.weight_threshold = 1; + a.active.weight_threshold = 1; + a.registrar = a.lifetime_referrer = a.referrer = GRAPHENE_NULL_ACCOUNT; + a.membership_expiration_date = time_point_sec::maximum(); + a.network_fee_percentage = 0; + a.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT; + }).get_id() == GRAPHENE_PROXY_TO_SELF_ACCOUNT); // Create more special accounts while( true ) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 7bba2f3a..824e64ae 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -415,7 +415,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g // specifying the opinions. const account_object& opinion_account = (stake_account.options.voting_account == - account_id_type())? stake_account + GRAPHENE_PROXY_TO_SELF_ACCOUNT)? stake_account : d.get(stake_account.options.voting_account); const auto& stats = stake_account.statistics(d); diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index 38d3db6d..a090eaa7 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -156,4 +156,6 @@ #define GRAPHENE_NULL_ACCOUNT (graphene::chain::account_id_type(3)) /// Represents the canonical account with WILDCARD authority (anybody can access funds in temp account) #define GRAPHENE_TEMP_ACCOUNT (graphene::chain::account_id_type(4)) +/// Represents the canonical account for specifying you will vote directly (as opposed to a proxy) +#define GRAPHENE_PROXY_TO_SELF_ACCOUNT (graphene::chain::account_id_type(5)) ///@} diff --git a/libraries/chain/include/graphene/chain/protocol/account.hpp b/libraries/chain/include/graphene/chain/protocol/account.hpp index 5c0045e3..c68334d6 100644 --- a/libraries/chain/include/graphene/chain/protocol/account.hpp +++ b/libraries/chain/include/graphene/chain/protocol/account.hpp @@ -14,9 +14,10 @@ namespace graphene { namespace chain { /// validated account activities. This field is here to prevent confusion if the active authority has zero or /// multiple keys in it. public_key_type memo_key; - /// If this field is set to an account ID other than 0, this account's votes will be ignored and its stake + /// If this field is set to an account ID other than GRAPHENE_PROXY_TO_SELF_ACCOUNT, + /// then this account's votes will be ignored; its stake /// will be counted as voting for the referenced account's selected votes instead. - account_id_type voting_account; + account_id_type voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; /// The number of active witnesses this account votes the blockchain should appoint /// Must not exceed the actual number of witnesses voted for in @ref votes diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 47aeed33..4b7cc064 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1418,9 +1418,9 @@ public: } else { - if (account_object_to_modify.options.voting_account == account_id_type()) + if (account_object_to_modify.options.voting_account == GRAPHENE_PROXY_TO_SELF_ACCOUNT) FC_THROW("Account ${account} is already voting for itself", ("account", account_to_modify)); - account_object_to_modify.options.voting_account = account_id_type(); + account_object_to_modify.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; } account_update_operation account_update_op; diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 61fb036d..730cb434 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -333,6 +333,7 @@ account_create_operation database_fixture::make_account( create_account.owner = authority(123, key, 123); create_account.active = authority(321, key, 321); create_account.options.memo_key = key; + create_account.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; auto& active_committee_members = db.get_global_properties().active_committee_members; if( active_committee_members.size() > 0 ) @@ -371,6 +372,7 @@ account_create_operation database_fixture::make_account( create_account.owner = authority(123, key, 123); create_account.active = authority(321, key, 321); create_account.options.memo_key = key; + create_account.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; const vector& active_committee_members = db.get_global_properties().active_committee_members; if( active_committee_members.size() > 0 ) @@ -555,6 +557,7 @@ const account_object& database_fixture::create_account( account_create_op.owner = authority(1234, public_key_type(key.get_public_key()), 1234); account_create_op.active = authority(5678, public_key_type(key.get_public_key()), 5678); account_create_op.options.memo_key = key.get_public_key(); + account_create_op.options.voting_account = GRAPHENE_PROXY_TO_SELF_ACCOUNT; trx.operations.push_back( account_create_op ); trx.validate(); diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index c1971142..00eca382 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -345,7 +345,7 @@ BOOST_AUTO_TEST_CASE( create_account_test ) BOOST_CHECK(nathan_account.owner.key_auths.at(committee_key) == 123); BOOST_REQUIRE(nathan_account.active.num_auths() == 1); BOOST_CHECK(nathan_account.active.key_auths.at(committee_key) == 321); - BOOST_CHECK(nathan_account.options.voting_account == account_id_type()); + BOOST_CHECK(nathan_account.options.voting_account == GRAPHENE_PROXY_TO_SELF_ACCOUNT); BOOST_CHECK(nathan_account.options.memo_key == committee_key); const account_statistics_object& statistics = nathan_account.statistics(db);