0.7.1 for Real ! - it was 0.7.0 before, not 0.7.1 !!
This commit is contained in:
140
kb_lib/src/db/dtos/chain_instruction.rs
Normal file
140
kb_lib/src/db/dtos/chain_instruction.rs
Normal file
@@ -0,0 +1,140 @@
|
||||
// file: kb_lib/src/db/dtos/chain_instruction.rs
|
||||
|
||||
//! Application-facing normalized chain instruction DTO.
|
||||
|
||||
/// Application-facing normalized chain instruction DTO.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct KbChainInstructionDto {
|
||||
/// Optional numeric primary key.
|
||||
pub id: std::option::Option<i64>,
|
||||
/// Parent transaction id.
|
||||
pub transaction_id: i64,
|
||||
/// Optional parent instruction id for inner instructions.
|
||||
pub parent_instruction_id: std::option::Option<i64>,
|
||||
/// Outer instruction index.
|
||||
pub instruction_index: u32,
|
||||
/// Optional inner instruction index.
|
||||
pub inner_instruction_index: std::option::Option<u32>,
|
||||
/// Optional program id.
|
||||
pub program_id: std::option::Option<std::string::String>,
|
||||
/// Optional program name.
|
||||
pub program_name: std::option::Option<std::string::String>,
|
||||
/// Optional stack height.
|
||||
pub stack_height: std::option::Option<u32>,
|
||||
/// Serialized accounts JSON array.
|
||||
pub accounts_json: std::string::String,
|
||||
/// Optional serialized data JSON.
|
||||
pub data_json: std::option::Option<std::string::String>,
|
||||
/// Optional parsed type.
|
||||
pub parsed_type: std::option::Option<std::string::String>,
|
||||
/// Optional serialized parsed JSON.
|
||||
pub parsed_json: std::option::Option<std::string::String>,
|
||||
/// Creation timestamp.
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl KbChainInstructionDto {
|
||||
/// Creates a new chain instruction DTO.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
transaction_id: i64,
|
||||
parent_instruction_id: std::option::Option<i64>,
|
||||
instruction_index: u32,
|
||||
inner_instruction_index: std::option::Option<u32>,
|
||||
program_id: std::option::Option<std::string::String>,
|
||||
program_name: std::option::Option<std::string::String>,
|
||||
stack_height: std::option::Option<u32>,
|
||||
accounts_json: std::string::String,
|
||||
data_json: std::option::Option<std::string::String>,
|
||||
parsed_type: std::option::Option<std::string::String>,
|
||||
parsed_json: std::option::Option<std::string::String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
transaction_id,
|
||||
parent_instruction_id,
|
||||
instruction_index,
|
||||
inner_instruction_index,
|
||||
program_id,
|
||||
program_name,
|
||||
stack_height,
|
||||
accounts_json,
|
||||
data_json,
|
||||
parsed_type,
|
||||
parsed_json,
|
||||
created_at: chrono::Utc::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<crate::KbChainInstructionEntity> for KbChainInstructionDto {
|
||||
type Error = crate::KbError;
|
||||
|
||||
fn try_from(entity: crate::KbChainInstructionEntity) -> Result<Self, Self::Error> {
|
||||
let instruction_index_result = u32::try_from(entity.instruction_index);
|
||||
let instruction_index = match instruction_index_result {
|
||||
Ok(instruction_index) => instruction_index,
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot convert chain instruction instruction_index '{}' to u32: {}",
|
||||
entity.instruction_index, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
let inner_instruction_index = match entity.inner_instruction_index {
|
||||
Some(inner_instruction_index) => {
|
||||
let inner_instruction_index_result = u32::try_from(inner_instruction_index);
|
||||
match inner_instruction_index_result {
|
||||
Ok(inner_instruction_index) => Some(inner_instruction_index),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot convert chain instruction inner_instruction_index '{}' to u32: {}",
|
||||
inner_instruction_index, error
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let stack_height = match entity.stack_height {
|
||||
Some(stack_height) => {
|
||||
let stack_height_result = u32::try_from(stack_height);
|
||||
match stack_height_result {
|
||||
Ok(stack_height) => Some(stack_height),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot convert chain instruction stack_height '{}' to u32: {}",
|
||||
stack_height, error
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let created_at_result = chrono::DateTime::parse_from_rfc3339(&entity.created_at);
|
||||
let created_at = match created_at_result {
|
||||
Ok(created_at) => created_at.with_timezone(&chrono::Utc),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot parse chain instruction created_at '{}': {}",
|
||||
entity.created_at, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
Ok(Self {
|
||||
id: Some(entity.id),
|
||||
transaction_id: entity.transaction_id,
|
||||
parent_instruction_id: entity.parent_instruction_id,
|
||||
instruction_index,
|
||||
inner_instruction_index,
|
||||
program_id: entity.program_id,
|
||||
program_name: entity.program_name,
|
||||
stack_height,
|
||||
accounts_json: entity.accounts_json,
|
||||
data_json: entity.data_json,
|
||||
parsed_type: entity.parsed_type,
|
||||
parsed_json: entity.parsed_json,
|
||||
created_at,
|
||||
})
|
||||
}
|
||||
}
|
||||
95
kb_lib/src/db/dtos/chain_slot.rs
Normal file
95
kb_lib/src/db/dtos/chain_slot.rs
Normal file
@@ -0,0 +1,95 @@
|
||||
// file: kb_lib/src/db/dtos/chain_slot.rs
|
||||
|
||||
//! Application-facing normalized chain slot DTO.
|
||||
|
||||
/// Application-facing normalized chain slot DTO.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct KbChainSlotDto {
|
||||
/// Slot number.
|
||||
pub slot: u64,
|
||||
/// Optional parent slot number.
|
||||
pub parent_slot: std::option::Option<u64>,
|
||||
/// Optional block time in unix seconds.
|
||||
pub block_time_unix: std::option::Option<i64>,
|
||||
/// Creation timestamp.
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
/// Update timestamp.
|
||||
pub updated_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl KbChainSlotDto {
|
||||
/// Creates a new chain slot DTO.
|
||||
pub fn new(
|
||||
slot: u64,
|
||||
parent_slot: std::option::Option<u64>,
|
||||
block_time_unix: std::option::Option<i64>,
|
||||
) -> Self {
|
||||
let now = chrono::Utc::now();
|
||||
Self {
|
||||
slot,
|
||||
parent_slot,
|
||||
block_time_unix,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<crate::KbChainSlotEntity> for KbChainSlotDto {
|
||||
type Error = crate::KbError;
|
||||
|
||||
fn try_from(entity: crate::KbChainSlotEntity) -> Result<Self, Self::Error> {
|
||||
let slot_result = u64::try_from(entity.slot);
|
||||
let slot = match slot_result {
|
||||
Ok(slot) => slot,
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot convert chain slot '{}' to u64: {}",
|
||||
entity.slot, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
let parent_slot = match entity.parent_slot {
|
||||
Some(parent_slot) => {
|
||||
let parent_slot_result = u64::try_from(parent_slot);
|
||||
match parent_slot_result {
|
||||
Ok(parent_slot) => Some(parent_slot),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot convert chain parent_slot '{}' to u64: {}",
|
||||
parent_slot, error
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let created_at_result = chrono::DateTime::parse_from_rfc3339(&entity.created_at);
|
||||
let created_at = match created_at_result {
|
||||
Ok(created_at) => created_at.with_timezone(&chrono::Utc),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot parse chain slot created_at '{}': {}",
|
||||
entity.created_at, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
let updated_at_result = chrono::DateTime::parse_from_rfc3339(&entity.updated_at);
|
||||
let updated_at = match updated_at_result {
|
||||
Ok(updated_at) => updated_at.with_timezone(&chrono::Utc),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot parse chain slot updated_at '{}': {}",
|
||||
entity.updated_at, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
Ok(Self {
|
||||
slot,
|
||||
parent_slot,
|
||||
block_time_unix: entity.block_time_unix,
|
||||
created_at,
|
||||
updated_at,
|
||||
})
|
||||
}
|
||||
}
|
||||
115
kb_lib/src/db/dtos/chain_transaction.rs
Normal file
115
kb_lib/src/db/dtos/chain_transaction.rs
Normal file
@@ -0,0 +1,115 @@
|
||||
// file: kb_lib/src/db/dtos/chain_transaction.rs
|
||||
|
||||
//! Application-facing normalized chain transaction DTO.
|
||||
|
||||
/// Application-facing normalized chain transaction DTO.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct KbChainTransactionDto {
|
||||
/// Optional numeric primary key.
|
||||
pub id: std::option::Option<i64>,
|
||||
/// Transaction signature.
|
||||
pub signature: std::string::String,
|
||||
/// Optional slot number.
|
||||
pub slot: std::option::Option<u64>,
|
||||
/// Optional block time in unix seconds.
|
||||
pub block_time_unix: std::option::Option<i64>,
|
||||
/// Optional source endpoint name.
|
||||
pub source_endpoint_name: std::option::Option<std::string::String>,
|
||||
/// Optional version text.
|
||||
pub version_text: std::option::Option<std::string::String>,
|
||||
/// Optional serialized transaction error JSON.
|
||||
pub err_json: std::option::Option<std::string::String>,
|
||||
/// Optional serialized meta JSON.
|
||||
pub meta_json: std::option::Option<std::string::String>,
|
||||
/// Serialized full transaction JSON.
|
||||
pub transaction_json: std::string::String,
|
||||
/// Creation timestamp.
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
/// Update timestamp.
|
||||
pub updated_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl KbChainTransactionDto {
|
||||
/// Creates a new chain transaction DTO.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
signature: std::string::String,
|
||||
slot: std::option::Option<u64>,
|
||||
block_time_unix: std::option::Option<i64>,
|
||||
source_endpoint_name: std::option::Option<std::string::String>,
|
||||
version_text: std::option::Option<std::string::String>,
|
||||
err_json: std::option::Option<std::string::String>,
|
||||
meta_json: std::option::Option<std::string::String>,
|
||||
transaction_json: std::string::String,
|
||||
) -> Self {
|
||||
let now = chrono::Utc::now();
|
||||
Self {
|
||||
id: None,
|
||||
signature,
|
||||
slot,
|
||||
block_time_unix,
|
||||
source_endpoint_name,
|
||||
version_text,
|
||||
err_json,
|
||||
meta_json,
|
||||
transaction_json,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<crate::KbChainTransactionEntity> for KbChainTransactionDto {
|
||||
type Error = crate::KbError;
|
||||
|
||||
fn try_from(entity: crate::KbChainTransactionEntity) -> Result<Self, Self::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 chain transaction slot '{}' to u64: {}",
|
||||
slot, error
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let created_at_result = chrono::DateTime::parse_from_rfc3339(&entity.created_at);
|
||||
let created_at = match created_at_result {
|
||||
Ok(created_at) => created_at.with_timezone(&chrono::Utc),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot parse chain transaction created_at '{}': {}",
|
||||
entity.created_at, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
let updated_at_result = chrono::DateTime::parse_from_rfc3339(&entity.updated_at);
|
||||
let updated_at = match updated_at_result {
|
||||
Ok(updated_at) => updated_at.with_timezone(&chrono::Utc),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot parse chain transaction updated_at '{}': {}",
|
||||
entity.updated_at, error
|
||||
)));
|
||||
}
|
||||
};
|
||||
Ok(Self {
|
||||
id: Some(entity.id),
|
||||
signature: entity.signature,
|
||||
slot,
|
||||
block_time_unix: entity.block_time_unix,
|
||||
source_endpoint_name: entity.source_endpoint_name,
|
||||
version_text: entity.version_text,
|
||||
err_json: entity.err_json,
|
||||
meta_json: entity.meta_json,
|
||||
transaction_json: entity.transaction_json,
|
||||
created_at,
|
||||
updated_at,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user