Skip to content

Add get chain-id command - #4605

Open
snickerdoodle2 wants to merge 6 commits into
masterfrom
feat/4597-get-chain-id
Open

snickerdoodle2 wants to merge 6 commits into
masterfrom
feat/4597-get-chain-id

Conversation

@snickerdoodle2

Copy link
Copy Markdown
Contributor

Closes #4597

Introduced changes

Added command to display chain's ID.

Plain output

Success: Chain ID retrieved

Chain ID:   0x534e5f5345504f4c4941
Chain Name: SN_SEPOLIA

JSON output

{
  "chain_id": "0x534e5f5345504f4c4941",
  "chain_name": "SN_SEPOLIA",
  "command": "get chain-id",
  "type": "response"
}

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

Comment on lines +34 to +37
let chain_id = provider
.chain_id()
.await
.map_err(|err| StarknetCommandError::ProviderError(err.into()))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's use existing get_chain_id function here

* [balance](./sncast/get/balance.md)
* [block](./sncast/get/block.md)
* [class-hash-at](./sncast/get/class_hash_at.md)
* [chain-id](./sncast/get/chain_id.md)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Put it above class-hash-at for alphabetical order

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: It can be renamed to chain-id.md

Comment on lines +21 to +25
let builder = if let Some(name) = &self.chain_name {
builder.field("Chain Name", name)
} else {
builder
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It can be replaced by OutputBuilder.if_some() call

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add a test for result 0x0

Comment on lines +27 to +28
let stdout = output.get_output().stdout.clone();
let json: serde_json::Value = serde_json::from_slice(&stdout).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
let stdout = output.get_output().stdout.clone();
let json: serde_json::Value = serde_json::from_slice(&stdout).unwrap();
let json: serde_json::Value = serde_json::from_slice(&output.get_output().stdout).unwrap();

This branch has not been deployed

No deployments
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.

Add command to get chain id

2 participants