From e555afcf1d1c8f5d9c41a0bf03863a3cab75abf5 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Sun, 26 Nov 2023 20:12:01 +0100 Subject: [PATCH] Improve block params names (#234) * Improve Block parms names * Rename Block to BlockResponse --- algonaut_algod/src/apis/public_api.rs | 4 +- algonaut_algod/src/ext/block.rs | 82 ++++++++++++--------------- src/algod/v2/mod.rs | 4 +- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/algonaut_algod/src/apis/public_api.rs b/algonaut_algod/src/apis/public_api.rs index 63c7e03..a2756bb 100644 --- a/algonaut_algod/src/apis/public_api.rs +++ b/algonaut_algod/src/apis/public_api.rs @@ -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)] @@ -830,7 +830,7 @@ pub async fn get_block( configuration: &configuration::Configuration, round: u64, format: Option<&str>, -) -> Result> { +) -> Result> { let local_var_configuration = configuration; let local_var_client = &local_var_configuration.client; diff --git a/algonaut_algod/src/ext/block.rs b/algonaut_algod/src/ext/block.rs index bb0449f..0fe0820 100644 --- a/algonaut_algod/src/ext/block.rs +++ b/algonaut_algod/src/ext/block.rs @@ -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 } @@ -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, - #[serde(default)] - pub fees: Option, - #[serde(default)] - pub frac: Option, - #[serde(default)] - pub gen: Option, - #[serde(default)] - pub gh: Option, - #[serde(default)] - pub prev: Option, - #[serde(default)] - pub proto: Option, - #[serde(default)] - pub rate: Option, - #[serde(default)] - pub rnd: Option, - #[serde(default)] - pub rwcalr: Option, - #[serde(default)] - pub rwd: Option, - #[serde(default)] +pub struct Block { + #[serde(rename = "earn")] + pub rewards_level: Option, + #[serde(rename = "fees")] + pub fee_sink: Option, + #[serde(rename = "frac")] + pub rewards_residue: Option, + #[serde(rename = "gen")] + pub genesis_id: Option, + #[serde(rename = "gh")] + pub genesis_hash: Option, + #[serde(rename = "prev")] + pub branch: Option, + #[serde(rename = "proto")] + pub current_protocol: Option, + #[serde(rename = "rate")] + pub rewards_rate: Option, + #[serde(rename = "rnd")] + pub round: Option, + #[serde(rename = "rwcalr")] + pub rewards_recalculation_round: Option, + #[serde(rename = "rwd")] + pub rewards_pool: Option, + #[serde(rename = "seed")] pub seed: Option, - #[serde(default)] - pub ts: Option, - #[serde(default)] - pub txn256: Option, - #[serde(default)] + #[serde(rename = "ts")] + pub timestamp: Option, + #[serde(rename = "txn256")] + pub txn_commitment: Option, + #[serde(rename = "txns")] pub txns: Option>, } diff --git a/src/algod/v2/mod.rs b/src/algod/v2/mod.rs index 7769058..7e66f04 100644 --- a/src/algod/v2/mod.rs +++ b/src/algod/v2/mod.rs @@ -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, @@ -133,7 +133,7 @@ impl Algod { } /// Get the block for the given round. - pub async fn block(&self, round: u64) -> Result { + pub async fn block(&self, round: u64) -> Result { Ok( algonaut_algod::apis::public_api::get_block(&self.configuration, round, None) .await