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

[3.2] cleos sorts keys/permission_levels/waits for "cleos set account permission #696

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions libraries/chain/include/eosio/chain/authority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ struct permission_level_weight {
friend bool operator == ( const permission_level_weight& lhs, const permission_level_weight& rhs ) {
return tie( lhs.permission, lhs.weight ) == tie( rhs.permission, rhs.weight );
}

friend bool operator < ( const permission_level_weight& lhs, const permission_level_weight& rhs ) {
return tie( lhs.permission, lhs.weight ) < tie( rhs.permission, rhs.weight );
}
};

struct key_weight {
Expand All @@ -93,6 +97,10 @@ struct key_weight {
friend bool operator == ( const key_weight& lhs, const key_weight& rhs ) {
return tie( lhs.key, lhs.weight ) == tie( rhs.key, rhs.weight );
}

friend bool operator < ( const key_weight& lhs, const key_weight& rhs ) {
return tie( lhs.key, lhs.weight ) < tie( rhs.key, rhs.weight );
}
};


Expand Down Expand Up @@ -137,6 +145,10 @@ struct wait_weight {
friend bool operator == ( const wait_weight& lhs, const wait_weight& rhs ) {
return tie( lhs.wait_sec, lhs.weight ) == tie( rhs.wait_sec, rhs.weight );
}

friend bool operator < ( const wait_weight& lhs, const wait_weight& rhs ) {
return tie( lhs.wait_sec, lhs.weight ) < tie( rhs.wait_sec, rhs.weight );
}
};

namespace config {
Expand Down Expand Up @@ -191,6 +203,12 @@ struct authority {
friend bool operator != ( const authority& lhs, const authority& rhs ) {
return tie( lhs.threshold, lhs.keys, lhs.accounts, lhs.waits ) != tie( rhs.threshold, rhs.keys, rhs.accounts, rhs.waits );
}

void sort_fields () {
std::sort(std::begin(keys), std::end(keys));
std::sort(std::begin(accounts), std::end(accounts));
std::sort(std::begin(waits), std::end(waits));
}
};


Expand Down
1 change: 1 addition & 0 deletions programs/cleos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ authority parse_json_authority_or_key(const std::string& authorityJsonOrFile) {
} EOS_RETHROW_EXCEPTIONS(public_key_type_exception, "Invalid public key: ${public_key}", ("public_key", authorityJsonOrFile))
} else {
auto result = parse_json_authority(authorityJsonOrFile);
result.sort_fields();
EOS_ASSERT( eosio::chain::validate(result), authority_type_exception, "Authority failed validation! ensure that keys, accounts, and waits are sorted and that the threshold is valid and satisfiable!");
return result;
}
Expand Down