Skip to content

Commit

Permalink
Merge branch 'main' into publish-crates
Browse files Browse the repository at this point in the history
  • Loading branch information
Vardominator authored Aug 8, 2024
2 parents 26c5275 + 831f54e commit 5553590
Show file tree
Hide file tree
Showing 27 changed files with 252 additions and 127 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ exclude = [".github", ".vscode", ".gitignore"]
reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rust_decimal = "1.34"
serde_qs = "0.12"
chrono = { version = "0.4", features = ["serde"] }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

## Installation

### [Crates Reference](TODO)
### Crates Reference

```bash
# TODO
Expand Down
8 changes: 4 additions & 4 deletions src/client/block_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ use crate::utils;
use serde::{Deserialize, Serialize};
use std::error::Error;

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct OperationalCertificate {
pub hot_vkey: String,
pub kes_period: i64,
pub kes_signature: String,
pub sequence_number: i64,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TotalExUnits {
pub mem: i64,
pub steps: i64,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct BlockInfoData {
pub absolute_slot: i64,
pub block_producer: String,
Expand All @@ -40,7 +40,7 @@ pub struct BlockInfoData {
pub vrf_key: String,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct BlockInfo {
pub data: BlockInfoData,
pub last_updated: utils::last_updated::LastUpdated,
Expand Down
4 changes: 2 additions & 2 deletions src/client/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use serde::Deserialize;

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct ClientConfig {
pub version: String,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct Config {
pub client: ClientConfig,
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/epochs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Maestro {
}

pub async fn specific_epoch(&self, epoch_no: i32) -> Result<EpochResp, Box<dyn Error>> {
let url = format!("/epochs/{}/info", epoch_no);
let url = format!("/epochs/{}", epoch_no);
let resp = self.get(&url).await?;
let specific_epoch =
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)?;
Expand Down
2 changes: 1 addition & 1 deletion src/client/linear_vesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::models::linear_vesting::{CollectTransaction, LockTransaction, Vesting
use serde::{Deserialize, Serialize};
use std::error::Error;

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LockBody {
pub sender: String,
pub beneficiary: String,
Expand Down
2 changes: 0 additions & 2 deletions src/client/maestro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ impl Maestro {
let req = self
.http_client
.post(format!("{}{}", &self.base_url, url))
.header("Accept", "application/json")
.header("api-key", &self.api_key)
.header("Content-Type", "application/json")
.body(json_body);

Expand Down
23 changes: 23 additions & 0 deletions src/client/markets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::models::markets::{DexPairOHLC, DexPairOHLCParameters};

use super::maestro::Maestro;
use std::{error::Error, fmt::Display};

impl Maestro {
/// Returns market activity in candlestick OHLC format for a specific DEX and token pair
pub async fn markets_dex_pair_ohlc(
&self,
dex: impl Display,
pair: impl Display,
parameters: Option<DexPairOHLCParameters>,
) -> Result<Vec<DexPairOHLC>, Box<dyn Error>> {
let ps = parameters
.and_then(|p| serde_qs::to_string(&p).ok())
.map(|x| format!("?{x}"))
.unwrap_or_default();
let url = format!("/markets/dexs/ohlc/{dex}/{pair}{ps}");
let resp = self.get(&url).await?;

serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)
}
}
1 change: 1 addition & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod epochs;
pub mod general;
pub mod linear_vesting;
pub mod maestro;
pub mod markets;
pub mod pools;
pub mod scripts;
pub mod transactions;
Expand Down
22 changes: 20 additions & 2 deletions src/client/pools.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::maestro::Maestro;
use crate::{
models::pools::{
PoolMintedBlocks, RegisteredPools, StakePoolDelegators, StakePoolHistory,
StakePoolInformation, StakePoolMetadata, StakePoolRelays, StakePoolUpdates,
PoolMintedBlocks, RegisteredPools, StakePoolDelegatorHistory, StakePoolDelegators,
StakePoolHistory, StakePoolInformation, StakePoolMetadata, StakePoolRelays,
StakePoolUpdates,
},
utils::Parameters,
};
Expand Down Expand Up @@ -103,4 +104,21 @@ impl Maestro {
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)?;
Ok(stake_pool_updates)
}

pub async fn stake_pool_delegator_history(
&self,
pool_id: &str,
epoch_no: i64,
params: Option<Parameters>,
) -> Result<StakePoolDelegatorHistory, Box<dyn Error>> {
let formatted_params = params.map(|p| p.format()).unwrap_or_default();
let url = format!(
"/pools/{}/delegators/{}{}",
pool_id, epoch_no, formatted_params
);
let resp = self.get(&url).await?;
let stake_pool_delegator_history =
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>)?;
Ok(stake_pool_delegator_history)
}
}
17 changes: 9 additions & 8 deletions src/client/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::maestro::Maestro;
use crate::models::{
common::BasicResponse,
transactions::{
EvaluateTx, RedeemerEvaluation, TransactionDetails, TransactionOutputFromReference,
TransactionOutputsFromReferences,
AdditionalUtxo, EvaluateTx, RedeemerEvaluation, TransactionDetails,
TransactionOutputFromReference, TransactionOutputsFromReferences,
},
};
use std::{collections::HashMap, error::Error};
Expand Down Expand Up @@ -54,11 +54,12 @@ impl Maestro {
params: Option<HashMap<String, String>>,
) -> Result<TransactionOutputFromReference, Box<dyn Error>> {
let formatted_params = params.map_or("".to_string(), |p| {
p.iter()
.map(|(k, v)| format!("{}={}", k, v))
.collect::<Vec<String>>()
.join("&")
.to_string()
"?".to_string()
+ p.iter()
.map(|(k, v)| format!("{}={}", k, v))
.collect::<Vec<String>>()
.join("&")
.as_str()
});
let url = format!(
"/transactions/{}/outputs/{}/txo{}",
Expand Down Expand Up @@ -92,7 +93,7 @@ impl Maestro {
pub async fn evaluate_tx(
&self,
tx_cbor: &str,
additional_utxos: Vec<String>,
additional_utxos: Vec<AdditionalUtxo>,
) -> Result<Vec<RedeemerEvaluation>, Box<dyn Error>> {
let url = "/transactions/evaluate";
let body = EvaluateTx {
Expand Down
26 changes: 13 additions & 13 deletions src/models/accounts.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
use crate::utils;
use serde::Deserialize;

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct AccountAddresses {
pub data: Vec<String>,
pub last_updated: utils::LastUpdated,
pub next_cursor: Option<String>,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct AccountAsset {
pub amount: i64,
pub unit: String,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct AccountAssets {
pub data: Vec<AccountAsset>,
pub last_updated: utils::LastUpdated,
pub next_cursor: Option<String>,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct StakeAccountHistoryItem {
pub active_stake: i64,
pub epoch_no: i64,
pub pool_id: String,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct StakeAccountHistory {
pub data: Vec<StakeAccountHistoryItem>,
pub last_updated: utils::LastUpdated,
pub next_cursor: Option<String>,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct AccountInformation {
pub delegated_pool: String,
pub registered: bool,
Expand All @@ -47,20 +47,20 @@ pub struct AccountInformation {
pub utxo_balance: i64,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct StakeAccountInformation {
pub data: AccountInformation,
pub last_updated: utils::LastUpdated,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub enum StakeRewardType {
Member,
Leader,
Refund,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct StakeAccountReward {
pub amount: i64,
pub earned_epoch: i64,
Expand All @@ -69,30 +69,30 @@ pub struct StakeAccountReward {
pub r#type: StakeRewardType,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct StakeAccountRewards {
pub data: Vec<StakeAccountReward>,
pub last_updated: utils::LastUpdated,
pub next_cursor: Option<String>,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub enum StakeUpdateAction {
Registration,
Deregistration,
Delegation,
Withdrawal,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct StakeAccountUpdate {
pub absolute_slot: i64,
pub action: StakeUpdateAction,
pub epoch_no: i64,
pub tx_hash: String,
}

#[derive(Deserialize)]
#[derive(Deserialize, Debug, Clone)]
pub struct StakeAccountUpdates {
pub data: Vec<StakeAccountUpdate>,
pub last_updated: utils::LastUpdated,
Expand Down
Loading

0 comments on commit 5553590

Please sign in to comment.