Skip to content

Commit

Permalink
Update to latest GraphQL Client version
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-mysten committed Oct 23, 2024
1 parent 4d8c762 commit 077965a
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 111 deletions.
8 changes: 4 additions & 4 deletions mvr-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mvr-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ name = "unit_tests"
path = "src/tests/unit_tests.rs"

[dependencies]
sui-types = { git = "https://github.com/mystenlabs/sui-rust-sdk", package = "sui-sdk-types", branch = "dynamic_fields" }
sui-client = { git = "https://github.com/mystenlabs/sui-rust-sdk", package = "sui-graphql-client", branch = "dynamic_fields" }
sui-types = { git = "https://github.com/mystenlabs/sui-rust-sdk", package = "sui-sdk-types", rev="3b9ee9bee52f0ee20c104f231e9bf49f2ea063e5" }
sui-client = { git = "https://github.com/mystenlabs/sui-rust-sdk", package = "sui-graphql-client", rev="3b9ee9bee52f0ee20c104f231e9bf49f2ea063e5" }

anyhow = "1.0"
clap = { version = "4.5", features = ["derive"] }
Expand Down
209 changes: 104 additions & 105 deletions mvr-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod commands;
pub mod helpers;
pub use commands::Command as CliCommand;
pub use commands::CommandOutput;
use sui_client::PaginationFilter;

use crate::commands::App;
use helpers::sui::force_build;
Expand Down Expand Up @@ -367,49 +368,44 @@ async fn resolve_on_chain_package_info(
let mut cursor = None;
let mut resolved_packages: HashMap<String, PackageInfo> = HashMap::new();
loop {
let dynamic_fields = mainnet_client
// .dynamic_fields(
let page = mainnet_client
.dynamic_fields(
Address::from_str(&app_registry_id.to_string())?,
cursor,
None,
None,
None,
PaginationFilter {
cursor: cursor.clone(),
..Default::default()
},
)
.await?;

if let Some(page) = dynamic_fields {
for dynamic_field_info in page.data().into_iter() {
let name = get_normalized_app_name_gql(&dynamic_field_info)?;
if package_set.contains(&name) {
if let Some(package_info) =
get_package_info_gql(&dynamic_field_info, client, network).await?
{
if let Some(full_name) = package_name_map.get(&name) {
resolved_packages.insert(full_name.clone(), package_info);
} else {
// Invariant: should never happen: package_set and package_name_map are set up in sync
eprintln!("Warning: Found package in set but not in map: {}", name);
}
for dynamic_field_info in page.data().into_iter() {
let name = get_normalized_app_name_gql(&dynamic_field_info)?;
if package_set.contains(&name) {
if let Some(package_info) =
get_package_info_gql(&dynamic_field_info, client, network).await?
{
if let Some(full_name) = package_name_map.get(&name) {
resolved_packages.insert(full_name.clone(), package_info);
} else {
bail!(
"{} {} {} {} {}",
"No on-chain PackageInfo for package".red(),
name.red().bold(),
"on".red(),
dependency.network.red().bold(),
"(it may not be registered).".red()
);
// Invariant: should never happen: package_set and package_name_map are set up in sync
eprintln!("Warning: Found package in set but not in map: {}", name);
}
} else {
bail!(
"{} {} {} {} {}",
"No on-chain PackageInfo for package".red(),
name.red().bold(),
"on".red(),
dependency.network.red().bold(),
"(it may not be registered).".red()
);
}
}
if !page.page_info().has_next_page {
break;
}
cursor = page.page_info().end_cursor.clone();
} else {
}
if !page.page_info().has_next_page {
break;
}
cursor = page.page_info().end_cursor.clone();
}

let resolved_on_chain: HashSet<String> = resolved_packages.keys().cloned().collect();
Expand Down Expand Up @@ -874,26 +870,27 @@ async fn get_git_versioning_gql(
let git_versioning_id = get_git_versioning_id_gql(package_info.as_ref())?;
let mut result = HashMap::new();

let mut after = None;
let mut cursor = None;
loop {
let dynamic_fields = client
.dynamic_fields(*git_versioning_id.as_address(), after, None, None, None)
let page = client
.dynamic_fields(
*git_versioning_id.as_address(),
PaginationFilter {
cursor: cursor.clone(),
..Default::default()
},
)
.await?;

if let Some(page) = dynamic_fields {
for dynamic_field_info in page.data().iter() {
let index = extract_index_gql(&dynamic_field_info)?;
let git_info = extract_git_info_gql(&dynamic_field_info)?;
result.insert(index, git_info);
}
if page.page_info().has_next_page {
after = page.page_info().end_cursor.clone();
} else {
break;
}
} else {
for dynamic_field_info in page.data().iter() {
let index = extract_index_gql(&dynamic_field_info)?;
let git_info = extract_git_info_gql(&dynamic_field_info)?;
result.insert(index, git_info);
}
if !page.page_info().has_next_page {
break;
}
cursor = page.page_info().end_cursor.clone();
}

Ok(result)
Expand Down Expand Up @@ -1247,29 +1244,47 @@ pub async fn subcommand_list(filter: Option<String>) -> Result<CommandOutput> {
.into();
let mut after = None;
loop {
let dfs = mainnet_client
.dynamic_fields(address, after, None, Some(10), None)
let page = mainnet_client
.dynamic_fields(
address,
PaginationFilter {
cursor: after.clone(),
..Default::default()
},
)
.await?;
if let Some(dfs) = dfs.as_ref() {
for dynamic_field_info in dfs.data().iter() {
let name = get_normalized_app_name_gql(&dynamic_field_info)?;
let pkg_testnet = get_package_info_gql(
&dynamic_field_info,
&testnet_client,
&PackageInfoNetwork::Testnet,
)
.await
.unwrap_or(None);
let pkg_mainnet = get_package_info_gql(
&dynamic_field_info,
&mainnet_client,
&PackageInfoNetwork::Mainnet,
)
.await
.unwrap_or(None);
if let Some(ref filter) = filter {
if is_name(filter) {
if &name == filter {
for dynamic_field_info in page.data().iter() {
let name = get_normalized_app_name_gql(&dynamic_field_info)?;
let pkg_testnet = get_package_info_gql(
&dynamic_field_info,
&testnet_client,
&PackageInfoNetwork::Testnet,
)
.await
.unwrap_or(None);
let pkg_mainnet = get_package_info_gql(
&dynamic_field_info,
&mainnet_client,
&PackageInfoNetwork::Mainnet,
)
.await
.unwrap_or(None);
if let Some(ref filter) = filter {
if is_name(filter) {
if &name == filter {
return Ok(CommandOutput::List(vec![App {
name: name.clone(),
package_info: vec![
(PackageInfoNetwork::Testnet, pkg_testnet),
(PackageInfoNetwork::Mainnet, pkg_mainnet),
],
}]));
}
}
// it is an address
else {
if let Some(ref pkg) = pkg_testnet {
if &pkg.package_address.to_string() == filter {
return Ok(CommandOutput::List(vec![App {
name: name.clone(),
package_info: vec![
Expand All @@ -1279,48 +1294,32 @@ pub async fn subcommand_list(filter: Option<String>) -> Result<CommandOutput> {
}]));
}
}
// it is an address
else {
if let Some(ref pkg) = pkg_testnet {
if &pkg.package_address.to_string() == filter {
return Ok(CommandOutput::List(vec![App {
name: name.clone(),
package_info: vec![
(PackageInfoNetwork::Testnet, pkg_testnet),
(PackageInfoNetwork::Mainnet, pkg_mainnet),
],
}]));
}
}
if let Some(ref pkg) = pkg_mainnet {
if &pkg.package_address.to_string() == filter {
return Ok(CommandOutput::List(vec![App {
name: name.clone(),
package_info: vec![
(PackageInfoNetwork::Testnet, pkg_testnet),
(PackageInfoNetwork::Mainnet, pkg_mainnet),
],
}]));
}
if let Some(ref pkg) = pkg_mainnet {
if &pkg.package_address.to_string() == filter {
return Ok(CommandOutput::List(vec![App {
name: name.clone(),
package_info: vec![
(PackageInfoNetwork::Testnet, pkg_testnet),
(PackageInfoNetwork::Mainnet, pkg_mainnet),
],
}]));
}
}
}
let app = App {
name: name.clone(),
package_info: vec![
(PackageInfoNetwork::Testnet, pkg_testnet),
(PackageInfoNetwork::Mainnet, pkg_mainnet),
],
};
output.push(app);
}
after = dfs.page_info().end_cursor.clone();
if after.is_none() {
break;
}
} else {
let app = App {
name: name.clone(),
package_info: vec![
(PackageInfoNetwork::Testnet, pkg_testnet),
(PackageInfoNetwork::Mainnet, pkg_mainnet),
],
};
output.push(app);
}
if after.is_none() {
break;
}
after = page.page_info().end_cursor.clone();
}
if filter.is_some() {
Ok(CommandOutput::List(vec![]))
Expand Down

0 comments on commit 077965a

Please sign in to comment.