0.7.26
This commit is contained in:
@@ -65,6 +65,60 @@ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads one chain instruction by its internal id.
|
||||
pub async fn get_chain_instruction_by_id(
|
||||
database: &crate::KbDatabase,
|
||||
instruction_id: i64,
|
||||
) -> Result<std::option::Option<crate::KbChainInstructionDto>, crate::KbError> {
|
||||
match database.connection() {
|
||||
crate::KbDatabaseConnection::Sqlite(pool) => {
|
||||
let query_result = sqlx::query_as::<sqlx::Sqlite, crate::KbChainInstructionEntity>(
|
||||
r#"
|
||||
SELECT
|
||||
id,
|
||||
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
|
||||
FROM kb_chain_instructions
|
||||
WHERE id = ?
|
||||
LIMIT 1
|
||||
"#,
|
||||
)
|
||||
.bind(instruction_id)
|
||||
.fetch_optional(pool)
|
||||
.await;
|
||||
let entity_option = match query_result {
|
||||
Ok(entity_option) => entity_option,
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Db(format!(
|
||||
"cannot fetch kb_chain_instructions id '{}' on sqlite: {}",
|
||||
instruction_id, error
|
||||
)));
|
||||
},
|
||||
};
|
||||
match entity_option {
|
||||
Some(entity) => {
|
||||
let dto_result = crate::KbChainInstructionDto::try_from(entity);
|
||||
match dto_result {
|
||||
Ok(dto) => return Ok(Some(dto)),
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
},
|
||||
None => return Ok(None),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Lists instructions for one transaction ordered from outer to inner.
|
||||
pub async fn list_chain_instructions_by_transaction_id(
|
||||
database: &crate::KbDatabase,
|
||||
|
||||
Reference in New Issue
Block a user