// file: kb_lib/src/db/dtos/token_burn_event.rs //! Token burn event DTO. /// Application-facing normalized token burn event DTO. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct KbTokenBurnEventDto { /// Optional numeric primary key. pub id: std::option::Option, /// Related token id. pub token_id: i64, /// Transaction signature. pub signature: std::string::String, /// Instruction index inside the transaction. pub instruction_index: i64, /// Optional slot number. pub slot: std::option::Option, /// Optional authority wallet. pub authority_wallet: std::option::Option, /// Optional source wallet. pub source_wallet: std::option::Option, /// Burned amount as decimal text. pub amount: std::string::String, /// Optional supply after burn as decimal text. pub supply_after: std::option::Option, /// Execution timestamp. pub executed_at: chrono::DateTime, } impl KbTokenBurnEventDto { /// Creates a new token burn event DTO. pub fn new( token_id: i64, signature: std::string::String, instruction_index: i64, slot: std::option::Option, authority_wallet: std::option::Option, source_wallet: std::option::Option, amount: std::string::String, supply_after: std::option::Option, ) -> Self { return Self { id: None, token_id, signature, instruction_index, slot, authority_wallet, source_wallet, amount, supply_after, executed_at: chrono::Utc::now(), }; } } impl TryFrom for KbTokenBurnEventDto { type Error = crate::KbError; fn try_from(entity: crate::KbTokenBurnEventEntity) -> Result { let executed_at_result = chrono::DateTime::parse_from_rfc3339(&entity.executed_at); let executed_at = match executed_at_result { Ok(executed_at) => executed_at.with_timezone(&chrono::Utc), Err(error) => { return Err(crate::KbError::Db(format!( "cannot parse token burn event executed_at '{}': {}", entity.executed_at, error ))); }, }; let slot = match entity.slot { Some(slot) => { let slot_result = u64::try_from(slot); match slot_result { Ok(slot) => Some(slot), Err(error) => { return Err(crate::KbError::Db(format!( "cannot convert token burn event slot '{}' to u64: {}", slot, error ))); }, } }, None => None, }; return Ok(Self { id: Some(entity.id), token_id: entity.token_id, signature: entity.signature, instruction_index: entity.instruction_index, slot, authority_wallet: entity.authority_wallet, source_wallet: entity.source_wallet, amount: entity.amount, supply_after: entity.supply_after, executed_at, }); } }