Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom authorities #1362

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f087234
Add basic files for custom authority feature
abitmore Aug 5, 2018
a479a7e
Add protocol/custom_authority.cpp
abitmore Aug 11, 2018
79f2dab
Remove commented out list_arg visitor code
abitmore Aug 11, 2018
f697801
Refactor operation visiting
abitmore Aug 11, 2018
1e4245d
Change validate_by_member_type arg type to pointer
abitmore Aug 11, 2018
7aa5fb8
Member_validate_visitor: avoid nullptr dereference
abitmore Aug 11, 2018
2e97fde
Visit operation members by index directly
abitmore Aug 11, 2018
4c818ea
Update validation of simple data type as argument
abitmore Aug 11, 2018
ea9cf64
Add func_attr validation
abitmore Aug 11, 2018
3f2f9d7
Code cleanup: remove code that is commented out
abitmore Aug 11, 2018
c5b1d42
Add comments for static_variant<> argument_type
abitmore Aug 11, 2018
0cf5edb
Update units calculation
abitmore Aug 12, 2018
0133291
Refactory: move restriction to new file and rename
abitmore Aug 12, 2018
6642974
Refactory: move restriction impl to new file
abitmore Aug 12, 2018
786cdec
Refactory: change function names
abitmore Aug 12, 2018
ae59f39
Refactor templates and fix comments/typo
abitmore Aug 12, 2018
02b0c89
Refactory: rename visitors
abitmore Aug 12, 2018
7439058
Refactory: rename variables
abitmore Aug 12, 2018
7793f2d
Refactory: rename restriction_type to restriction
abitmore Aug 12, 2018
4095bc5
Add reflection for custom_authority_create_op
abitmore Aug 12, 2018
f35f6ee
Basic impl of custom_authority_create_evaluator
abitmore Aug 12, 2018
dbc8a76
Temporarily update FC to for-cust-auth branch
abitmore Oct 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ endif( GRAPHENE_DISABLE_UNITY_BUILD )
## SORT .cpp by most likely to change / break compile
add_library( graphene_chain

protocol/restriction.cpp
protocol/custom_authority.cpp
# As database takes the longest to compile, start it first
${GRAPHENE_DB_FILES}
fork_database.cpp
Expand Down Expand Up @@ -80,6 +82,7 @@ add_library( graphene_chain
confidential_evaluator.cpp
special_authority.cpp
buyback.cpp
custom_authority_evaluator.cpp

account_object.cpp
asset_object.cpp
Expand Down
116 changes: 116 additions & 0 deletions libraries/chain/custom_authority_evaluator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (c) 2018 Abit More, and contributors.
*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <graphene/chain/custom_authority_evaluator.hpp>
#include <graphene/chain/custom_authority_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/hardfork.hpp>

namespace graphene { namespace chain {

void_result custom_authority_create_evaluator::do_evaluate(const custom_authority_create_operation& op)
{ try {
const database& d = db();

// account is fee payer so should be valid

// custom_id should be unique per account

// valid_from ?
// valid_to should not be too far in the future

// operation_type HF check

// if there is an account in auth, need to be valid

// restrictions size check? global limitation?

// how many custom authorities per account?

/*
asset fee;
account_id_type account;
uint32_t custom_id;
bool enabled;
time_point_sec valid_from;
time_point_sec valid_to;
unsigned_int operation_type;
authority auth;
vector<restriction> restrictions;

empty_extensions_type extensions;
*/

return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

object_id_type custom_authority_create_evaluator::do_apply(const custom_authority_create_operation& op)
{ try {
database& d = db();

const auto& new_object = d.create<custom_authority_object>( [&op]( custom_authority_object& obj ){
obj.account = op.account;
obj.custom_id = op.custom_id;
obj.enabled = op.enabled;
obj.valid_from = op.valid_from;
obj.valid_to = op.valid_to;
obj.operation_type = op.operation_type;
obj.auth = op.auth;
obj.restrictions = op.restrictions;
});

return new_object.id;

} FC_CAPTURE_AND_RETHROW( (op) ) }

void_result custom_authority_update_evaluator::do_evaluate(const custom_authority_update_operation& op)
{ try {
const database& d = db();

return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

void_result custom_authority_update_evaluator::do_apply(const custom_authority_update_operation& op)
{ try {
database& d = db();

return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

void_result custom_authority_delete_evaluator::do_evaluate(const custom_authority_delete_operation& op)
{ try {
const database& d = db();

return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

void_result custom_authority_delete_evaluator::do_apply(const custom_authority_delete_operation& op)
{ try {
database& d = db();

return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

} } // graphene::chain
6 changes: 6 additions & 0 deletions libraries/chain/db_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <graphene/chain/chain_property_object.hpp>
#include <graphene/chain/committee_member_object.hpp>
#include <graphene/chain/confidential_object.hpp>
#include <graphene/chain/custom_authority_object.hpp>
#include <graphene/chain/fba_object.hpp>
#include <graphene/chain/global_property_object.hpp>
#include <graphene/chain/market_object.hpp>
Expand All @@ -53,6 +54,7 @@
#include <graphene/chain/committee_member_evaluator.hpp>
#include <graphene/chain/confidential_evaluator.hpp>
#include <graphene/chain/custom_evaluator.hpp>
#include <graphene/chain/custom_authority_evaluator.hpp>
#include <graphene/chain/market_evaluator.hpp>
#include <graphene/chain/proposal_evaluator.hpp>
#include <graphene/chain/transfer_evaluator.hpp>
Expand Down Expand Up @@ -173,6 +175,9 @@ void database::initialize_evaluators()
register_evaluator<asset_claim_fees_evaluator>();
register_evaluator<asset_update_issuer_evaluator>();
register_evaluator<asset_claim_pool_evaluator>();
register_evaluator<custom_authority_create_evaluator>();
register_evaluator<custom_authority_update_evaluator>();
register_evaluator<custom_authority_delete_evaluator>();
}

void database::initialize_indexes()
Expand Down Expand Up @@ -216,6 +221,7 @@ void database::initialize_indexes()
add_index< primary_index< special_authority_index > >();
add_index< primary_index< buyback_index > >();
add_index< primary_index<collateral_bid_index > >();
add_index< primary_index<custom_authority_index > >();

add_index< primary_index< simple_index< fba_accumulator_object > > >();
}
Expand Down
19 changes: 19 additions & 0 deletions libraries/chain/db_notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ struct get_impacted_account_visitor
{
_impacted.insert( op.fee_payer() ); // account_id
}
void operator()( const custom_authority_create_operation& op )
{
_impacted.insert( op.fee_payer() ); // account
add_authority_accounts( _impacted, op.auth );
}
void operator()( const custom_authority_update_operation& op )
{
_impacted.insert( op.fee_payer() ); // account
}
void operator()( const custom_authority_delete_operation& op )
{
_impacted.insert( op.fee_payer() ); // account
}
};

void graphene::chain::operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
Expand Down Expand Up @@ -406,6 +419,12 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
FC_ASSERT( aobj != nullptr );
accounts.insert( aobj->bidder );
break;
} case impl_custom_authority_object_type:{
const auto& aobj = dynamic_cast<const custom_authority_object*>(obj);
FC_ASSERT( aobj != nullptr );
accounts.insert( aobj->account );
add_authority_accounts( accounts, aobj->auth );
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2018 Abit More, and contributors.
*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once

#include <graphene/chain/evaluator.hpp>

namespace graphene { namespace chain {

class custom_authority_create_evaluator : public evaluator<custom_authority_create_evaluator>
{
public:
typedef custom_authority_create_operation operation_type;

void_result do_evaluate( const operation_type& op );
object_id_type do_apply( const operation_type& op );
};

class custom_authority_update_evaluator : public evaluator<custom_authority_update_evaluator>
{
public:
typedef custom_authority_update_operation operation_type;

void_result do_evaluate( const operation_type& op );
void_result do_apply( const operation_type& op );
};

class custom_authority_delete_evaluator : public evaluator<custom_authority_delete_evaluator>
{
public:
typedef custom_authority_delete_operation operation_type;

void_result do_evaluate( const operation_type& op );
void_result do_apply( const operation_type& op );
};

} } // graphene::chain
89 changes: 89 additions & 0 deletions libraries/chain/include/graphene/chain/custom_authority_object.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2018 Abit More, and contributors.
*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include <graphene/chain/protocol/authority.hpp>
#include <graphene/chain/protocol/custom_authority.hpp>
#include <graphene/db/generic_index.hpp>
#include <boost/multi_index/composite_key.hpp>

namespace graphene { namespace chain {

/**
* @brief Tracks account custom authorities
* @ingroup object
*
*/
class custom_authority_object : public abstract_object<custom_authority_object>
{
public:
static const uint8_t space_id = implementation_ids;
static const uint8_t type_id = impl_custom_authority_object_type;

account_id_type account;
uint32_t custom_id;
bool enabled;
time_point_sec valid_from;
time_point_sec valid_to;
unsigned_int operation_type;
authority auth;
vector<restriction> restrictions;
};

struct by_account_custom;

/**
* @ingroup object_index
*/
typedef multi_index_container<
custom_authority_object,
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_account_custom>,
composite_key<
custom_authority_object,
member<custom_authority_object, account_id_type, &custom_authority_object::account>,
member<custom_authority_object, uint32_t, &custom_authority_object::custom_id>
>
>
>
> custom_authority_multi_index_type;

/**
* @ingroup object_index
*/
typedef generic_index<custom_authority_object, custom_authority_multi_index_type> custom_authority_index;

} } // graphene::chain

FC_REFLECT_DERIVED( graphene::chain::custom_authority_object,
(graphene::db::object),
(account)
(custom_id)
(enabled)
(valid_from)
(valid_to)
(operation_type)
(auth)
(restrictions)
)
Loading