This Rust project fetches validator delegations from a Cosmos-based blockchain (specifically Coreum, but should work with any Cosmos SDK chain) using gRPC and exports the data to a CSV file.
- Connects to a Coreum full node using gRPC
- Fetches validator delegations for a specific validator
- Exports delegation data to a CSV file
- Error handling using custom
AppError
enum - Asynchronous operations with Tokio runtime
- Rust (latest stable version)
- Cargo (comes with Rust)
-
Clone the repository:
git clone https://github.com/elix1er/rustgrpc-cosmos-delegations.git cd rustgrpc-cosmos-delegations
-
Build the project:
cargo build --release
Run the compiled binary:
./target/release/rustgrpc-cosmos-delegations
Or - just run cargo run
to build and run the project.
The program will:
- Connect to the Coreum full node
- Fetch validator delegations
- Create a CSV file in the
output
directory namedvalidator_delegations.csv
The validator address is currently hardcoded in the fetch_validator_delegations
function.
To change the validator address, modify this line before compiling.
src/main.rs
: Contains the main logic for fetching delegations and creating the CSV file
tonic
: gRPC clienttokio
: Asynchronous runtimecosmos-sdk-proto
: Cosmos SDK protobuf definitionscsv
: CSV file creationthiserror
: Error handling
Run the tests using:
cargo test
The test_fetch_validator_delegations
function in src/tests.rs
tests the main functionality of fetching validator delegations.
Contributions are welcome! Please feel free to submit a Pull Request.