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

feat: add format flag in chain head command #5215

Merged

Conversation

akaladarshi
Copy link
Contributor

@akaladarshi akaladarshi commented Jan 31, 2025

Summary of changes

Changes introduced in this pull request:

  • Adds --format or -f flag to the forest-cli chain head command
  • --format flag accepts json or text value, by default text

Reference issue to close (if applicable)

#4954

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@akaladarshi akaladarshi requested a review from a team as a code owner January 31, 2025 12:03
@akaladarshi akaladarshi requested review from LesnyRumcajs and sudo-shashank and removed request for a team January 31, 2025 12:03
@CLAassistant
Copy link

CLAassistant commented Jan 31, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akaladarshi Thanks for the contribution! In general, looks good. I requested some minor changes.

Also

  1. Pease add sample test to:
    https://github.com/akaladarshi/forest/blob/akaladarshi/add-format-flag/scripts/tests/calibnet_other_check.sh#L32-L34

Something along forest-cli chain head --tipsets 5 --format json | jq to assert valid JSON is produced

  1. Please add an entry to the changelog

Comment on lines 38 to 39
#[arg(short, long, default_value = "text")]
format: Format,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use the short -f here. Typically, it denotes --force or --file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

cids: Vec<String>,
}

async fn collect_tipsets(client: &rpc::Client, n: u64) -> anyhow::Result<Vec<TipsetInfo>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a doc for the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cids: Vec<String>,
}

async fn collect_tipsets(client: &rpc::Client, n: u64) -> anyhow::Result<Vec<TipsetInfo>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async fn collect_tipsets(client: &rpc::Client, n: u64) -> anyhow::Result<Vec<TipsetInfo>> {
async fn collect_n_tipsets(client: &rpc::Client, n: u64) -> anyhow::Result<Vec<TipsetInfo>> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

ensure!(n > 0, "number of tipsets must be positive");
let current_epoch = ChainHead::call(client, ()).await?.epoch() as u64;

let mut result = Vec::with_capacity(n as usize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut result = Vec::with_capacity(n as usize);
let mut tipsets = Vec::with_capacity(n as usize);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


/// Print the first `n` tipsets from the head (inclusive).
async fn print_chain_head(client: &rpc::Client, n: u64, format: Format) -> anyhow::Result<()> {
let result = collect_tipsets(client, n).await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let result = collect_tipsets(client, n).await?;
let tipsets = collect_tipsets(client, n).await?;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 169 to 170
/// Collects `n` tipsets from the head (inclusive) and returns them as a list of
/// `TipsetInfo` objects.
Copy link
Member

@LesnyRumcajs LesnyRumcajs Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have proper Rust doc linking.

Suggested change
/// Collects `n` tipsets from the head (inclusive) and returns them as a list of
/// `TipsetInfo` objects.
/// Collects `n` tipsets from the head (inclusive) and returns them as a list of
/// [`TipsetInfo`] objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Feb 3, 2025
Merged via the queue into ChainSafe:main with commit 2755a80 Feb 3, 2025
41 checks passed
@akaladarshi akaladarshi deleted the akaladarshi/add-format-flag branch February 3, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants