This commit is contained in:
2026-04-24 12:01:35 +02:00
parent 54778373b8
commit 0ad6145091
23 changed files with 1653 additions and 5 deletions

View File

@@ -0,0 +1,103 @@
// 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<i64>,
/// 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<u64>,
/// Optional authority wallet.
pub authority_wallet: std::option::Option<std::string::String>,
/// Optional source wallet.
pub source_wallet: std::option::Option<std::string::String>,
/// Burned amount as decimal text.
pub amount: std::string::String,
/// Optional supply after burn as decimal text.
pub supply_after: std::option::Option<std::string::String>,
/// Execution timestamp.
pub executed_at: chrono::DateTime<chrono::Utc>,
}
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<u64>,
authority_wallet: std::option::Option<std::string::String>,
source_wallet: std::option::Option<std::string::String>,
amount: std::string::String,
supply_after: std::option::Option<std::string::String>,
) -> Self {
Self {
id: None,
token_id,
signature,
instruction_index,
slot,
authority_wallet,
source_wallet,
amount,
supply_after,
executed_at: chrono::Utc::now(),
}
}
}
impl TryFrom<crate::KbTokenBurnEventEntity> for KbTokenBurnEventDto {
type Error = crate::KbError;
fn try_from(
entity: crate::KbTokenBurnEventEntity,
) -> Result<Self, Self::Error> {
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,
};
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,
})
}
}