diff --git a/algonaut_model/src/algod/v2/block.rs b/algonaut_model/src/algod/v2/block.rs index ea856b9..bb0449f 100644 --- a/algonaut_model/src/algod/v2/block.rs +++ b/algonaut_model/src/algod/v2/block.rs @@ -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 { @@ -78,57 +80,3 @@ pub struct BlockHeader { #[serde(default)] pub txns: Option>, } - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct TransactionHeader { - pub hgi: Option, - pub sig: Option, - pub txn: Option, -} - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct Transaction { - // Header - pub fee: Option, - pub fv: Option, - pub gh: Option, - pub lv: Option, - pub snd: Option, - #[serde(rename = "type")] - pub t: Option, - pub gen: Option, - pub grp: Option, - pub lx: Option, - pub note: Option, - pub rekey: Option, - - // Payment - pub rcv: Option, - pub amt: Option, - pub close: Option, - - // Key Registration - pub votekey: Option, - pub selkey: Option, - pub sprfkey: Option, - pub votefst: Option, - pub votelst: Option, - pub votekd: Option, - pub nonpart: Option, -} - -#[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, -} diff --git a/algonaut_model/src/algod/v2/transaction.rs b/algonaut_model/src/algod/v2/transaction.rs index e69de29..fa174a1 100644 --- a/algonaut_model/src/algod/v2/transaction.rs +++ b/algonaut_model/src/algod/v2/transaction.rs @@ -0,0 +1,256 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct TransactionHeader { + pub hgi: Option, + pub sig: Option, + pub txn: Option, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(tag = "type")] +pub enum Transaction { + #[serde(rename = "pay")] + Payment { + #[serde(rename = "fee")] + fee: Option, + #[serde(rename = "fv")] + first_valid: Option, + #[serde(rename = "gh")] + genesis_hash: Option, + #[serde(rename = "lv")] + last_valid: Option, + #[serde(rename = "snd")] + sender: Option, + #[serde(rename = "gen")] + genesis_id: Option, + #[serde(rename = "grp")] + group: Option, + #[serde(rename = "lx")] + lease: Option, + #[serde(rename = "note")] + note: Option, + #[serde(rename = "rekey")] + rekey: Option, + // type specific fields + #[serde(rename = "rcv")] + receiver: Option, + #[serde(rename = "amt")] + amount: Option, + #[serde(rename = "close")] + close_remainder_to: Option, + }, + #[serde(rename = "keyreg")] + KeyRegistration { + #[serde(rename = "fee")] + fee: Option, + #[serde(rename = "fv")] + first_valid: Option, + #[serde(rename = "gh")] + genesis_hash: Option, + #[serde(rename = "lv")] + last_valid: Option, + #[serde(rename = "snd")] + sender: Option, + #[serde(rename = "gen")] + genesis_id: Option, + #[serde(rename = "grp")] + group: Option, + #[serde(rename = "lx")] + lease: Option, + #[serde(rename = "note")] + note: Option, + #[serde(rename = "rekey")] + rekey: Option, + // type specific fields + #[serde(rename = "votekey")] + vote_pk: Option, + #[serde(rename = "selkey")] + selection_pk: Option, + #[serde(rename = "sprfkey")] + state_proof_pk: Option, + #[serde(rename = "votefst")] + vote_first: Option, + #[serde(rename = "votelst")] + vote_last: Option, + #[serde(rename = "votekd")] + vote_key_dilution: Option, + #[serde(rename = "nonpart")] + nonparticipating: Option, + }, + #[serde(rename = "acfg")] + AssetConfig { + #[serde(rename = "fee")] + fee: Option, + #[serde(rename = "fv")] + first_valid: Option, + #[serde(rename = "gh")] + genesis_hash: Option, + #[serde(rename = "lv")] + last_valid: Option, + #[serde(rename = "snd")] + sender: Option, + #[serde(rename = "gen")] + genesis_id: Option, + #[serde(rename = "grp")] + group: Option, + #[serde(rename = "lx")] + lease: Option, + #[serde(rename = "note")] + note: Option, + #[serde(rename = "rekey")] + rekey: Option, + // type specific fields + #[serde(rename = "caid")] + config_asset: Option, + #[serde(rename = "apar")] + params: Option, + }, + #[serde(rename = "axfer")] + AssetTransfer { + #[serde(rename = "fee")] + fee: Option, + #[serde(rename = "fv")] + first_valid: Option, + #[serde(rename = "gh")] + genesis_hash: Option, + #[serde(rename = "lv")] + last_valid: Option, + #[serde(rename = "snd")] + sender: Option, + #[serde(rename = "gen")] + genesis_id: Option, + #[serde(rename = "grp")] + group: Option, + #[serde(rename = "lx")] + lease: Option, + #[serde(rename = "note")] + note: Option, + #[serde(rename = "rekey")] + rekey: Option, + // type specific fields + #[serde(rename = "xaid")] + asset_xfer: Option, + #[serde(rename = "aamt")] + asset_amount: Option, + #[serde(rename = "asnd")] + asset_sender: Option, + #[serde(rename = "arcv")] + asset_receiver: Option, + #[serde(rename = "close")] + asset_close_remainder_to: Option, + }, + #[serde(rename = "afrz")] + AssetFreeze { + #[serde(rename = "fee")] + fee: Option, + #[serde(rename = "fv")] + first_valid: Option, + #[serde(rename = "gh")] + genesis_hash: Option, + #[serde(rename = "lv")] + last_valid: Option, + #[serde(rename = "snd")] + sender: Option, + #[serde(rename = "gen")] + genesis_id: Option, + #[serde(rename = "grp")] + group: Option, + #[serde(rename = "lx")] + lease: Option, + #[serde(rename = "note")] + note: Option, + #[serde(rename = "rekey")] + rekey: Option, + // type specific fields + #[serde(rename = "fadd")] + freeze_account: Option, + #[serde(rename = "faid")] + asset_id: Option, + #[serde(rename = "ffrz")] + frozen: Option, + }, + #[serde(rename = "appl")] + Application { + #[serde(rename = "fee")] + fee: Option, + #[serde(rename = "fv")] + first_valid: Option, + #[serde(rename = "gh")] + genesis_hash: Option, + #[serde(rename = "lv")] + last_valid: Option, + #[serde(rename = "snd")] + sender: Option, + #[serde(rename = "gen")] + genesis_id: Option, + #[serde(rename = "grp")] + group: Option, + #[serde(rename = "lx")] + lease: Option, + #[serde(rename = "note")] + note: Option, + #[serde(rename = "rekey")] + rekey: Option, + // type specific fields + #[serde(rename = "apid")] + app_id: Option, + #[serde(rename = "apan")] + on_complete: Option, + #[serde(rename = "apat")] + accounts: Option>, + #[serde(rename = "apap")] + approval_program: Option>, + #[serde(rename = "apaa")] + app_arguments: Option>, + #[serde(rename = "apsu")] + clear_state_program: Option, + #[serde(rename = "apfa")] + foreign_apps: Option>, + #[serde(rename = "apas")] + foreign_assets: Option>, + #[serde(rename = "apgs")] + global_state_schema: Option, + #[serde(rename = "apls")] + local_state_schema: Option, + #[serde(rename = "apep")] + extra_program_pages: Option, + // TODO + // #[serde(rename = "apbx")] + // boxes: Option>, + }, +} + +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +pub struct AssetParams { + #[serde(rename = "am")] + pub meta_data_hash: Option>, + #[serde(rename = "an")] + pub asset_name: Option, + #[serde(rename = "au")] + pub url: Option, + #[serde(rename = "c")] + pub clawback: Option, + #[serde(rename = "dc")] + pub decimals: Option, + #[serde(rename = "df")] + pub default_frozen: Option, + #[serde(rename = "f")] + pub freeze: Option, + #[serde(rename = "m")] + pub manager: Option, + #[serde(rename = "r")] + pub reserve: Option, + #[serde(rename = "t")] + pub total: Option, + #[serde(rename = "un")] + pub unit_name: Option, +} + +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] +pub struct StateSchema { + #[serde(rename = "nui")] + pub ints: Option, + #[serde(rename = "nbs")] + pub byte_slices: Option, +}