Skip to content

Commit

Permalink
Merge pull request #696 from eosnetworkfoundation/cleos_sort_keys
Browse files Browse the repository at this point in the history
[3.2] cleos sorts keys/permission_levels/waits for "cleos set account permission
  • Loading branch information
ClaytonCalabrese authored Jul 20, 2022
2 parents 6a4e948 + c061f0a commit 94a9fb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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 @@ -835,6 +835,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

0 comments on commit 94a9fb8

Please sign in to comment.