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

[rpc] Get protocol config endpoint #11510

Merged
merged 8 commits into from
May 5, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
lookup prot cfg by string
  • Loading branch information
oxade committed Apr 29, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 859edc2eb71ab16c3d830704d0f41829f30e072a
6 changes: 3 additions & 3 deletions crates/sui-protocol-config-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -130,17 +130,17 @@ pub fn getters_macro(input: TokenStream) -> TokenStream {
#(#getters)*

/// Lookup a config attribute by its string representation
pub fn lookup_value(&self, value: String) -> Option<String> {
pub fn lookup_attr(&self, value: String) -> Option<String> {
match value.as_str() {
#(#value_lookup)*
_ => None,
}
}

/// Get a map of all config attribute string representations to their string values
pub fn value_map(&self) -> std::collections::BTreeMap<String, Option<String>> {
pub fn attr_map(&self) -> std::collections::BTreeMap<String, Option<String>> {
vec![
#(((#field_names_str).to_owned(), self.lookup_value((#field_names_str).to_owned())),)*
#(((#field_names_str).to_owned(), self.lookup_attr((#field_names_str).to_owned())),)*
].into_iter().collect()
}

10 changes: 5 additions & 5 deletions crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1294,32 +1294,32 @@ mod test {
fn lookup_by_string_test() {
let prot: ProtocolConfig = ProtocolConfig::get_for_version(ProtocolVersion::new(1));
assert!(
prot.lookup_value("max_arguments".to_string())
prot.lookup_attr("max_arguments".to_string())
== Some(format!("{}", prot.max_arguments()))
);

// We didnt have this in version 1
assert!(prot
.lookup_value("max_move_identifier_len".to_string())
.lookup_attr("max_move_identifier_len".to_string())
.is_none());

// But we did in version 9
let prot: ProtocolConfig = ProtocolConfig::get_for_version(ProtocolVersion::new(9));
assert!(
prot.lookup_value("max_move_identifier_len".to_string())
prot.lookup_attr("max_move_identifier_len".to_string())
== Some(format!("{}", prot.max_move_identifier_len()))
);

let prot: ProtocolConfig = ProtocolConfig::get_for_version(ProtocolVersion::new(1));
// We didnt have this in version 1
assert!(prot
.value_map()
.attr_map()
.get("max_move_identifier_len")
.unwrap()
.is_none());
// We had this in version 1
assert!(
prot.value_map().get("max_arguments").unwrap()
prot.attr_map().get("max_arguments").unwrap()
== &Some(format!("{}", prot.max_arguments()))
);
}