Skip to content

Commit

Permalink
update rs/README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
amirylm committed Nov 3, 2024
1 parent d0e2e48 commit faf5e8f
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,51 @@

This folder contains the Rust implementation of the Chain Selectors module.

## Pre-requisites
## Installation

```shell
cargo add --git https://github.com/smartcontractkit/chain-selectors --tag <TAG>
```

## Usage

```rust
use std::str::FromStr;
use chainselectors::generated_chains;

fn main() {
match generated_chains::ChainName::try_from(420) {
Ok(c) => {
assert_eq!(c, generated_chains::ChainName::EthereumTestnetGoerliOptimism1);
}
Err(_) => {
panic!("Failed to convert chain id to chain name");
}
}

let selector = generated_chains::chain_selector(generated_chains::ChainName::EthereumTestnetGoerliOptimism1);
assert_eq!(
selector,
2664363617261496610,
);

match generated_chains::ChainName::from_str("ethereum-testnet-goerli-optimism-1") {
Ok(chain) => {
assert_eq!(chain, generated_chains::ChainName::EthereumTestnetGoerliOptimism1);
}
Err(_) => {
panic!("Failed to parse chain name");
}
}
}
```

## Dev Guide

### Pre-requisites

As part of the code generation, `rustfmt` is used to format the generated code. If you don't have rust toolchain installed, it will run in docker.

## Build
### Build

To build the Chain Selectors module, run the `go generate ./rs` from the root of the project.
To build the Chain Selectors module, run the `go generate ./rs` from the root of the project, or `go generate ./...` to generate all modules (not just rust).

0 comments on commit faf5e8f

Please sign in to comment.