Skip to content

Commit

Permalink
Add all transaction schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmauro committed Nov 26, 2023
1 parent bf5c3de commit ab5cf7c
Show file tree
Hide file tree
Showing 2 changed files with 258 additions and 54 deletions.
56 changes: 2 additions & 54 deletions algonaut_model/src/algod/v2/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use algonaut_crypto::HashDigest;
use serde::{Deserialize, Serialize};

use super::transaction::TransactionHeader;

/// Block
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Block {
Expand Down Expand Up @@ -78,57 +80,3 @@ pub struct BlockHeader {
#[serde(default)]
pub txns: Option<Vec<TransactionHeader>>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct TransactionHeader {
pub hgi: Option<bool>,
pub sig: Option<String>,
pub txn: Option<Transaction>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Transaction {
// Header
pub fee: Option<u64>,
pub fv: Option<u64>,
pub gh: Option<String>,
pub lv: Option<u64>,
pub snd: Option<String>,
#[serde(rename = "type")]
pub t: Option<TransactionType>,
pub gen: Option<String>,
pub grp: Option<String>,
pub lx: Option<String>,
pub note: Option<String>,
pub rekey: Option<String>,

// Payment
pub rcv: Option<String>,
pub amt: Option<u64>,
pub close: Option<String>,

// Key Registration
pub votekey: Option<String>,
pub selkey: Option<String>,
pub sprfkey: Option<String>,
pub votefst: Option<u64>,
pub votelst: Option<u64>,
pub votekd: Option<u64>,
pub nonpart: Option<bool>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum TransactionType {
#[serde(rename = "pay")]
Payment,
#[serde(rename = "keyreg")]
KeyRegistration,
#[serde(rename = "acfg")]
AssetConfig,
#[serde(rename = "axfer")]
AssetTransfer,
#[serde(rename = "afrz")]
AssetFreeze,
#[serde(rename = "appl")]
Application,
}
256 changes: 256 additions & 0 deletions algonaut_model/src/algod/v2/transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct TransactionHeader {
pub hgi: Option<bool>,
pub sig: Option<String>,
pub txn: Option<Transaction>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(tag = "type")]
pub enum Transaction {
#[serde(rename = "pay")]
Payment {
#[serde(rename = "fee")]
fee: Option<u64>,
#[serde(rename = "fv")]
first_valid: Option<u64>,
#[serde(rename = "gh")]
genesis_hash: Option<String>,
#[serde(rename = "lv")]
last_valid: Option<u64>,
#[serde(rename = "snd")]
sender: Option<String>,
#[serde(rename = "gen")]
genesis_id: Option<String>,
#[serde(rename = "grp")]
group: Option<String>,
#[serde(rename = "lx")]
lease: Option<String>,
#[serde(rename = "note")]
note: Option<String>,
#[serde(rename = "rekey")]
rekey: Option<String>,
// type specific fields
#[serde(rename = "rcv")]
receiver: Option<String>,
#[serde(rename = "amt")]
amount: Option<u64>,
#[serde(rename = "close")]
close_remainder_to: Option<String>,
},
#[serde(rename = "keyreg")]
KeyRegistration {
#[serde(rename = "fee")]
fee: Option<u64>,
#[serde(rename = "fv")]
first_valid: Option<u64>,
#[serde(rename = "gh")]
genesis_hash: Option<String>,
#[serde(rename = "lv")]
last_valid: Option<u64>,
#[serde(rename = "snd")]
sender: Option<String>,
#[serde(rename = "gen")]
genesis_id: Option<String>,
#[serde(rename = "grp")]
group: Option<String>,
#[serde(rename = "lx")]
lease: Option<String>,
#[serde(rename = "note")]
note: Option<String>,
#[serde(rename = "rekey")]
rekey: Option<String>,
// type specific fields
#[serde(rename = "votekey")]
vote_pk: Option<String>,
#[serde(rename = "selkey")]
selection_pk: Option<String>,
#[serde(rename = "sprfkey")]
state_proof_pk: Option<String>,
#[serde(rename = "votefst")]
vote_first: Option<u64>,
#[serde(rename = "votelst")]
vote_last: Option<u64>,
#[serde(rename = "votekd")]
vote_key_dilution: Option<u64>,
#[serde(rename = "nonpart")]
nonparticipating: Option<bool>,
},
#[serde(rename = "acfg")]
AssetConfig {
#[serde(rename = "fee")]
fee: Option<u64>,
#[serde(rename = "fv")]
first_valid: Option<u64>,
#[serde(rename = "gh")]
genesis_hash: Option<String>,
#[serde(rename = "lv")]
last_valid: Option<u64>,
#[serde(rename = "snd")]
sender: Option<String>,
#[serde(rename = "gen")]
genesis_id: Option<String>,
#[serde(rename = "grp")]
group: Option<String>,
#[serde(rename = "lx")]
lease: Option<String>,
#[serde(rename = "note")]
note: Option<String>,
#[serde(rename = "rekey")]
rekey: Option<String>,
// type specific fields
#[serde(rename = "caid")]
config_asset: Option<u64>,
#[serde(rename = "apar")]
params: Option<AssetParams>,
},
#[serde(rename = "axfer")]
AssetTransfer {
#[serde(rename = "fee")]
fee: Option<u64>,
#[serde(rename = "fv")]
first_valid: Option<u64>,
#[serde(rename = "gh")]
genesis_hash: Option<String>,
#[serde(rename = "lv")]
last_valid: Option<u64>,
#[serde(rename = "snd")]
sender: Option<String>,
#[serde(rename = "gen")]
genesis_id: Option<String>,
#[serde(rename = "grp")]
group: Option<String>,
#[serde(rename = "lx")]
lease: Option<String>,
#[serde(rename = "note")]
note: Option<String>,
#[serde(rename = "rekey")]
rekey: Option<String>,
// type specific fields
#[serde(rename = "xaid")]
asset_xfer: Option<u64>,
#[serde(rename = "aamt")]
asset_amount: Option<u64>,
#[serde(rename = "asnd")]
asset_sender: Option<String>,
#[serde(rename = "arcv")]
asset_receiver: Option<String>,
#[serde(rename = "close")]
asset_close_remainder_to: Option<String>,
},
#[serde(rename = "afrz")]
AssetFreeze {
#[serde(rename = "fee")]
fee: Option<u64>,
#[serde(rename = "fv")]
first_valid: Option<u64>,
#[serde(rename = "gh")]
genesis_hash: Option<String>,
#[serde(rename = "lv")]
last_valid: Option<u64>,
#[serde(rename = "snd")]
sender: Option<String>,
#[serde(rename = "gen")]
genesis_id: Option<String>,
#[serde(rename = "grp")]
group: Option<String>,
#[serde(rename = "lx")]
lease: Option<String>,
#[serde(rename = "note")]
note: Option<String>,
#[serde(rename = "rekey")]
rekey: Option<String>,
// type specific fields
#[serde(rename = "fadd")]
freeze_account: Option<String>,
#[serde(rename = "faid")]
asset_id: Option<u64>,
#[serde(rename = "ffrz")]
frozen: Option<bool>,
},
#[serde(rename = "appl")]
Application {
#[serde(rename = "fee")]
fee: Option<u64>,
#[serde(rename = "fv")]
first_valid: Option<u64>,
#[serde(rename = "gh")]
genesis_hash: Option<String>,
#[serde(rename = "lv")]
last_valid: Option<u64>,
#[serde(rename = "snd")]
sender: Option<String>,
#[serde(rename = "gen")]
genesis_id: Option<String>,
#[serde(rename = "grp")]
group: Option<String>,
#[serde(rename = "lx")]
lease: Option<String>,
#[serde(rename = "note")]
note: Option<String>,
#[serde(rename = "rekey")]
rekey: Option<String>,
// type specific fields
#[serde(rename = "apid")]
app_id: Option<u64>,
#[serde(rename = "apan")]
on_complete: Option<u64>,
#[serde(rename = "apat")]
accounts: Option<Vec<String>>,
#[serde(rename = "apap")]
approval_program: Option<Vec<String>>,
#[serde(rename = "apaa")]
app_arguments: Option<Vec<String>>,
#[serde(rename = "apsu")]
clear_state_program: Option<String>,
#[serde(rename = "apfa")]
foreign_apps: Option<Vec<u64>>,
#[serde(rename = "apas")]
foreign_assets: Option<Vec<u64>>,
#[serde(rename = "apgs")]
global_state_schema: Option<StateSchema>,
#[serde(rename = "apls")]
local_state_schema: Option<StateSchema>,
#[serde(rename = "apep")]
extra_program_pages: Option<u64>,
// TODO
// #[serde(rename = "apbx")]
// boxes: Option<Vec<String>>,
},
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
pub struct AssetParams {
#[serde(rename = "am")]
pub meta_data_hash: Option<Vec<u8>>,
#[serde(rename = "an")]
pub asset_name: Option<String>,
#[serde(rename = "au")]
pub url: Option<String>,
#[serde(rename = "c")]
pub clawback: Option<String>,
#[serde(rename = "dc")]
pub decimals: Option<u32>,
#[serde(rename = "df")]
pub default_frozen: Option<bool>,
#[serde(rename = "f")]
pub freeze: Option<String>,
#[serde(rename = "m")]
pub manager: Option<String>,
#[serde(rename = "r")]
pub reserve: Option<String>,
#[serde(rename = "t")]
pub total: Option<u64>,
#[serde(rename = "un")]
pub unit_name: Option<String>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
pub struct StateSchema {
#[serde(rename = "nui")]
pub ints: Option<u64>,
#[serde(rename = "nbs")]
pub byte_slices: Option<u64>,
}

0 comments on commit ab5cf7c

Please sign in to comment.