From a744f46415a83b6c1954134d347605dd75cb6d87 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 2 Aug 2017 10:51:16 -0500 Subject: [PATCH] Ref #123: Define types Define the types documented in the issue. TODO: Implement logic --- .../eos/chain/permission_link_object.hpp | 81 +++++++++++++++++++ libraries/chain/include/eos/chain/types.hpp | 3 + libraries/types/types.eos | 6 ++ 3 files changed, 90 insertions(+) create mode 100644 libraries/chain/include/eos/chain/permission_link_object.hpp diff --git a/libraries/chain/include/eos/chain/permission_link_object.hpp b/libraries/chain/include/eos/chain/permission_link_object.hpp new file mode 100644 index 00000000000..ec286b54ad4 --- /dev/null +++ b/libraries/chain/include/eos/chain/permission_link_object.hpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017, Respective Authors. + * + * 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 + +#include "multi_index_includes.hpp" + +namespace eos { namespace chain { + /** + * @brief The permission_link_object class assigns permission_objects to message types + * + * This class records the links from contracts and message types within those contracts to permission_objects + * defined by the user to record the authority required to execute those messages within those contracts. For + * example, suppose we have a contract called "currency" and that contract defines a message called "transfer". + * Furthermore, suppose a user, "joe", has a permission level called "money" and joe would like to require that + * permission level in order for his account to invoke currency.transfer. To do this, joe would create a + * permission_link_object for his account with "currency" as the code account, "transfer" as the message_type, and + * "money" as the required_permission. After this, in order to validate, any message to "currency" of type + * "transfer" that requires joe's approval would require signatures sufficient to satisfy joe's "money" authority. + */ + class permission_link_object : public chainbase::object { + OBJECT_CTOR(permission_link_object) + + id_type id; + AccountName account; + AccountName code; + FuncName message_type; + PermissionName required_permission; + }; + + struct by_message_type; + struct by_permission_name; + using permission_link_index = chainbase::shared_multi_index_container< + permission_link_object, + indexed_by< + ordered_unique, + BOOST_MULTI_INDEX_MEMBER(permission_link_object, permission_link_object::id_type, id) + >, + ordered_unique, + composite_key + >, + ordered_unique, + composite_key + > + > + >; +} } // eos::chain + +CHAINBASE_SET_INDEX_TYPE(eos::chain::permission_link_object, eos::chain::permission_link_index) + +FC_REFLECT(eos::chain::permission_link_object, (id)(account)(code)(message_type)(required_permission)) diff --git a/libraries/chain/include/eos/chain/types.hpp b/libraries/chain/include/eos/chain/types.hpp index 62949e704a7..e1bb51d7387 100644 --- a/libraries/chain/include/eos/chain/types.hpp +++ b/libraries/chain/include/eos/chain/types.hpp @@ -118,6 +118,7 @@ namespace eos { namespace chain { using eos::types::Transaction; using eos::types::PermissionName; using eos::types::TypeName; + using eos::types::FuncName; using eos::types::Time; using eos::types::Field; using eos::types::String; @@ -161,6 +162,7 @@ namespace eos { namespace chain { null_object_type, account_object_type, permission_object_type, + permission_link_object_type, action_code_object_type, key_value_object_type, key128x128_value_object_type, @@ -206,6 +208,7 @@ FC_REFLECT_ENUM(eos::chain::object_type, (null_object_type) (account_object_type) (permission_object_type) + (permission_link_object_type) (action_code_object_type) (key_value_object_type) (key128x128_value_object_type) diff --git a/libraries/types/types.eos b/libraries/types/types.eos index 5c5be6218a8..7cfaefee69a 100644 --- a/libraries/types/types.eos +++ b/libraries/types/types.eos @@ -125,3 +125,9 @@ struct UpdatePermission struct DeletePermission account AccountName permission PermissionName + +struct requirepermission + account AccountName + code AccountName + type FuncName + requirement PermissionName