Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Ref #123: Define types
Browse files Browse the repository at this point in the history
Define the types documented in the issue.

TODO: Implement logic
  • Loading branch information
nathanielhourt committed Aug 3, 2017
1 parent 91b7800 commit a744f46
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
81 changes: 81 additions & 0 deletions libraries/chain/include/eos/chain/permission_link_object.hpp
Original file line number Diff line number Diff line change
@@ -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 <eos/chain/authority.hpp>

#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<permission_link_object_type, permission_link_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<tag<by_id>,
BOOST_MULTI_INDEX_MEMBER(permission_link_object, permission_link_object::id_type, id)
>,
ordered_unique<tag<by_message_type>,
composite_key<permission_link_object,
BOOST_MULTI_INDEX_MEMBER(permission_link_object, AccountName, account),
BOOST_MULTI_INDEX_MEMBER(permission_link_object, AccountName, code),
BOOST_MULTI_INDEX_MEMBER(permission_link_object, FuncName, message_type)
>
>,
ordered_unique<tag<by_permission_name>,
composite_key<permission_link_object,
BOOST_MULTI_INDEX_MEMBER(permission_link_object, AccountName, account),
BOOST_MULTI_INDEX_MEMBER(permission_link_object, PermissionName, required_permission),
BOOST_MULTI_INDEX_MEMBER(permission_link_object, AccountName, code),
BOOST_MULTI_INDEX_MEMBER(permission_link_object, FuncName, message_type)
>
>
>
>;
} } // 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))
3 changes: 3 additions & 0 deletions libraries/chain/include/eos/chain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions libraries/types/types.eos
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,9 @@ struct UpdatePermission
struct DeletePermission
account AccountName
permission PermissionName

struct requirepermission
account AccountName
code AccountName
type FuncName
requirement PermissionName

0 comments on commit a744f46

Please sign in to comment.