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

Better serde for blocks #233

Merged
merged 14 commits into from
Nov 26, 2023
34 changes: 9 additions & 25 deletions .github/workflows/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,22 @@ jobs:
name: cargo-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check
- uses: actions-rs/cargo@v1
- uses: actions/checkout@v3
- run: cargo check

wasm-check:
name: cargo-check-wasm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: wasm32-unknown-unknown
- uses: actions-rs/cargo@v1
with:
command: check
args: --target wasm32-unknown-unknown

- uses: actions/checkout@v3
- run: rustup target install wasm32-unknown-unknown
- run: cargo check --target wasm32-unknown-unknown

tests:
name: cargo-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -56,7 +40,7 @@ jobs:
name: cargo-fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand All @@ -72,7 +56,7 @@ jobs:
name: cargo-clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand Down
27 changes: 27 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@ Before submitting your pull request to the repository, please make sure you have

Documentation improvements are always welcome! A solid SDK needs to have solid documentation to go with it.

## Dependency Diagram

```mermaid
stateDiagram-v2
algod --> encoding
core --> encoding
crypto --> encoding
indexer --> encoding
kmd --> encoding
model --> encoding
transaction --> encoding
algod --> crypto
indexer --> crypto
core --> crypto
kmd --> crypto
model --> crypto
transaction --> crypto
abi --> core
kmd --> core
model --> core
transaction --> core
algod --> model
kmd --> model
transaction --> model
transaction --> abi
```

## Useful Resources

- [Git Style Guide](https://github.com/agis/git-style-guide)
Expand Down
2 changes: 1 addition & 1 deletion algonaut_abi/src/abi_type_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ mod test {
assert!(t.byte_len().is_err())
} else {
let mut size = 0;
let ct_list = t.children().clone();
let ct_list = t.children();

for i in 0..ct_list.len() {
match ct_list[i] {
Expand Down
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;
use crate::{apis::ResponseContent, ext::block::Block};

/// 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<crate::models::GetBlock200Response, Error<GetBlockError>> {
) -> Result<Block, Error<GetBlockError>> {
let local_var_configuration = configuration;

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

use super::transaction::TransactionHeader;

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

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

impl BlockWithCertificate {
pub fn hash(&self) -> HashDigest {
self.cert.prop.hash
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BlockCertificate {
pub prop: BlockCertificateProp,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BlockCertificateProp {
#[serde(rename = "dig")]
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 seed: Option<String>,
#[serde(default)]
pub ts: Option<u64>,
#[serde(default)]
pub txn256: Option<String>,
#[serde(default)]
pub txns: Option<Vec<TransactionHeader>>,
}
2 changes: 2 additions & 0 deletions algonaut_algod/src/ext/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod block;
pub mod transaction;
Loading
Loading