100 lines
3.4 KiB
Rust
100 lines
3.4 KiB
Rust
// 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 TokenBurnEventDto {
|
|
/// 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 TokenBurnEventDto {
|
|
/// 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 {
|
|
return Self {
|
|
id: None,
|
|
token_id,
|
|
signature,
|
|
instruction_index,
|
|
slot,
|
|
authority_wallet,
|
|
source_wallet,
|
|
amount,
|
|
supply_after,
|
|
executed_at: chrono::Utc::now(),
|
|
};
|
|
}
|
|
}
|
|
|
|
impl TryFrom<crate::TokenBurnEventEntity> for TokenBurnEventDto {
|
|
type Error = crate::Error;
|
|
|
|
fn try_from(entity: crate::TokenBurnEventEntity) -> 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::Error::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::Error::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,
|
|
});
|
|
}
|
|
}
|