Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
set_account_permission_subcommand Struct Reference

Public Member Functions

 set_account_permission_subcommand (CLI::App *accountCmd)
 

Public Attributes

string account
 
string permission
 
string authority_json_or_file
 
string parent
 
bool add_code = false
 
bool remove_code = false
 

Detailed Description

Definition at line 847 of file main.cpp.

Constructor & Destructor Documentation

◆ set_account_permission_subcommand()

set_account_permission_subcommand::set_account_permission_subcommand ( CLI::App * accountCmd)
inline

Definition at line 855 of file main.cpp.

855 {
856 auto permissions = accountCmd->add_subcommand("permission", localized("Set parameters dealing with account permissions"));
857 permissions->add_option("account", account, localized("The account to set/delete a permission authority for"))->required();
858 permissions->add_option("permission", permission, localized("The permission name to set/delete an authority for"))->required();
859 permissions->add_option("authority", authority_json_or_file, localized("[delete] NULL, [create/update] public key, JSON string or filename defining the authority, [code] contract name"));
860 permissions->add_option("parent", parent, localized("[create] The permission name of this parents permission, defaults to 'active'"));
861 permissions->add_flag("--add-code", add_code, localized("[code] add '${code}' permission to specified permission authority", ("code", name(config::sysio_code_name))));
862 permissions->add_flag("--remove-code", remove_code, localized("[code] remove '${code}' permission from specified permission authority", ("code", name(config::sysio_code_name))));
863
864 add_standard_transaction_options(permissions, "account@active");
865
866 permissions->callback([this] {
867 SYSC_ASSERT( !(add_code && remove_code), "ERROR: Either --add-code or --remove-code can be set" );
868 SYSC_ASSERT( (add_code ^ remove_code) || !authority_json_or_file.empty(), "ERROR: authority should be specified unless add or remove code permission" );
869
870 authority auth;
871
872 bool need_parent = parent.empty() && (name(permission) != name("owner"));
873 bool need_auth = add_code || remove_code;
874
875 if ( !need_auth && boost::iequals(authority_json_or_file, "null") ) {
876 send_actions( { create_deleteauth(name(account), name(permission)) } );
877 return;
878 }
879
880 if ( need_parent || need_auth ) {
883 auto itr = std::find_if(res.permissions.begin(), res.permissions.end(), [&](const auto& perm) {
884 return perm.perm_name == name(permission);
885 });
886
887 if ( need_parent ) {
888 // see if we can auto-determine the proper parent
889 if ( itr != res.permissions.end() ) {
890 parent = (*itr).parent.to_string();
891 } else {
892 // if this is a new permission and there is no parent we default to "active"
893 parent = config::active_name.to_string();
894 }
895 }
896
897 if ( need_auth ) {
898 auto actor = (authority_json_or_file.empty()) ? name(account) : name(authority_json_or_file);
899 auto code_name = config::sysio_code_name;
900
901 if ( itr != res.permissions.end() ) {
902 // fetch existing authority
903 auth = std::move((*itr).required_auth);
904
905 auto code_perm = permission_level { actor, code_name };
906 auto itr2 = std::lower_bound(auth.accounts.begin(), auth.accounts.end(), code_perm, [&](const auto& perm_level, const auto& value) {
907 return perm_level.permission < value; // Safe since valid authorities must order the permissions in accounts in ascending order
908 });
909
910 if ( add_code ) {
911 if ( itr2 != auth.accounts.end() && itr2->permission == code_perm ) {
912 // authority already contains code permission, promote its weight to satisfy threshold
913 if ( (*itr2).weight < auth.threshold ) {
914 if ( auth.threshold > std::numeric_limits<weight_type>::max() ) {
915 std::cerr << "ERROR: Threshold is too high to be satisfied by sole code permission" << std::endl;
916 return;
917 }
918 std::cerr << localized("The weight of '${actor}@${code}' in '${permission}' permission authority will be increased up to threshold",
919 ("actor", actor)("code", code_name)("permission", permission)) << std::endl;
920 (*itr2).weight = static_cast<weight_type>(auth.threshold);
921 } else {
922 std::cerr << localized("ERROR: The permission '${permission}' already contains '${actor}@${code}'",
923 ("permission", permission)("actor", actor)("code", code_name)) << std::endl;
924 return ;
925 }
926 } else {
927 // add code permission to specified authority
928 if ( auth.threshold > std::numeric_limits<weight_type>::max() ) {
929 std::cerr << "ERROR: Threshold is too high to be satisfied by sole code permission" << std::endl;
930 return;
931 }
932 auth.accounts.insert( itr2, permission_level_weight {
933 .permission = { actor, code_name },
934 .weight = static_cast<weight_type>(auth.threshold)
935 });
936 }
937 } else {
938 if ( itr2 != auth.accounts.end() && itr2->permission == code_perm ) {
939 // remove code permission, if authority becomes empty by the removal of code permission, delete permission
940 auth.accounts.erase( itr2 );
941 if ( auth.keys.empty() && auth.accounts.empty() && auth.waits.empty() ) {
942 send_actions( { create_deleteauth(name(account), name(permission)) } );
943 return;
944 }
945 } else {
946 // authority doesn't contain code permission
947 std::cerr << localized("ERROR: '${actor}@${code}' does not exist in '${permission}' permission authority",
948 ("actor", actor)("code", code_name)("permission", permission)) << std::endl;
949 return;
950 }
951 }
952 } else {
953 if ( add_code ) {
954 // create new permission including code permission
955 auth.threshold = 1;
956 auth.accounts.push_back( permission_level_weight {
957 .permission = { actor, code_name },
958 .weight = 1
959 });
960 } else {
961 // specified permission doesn't exist, so failed to remove code permission from it
962 std::cerr << localized("ERROR: The permission '${permission}' does not exist", ("permission", permission)) << std::endl;
963 return;
964 }
965 }
966 }
967 }
968
969 if ( !need_auth ) {
971 }
972
973 send_actions( { create_updateauth(name(account), name(permission), name(parent), auth) } );
974 });
975 }
std::string name
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
Definition CLI11.hpp:5538
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
Definition CLI11.hpp:5099
CRTP * required(bool value=true)
Set the option as required.
Definition CLI11.hpp:3400
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
return
#define localized(str,...)
Definition localize.hpp:10
uint16_t weight_type
Definition types.hpp:238
const string get_account_func
Definition httpc.hpp:93
#define value
Definition pkcs11.h:157
#define SYSC_ASSERT(TEST,...)
Definition main.cpp:134
chain::action create_updateauth(const name &account, const name &permission, const name &parent, const authority &auth)
Definition main.cpp:772
void add_standard_transaction_options(CLI::App *cmd, string default_permission="")
Definition main.cpp:202
authority parse_json_authority_or_key(const std::string &authorityJsonOrFile)
Definition main.cpp:800
void send_actions(std::vector< chain::action > &&actions, packed_transaction::compression_type compression=packed_transaction::compression_type::none)
Definition main.cpp:616
chain::action create_deleteauth(const name &account, const name &permission)
Definition main.cpp:777
fc::variant call(const std::string &url, const std::string &path, const T &v)
Definition main.cpp:258
vector< wait_weight > waits
vector< permission_level_weight > accounts
vector< key_weight > keys
Immutable except for fc::from_variant.
Definition name.hpp:43
if(ppFunctionList==NULL)
Here is the call graph for this function:

Member Data Documentation

◆ account

string set_account_permission_subcommand::account

Definition at line 848 of file main.cpp.

◆ add_code

bool set_account_permission_subcommand::add_code = false

Definition at line 852 of file main.cpp.

◆ authority_json_or_file

string set_account_permission_subcommand::authority_json_or_file

Definition at line 850 of file main.cpp.

◆ parent

string set_account_permission_subcommand::parent

Definition at line 851 of file main.cpp.

◆ permission

string set_account_permission_subcommand::permission

Definition at line 849 of file main.cpp.

◆ remove_code

bool set_account_permission_subcommand::remove_code = false

Definition at line 853 of file main.cpp.


The documentation for this struct was generated from the following file: