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

refactor: various minor improvements #174

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
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
Next Next commit
refactor: pretty print JSON files
  • Loading branch information
samuelvanderwaal committed Aug 10, 2022
commit 0ef74ffcd22044ee6cede2fa8625653faca3c946
5 changes: 1 addition & 4 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Cache {
}

pub fn write<W: Write>(self, writer: W) -> AnyResult<()> {
serde_json::to_writer(writer, &self)?;
serde_json::to_writer_pretty(writer, &self)?;
Ok(())
}

Expand Down Expand Up @@ -162,9 +162,6 @@ pub trait Action {
new_value: args.new_value.clone(),
});

// Increment the counter and update the progress bar.
// pb.inc(1);

// Move the permit into the thread to take ownership of it and then drop it
// when the future is complete.
drop(permit);
Expand Down
2 changes: 1 addition & 1 deletion src/collections/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub async fn check_collection_items(
if debug {
println!("Writing debug file...");
let out = File::create(format!("{collection_mint}-debug-collections.json"))?;
serde_json::to_writer(out, &collections)?;
serde_json::to_writer_pretty(out, &collections)?;
}

// Check if there's the only one and correct collection parent associated with the mint list and that all items in the list belong to it.
Expand Down
2 changes: 1 addition & 1 deletion src/collections/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl MigrateCache {
}

pub fn write<W: Write>(self, writer: W) -> AnyResult<()> {
serde_json::to_writer(writer, &self)?;
serde_json::to_writer_pretty(writer, &self)?;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn decode_metadata_all(
};

debug!("Writing to file for mint account: {}", mint_account);
match serde_json::to_writer(&mut file, &json_metadata) {
match serde_json::to_writer_pretty(&mut file, &json_metadata) {
Ok(_) => (),
Err(err) => {
error!(
Expand Down Expand Up @@ -161,7 +161,7 @@ pub fn decode_metadata(
let metadata = decode(client, mint_account)?;
let json_metadata = decode_to_json(metadata, full)?;
let mut file = File::create(format!("{}/{}.json", output, mint_account))?;
serde_json::to_writer(&mut file, &json_metadata)?;
serde_json::to_writer_pretty(&mut file, &json_metadata)?;
} else if let Some(list_path) = list_path {
decode_metadata_all(client, list_path, full, output)?;
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/snapshot/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn snapshot_mints(client: &RpcClient, args: SnapshotMintsArgs) -> Result<()>
)?;

let mut file = File::create(format!("{}/{}_mint_accounts.json", args.output, prefix))?;
serde_json::to_writer(&mut file, &mint_accounts)?;
serde_json::to_writer_pretty(&mut file, &mint_accounts)?;

Ok(())
}
Expand Down Expand Up @@ -68,7 +68,7 @@ pub async fn snapshot_indexed_mints(
}

let mut file = File::create(format!("{output}/{creator}_mint_accounts.json"))?;
serde_json::to_writer(&mut file, &mint_addresses)?;
serde_json::to_writer_pretty(&mut file, &mint_addresses)?;

Ok(())
}
Expand Down Expand Up @@ -258,7 +258,7 @@ pub fn snapshot_holders(
};

let mut file = File::create(format!("{}/{}_holders.json", output, prefix))?;
serde_json::to_writer(&mut file, &nft_holders)?;
serde_json::to_writer_pretty(&mut file, &nft_holders)?;

Ok(())
}
Expand Down Expand Up @@ -319,15 +319,15 @@ pub async fn snapshot_indexed_holders(
.map(|e| e.to_string())
.collect::<Vec<_>>();
let f = File::create(format!("{}/{}_errors.json", output, creator))?;
serde_json::to_writer(&f, &errors)?;
serde_json::to_writer_pretty(&f, &errors)?;
}

// Unwrap sucessful
let nft_holders: Vec<Holder> = successful_results.into_iter().map(Result::unwrap).collect();
println!("Found {} holders", nft_holders.len());

let mut file = File::create(format!("{output}/{creator}_holders.json"))?;
serde_json::to_writer(&mut file, &nft_holders)?;
serde_json::to_writer_pretty(&mut file, &nft_holders)?;

Ok(())
}
Expand Down Expand Up @@ -511,7 +511,7 @@ pub fn snapshot_cm_accounts(
};

let mut file = File::create(format!("{}/{}_accounts.json", output, update_authority))?;
serde_json::to_writer(&mut file, &candy_machine_program_accounts)?;
serde_json::to_writer_pretty(&mut file, &candy_machine_program_accounts)?;

Ok(())
}
Expand Down