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

Initial SDK implementation #1

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[package]
name = "rust-sdk"
version = "0.1.0"
name = "maestro"
version = "1.0.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
license = "Apache-2.0"

[dependencies]
reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
366 changes: 183 additions & 183 deletions LICENSE

Large diffs are not rendered by default.

201 changes: 0 additions & 201 deletions LICENSE copy

This file was deleted.

38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
# Getting Started

## Prerequisites
* [Rust](https://www.rust-lang.org/tools/install)
* [Clippy](https://github.com/rust-lang/rust-clippy)
* [Audit](https://docs.rs/cargo-audit/latest/cargo_audit/)

- [Rust](https://www.rust-lang.org/tools/install)
- [Clippy](https://github.com/rust-lang/rust-clippy)
- [Audit](https://docs.rs/cargo-audit/latest/cargo_audit/)

## Installation

Expand All @@ -45,22 +46,43 @@

## Usage
adamped marked this conversation as resolved.
Show resolved Hide resolved

```toml
[dependencies]
maestro = { git = "https://github.com/maestro-org/rust-sdk.git" }
```

```rust
// TODO
use maestro::Maestro;

let maestro_client = Maestro::new("<PROJECT_API_KEY>", "<NETWORK>")
```

* To generate an API key, create a free account [here](https://dashboard.gomaestro.org/)!
* Network options: `mainnet`, `preprod`, `preview`
- To generate an API key, create a free account [here](https://dashboard.gomaestro.org/)!
- Network options: `mainnet`, `preprod`, `preview`

## Example

```rust
// TODO
use maestro::Maestro;

#[tokio::main]
async fn main() {
let maestro_client = Maestro::new(
String::from("<PROJECT_API_KEY>"),
String::from("<NETWORK>"),
);

match maestro_client.block_info(9005859).await {
Ok(block_info) => println!("{}", block_info.data.absolute_slot),
Err(e) => eprint!("Failed to retrieve block info {}", e),
}
}
```

# Documentation

* [Maestro public docs](https://docs.gomaestro.org/)
- [Maestro public docs](https://docs.gomaestro.org/)

# Contributing

Meastro welcomes all contributors! Please see our [contributing guidelines](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md).
87 changes: 87 additions & 0 deletions src/client/accounts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use super::maestro::Maestro;
use crate::{
models::accounts::{
AccountAddresses, AccountAssets, StakeAccountHistory, StakeAccountInformation,
StakeAccountRewards, StakeAccountUpdates,
},
utils::Parameters,
};
use std::error::Error;

impl Maestro {
pub async fn account_addresses(
&self,
stake_addr: &str,
params: Option<Parameters>,
) -> Result<AccountAddresses, Box<dyn Error>> {
let formatted_params = params.map(|p| p.format()).unwrap_or_default();
let url = format!("/accounts/{}/addresses{}", stake_addr, formatted_params);
let resp = self.get(&url).await?;
let account_addresses =
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)?;
Ok(account_addresses)
}

pub async fn account_assets(
&self,
stake_addr: &str,
params: Option<Parameters>,
) -> Result<AccountAssets, Box<dyn Error>> {
let formatted_params = params.map(|p| p.format()).unwrap_or_default();
let url = format!("/accounts/{}/assets{}", stake_addr, formatted_params);
let resp = self.get(&url).await?;
let account_assets =
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)?;
Ok(account_assets)
}

pub async fn stake_account_history(
&self,
stake_addr: &str,
params: Option<Parameters>,
) -> Result<StakeAccountHistory, Box<dyn Error>> {
let formatted_params = params.map(|p| p.format()).unwrap_or_default();
let url = format!("/accounts/{}/history{}", stake_addr, formatted_params);
let resp = self.get(&url).await?;
let stake_account_history =
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)?;
Ok(stake_account_history)
}

pub async fn stake_account_information(
&self,
stake_addr: &str,
) -> Result<StakeAccountInformation, Box<dyn Error>> {
let url = format!("/accounts/{}", stake_addr);
let resp = self.get(&url).await?;
let stake_account_information =
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)?;
Ok(stake_account_information)
}

pub async fn stake_account_rewards(
&self,
stake_addr: &str,
params: Option<Parameters>,
) -> Result<StakeAccountRewards, Box<dyn Error>> {
let formatted_params = params.map(|p| p.format()).unwrap_or_default();
let url = format!("/accounts/{}/rewards{}", stake_addr, formatted_params);
let resp = self.get(&url).await?;
let stake_account_rewards =
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)?;
Ok(stake_account_rewards)
}

pub async fn stake_account_updates(
&self,
stake_addr: &str,
params: Option<Parameters>,
) -> Result<StakeAccountUpdates, Box<dyn Error>> {
let formatted_params = params.map(|p| p.format()).unwrap_or_default();
let url = format!("/accounts/{}/updates{}", stake_addr, formatted_params);
let resp = self.get(&url).await?;
let stake_account_updates =
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)?;
Ok(stake_account_updates)
}
}
Loading