Skip to content

Commit

Permalink
Improve block params names (#234)
Browse files Browse the repository at this point in the history
* Improve Block parms names

* Rename Block to BlockResponse
  • Loading branch information
manuelmauro authored Nov 26, 2023
1 parent daf1de6 commit e555afc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 51 deletions.
4 changes: 2 additions & 2 deletions algonaut_algod/src/apis/public_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use reqwest;

use super::{configuration, Error};
use crate::{apis::ResponseContent, ext::block::Block};
use crate::{apis::ResponseContent, ext::block::BlockResponse};

/// struct for typed errors of method [`account_application_information`]
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -830,7 +830,7 @@ pub async fn get_block(
configuration: &configuration::Configuration,
round: u64,
format: Option<&str>,
) -> Result<Block, Error<GetBlockError>> {
) -> Result<BlockResponse, Error<GetBlockError>> {
let local_var_configuration = configuration;

let local_var_client = &local_var_configuration.client;
Expand Down
82 changes: 35 additions & 47 deletions algonaut_algod/src/ext/block.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
use super::transaction::TransactionHeader;
use algonaut_crypto::HashDigest;
use serde::{Deserialize, Serialize};

use super::transaction::TransactionHeader;

/// Block
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Block {
pub struct BlockResponse {
/// Block header data.
pub block: BlockHeader,
pub block: Block,
}

/// Block with certificate
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BlockWithCertificate {
pub struct BlockWithCertificateResponse {
/// Block header data
pub block: BlockHeader,
pub block: Block,
/// Certificate
pub cert: BlockCertificate,
}

impl BlockWithCertificate {
impl BlockWithCertificateResponse {
pub fn hash(&self) -> HashDigest {
self.cert.prop.hash
}
Expand All @@ -36,47 +35,36 @@ pub struct BlockCertificateProp {
pub hash: HashDigest,
}

/// BlockHeader
///
/// Note: fields seem to be managed as untyped map and currently not documented ([docs](https://developer.algorand.org/docs/rest-apis/algod/v2/#getblock-response-200)),
/// so everything optional. Some may be outdated or missing.
///
/// For now, also, byte array representations as strings,
/// different encodings and prefixes are used, hindering a standarized deserialization.
///
/// It probably makes sense to deserialize this and [BlockHeaderMsgPack]
/// to the same struct, but above makes it currently not possible.
///
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BlockHeader {
#[serde(default)]
pub earn: Option<u64>,
#[serde(default)]
pub fees: Option<String>,
#[serde(default)]
pub frac: Option<u64>,
#[serde(default)]
pub gen: Option<String>,
#[serde(default)]
pub gh: Option<String>,
#[serde(default)]
pub prev: Option<String>,
#[serde(default)]
pub proto: Option<String>,
#[serde(default)]
pub rate: Option<u64>,
#[serde(default)]
pub rnd: Option<u64>,
#[serde(default)]
pub rwcalr: Option<u64>,
#[serde(default)]
pub rwd: Option<String>,
#[serde(default)]
pub struct Block {
#[serde(rename = "earn")]
pub rewards_level: Option<u64>,
#[serde(rename = "fees")]
pub fee_sink: Option<String>,
#[serde(rename = "frac")]
pub rewards_residue: Option<u64>,
#[serde(rename = "gen")]
pub genesis_id: Option<String>,
#[serde(rename = "gh")]
pub genesis_hash: Option<String>,
#[serde(rename = "prev")]
pub branch: Option<String>,
#[serde(rename = "proto")]
pub current_protocol: Option<String>,
#[serde(rename = "rate")]
pub rewards_rate: Option<u64>,
#[serde(rename = "rnd")]
pub round: Option<u64>,
#[serde(rename = "rwcalr")]
pub rewards_recalculation_round: Option<u64>,
#[serde(rename = "rwd")]
pub rewards_pool: Option<String>,
#[serde(rename = "seed")]
pub seed: Option<String>,
#[serde(default)]
pub ts: Option<u64>,
#[serde(default)]
pub txn256: Option<String>,
#[serde(default)]
#[serde(rename = "ts")]
pub timestamp: Option<u64>,
#[serde(rename = "txn256")]
pub txn_commitment: Option<String>,
#[serde(rename = "txns")]
pub txns: Option<Vec<TransactionHeader>>,
}
4 changes: 2 additions & 2 deletions src/algod/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use self::error::AlgodError;
use crate::Error;
use algonaut_algod::{
apis::configuration::{ApiKey, Configuration},
ext::block::Block,
ext::block::BlockResponse,
models::{
self, Account, AccountApplicationInformation200Response, Application, Asset, DryrunRequest,
GetApplicationBoxes200Response, GetBlockHash200Response,
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Algod {
}

/// Get the block for the given round.
pub async fn block(&self, round: u64) -> Result<Block, Error> {
pub async fn block(&self, round: u64) -> Result<BlockResponse, Error> {
Ok(
algonaut_algod::apis::public_api::get_block(&self.configuration, round, None)
.await
Expand Down

0 comments on commit e555afc

Please sign in to comment.