skar_client_fuel/
types.rs1use crate::ArrowChunk;
2use anyhow::{anyhow, Result};
3use arrow2::datatypes::SchemaRef;
4use skar_format::{
5 BlockHeader, Data, Hash, Input, Output, Receipt, ReceiptType, Transaction, UInt,
6};
7
8#[derive(Debug, Clone)]
9pub struct QueryResponseData {
10 pub blocks: Vec<ArrowBatch>,
11 pub transactions: Vec<ArrowBatch>,
12 pub receipts: Vec<ArrowBatch>,
13 pub inputs: Vec<ArrowBatch>,
14 pub outputs: Vec<ArrowBatch>,
15}
16
17#[derive(Debug, Clone)]
18pub struct QueryResponseDataTyped {
19 pub blocks: Vec<BlockHeader>,
20 pub transactions: Vec<Transaction>,
21 pub receipts: Vec<Receipt>,
22 pub inputs: Vec<Input>,
23 pub outputs: Vec<Output>,
24}
25
26#[derive(Debug, Clone)]
27pub struct QueryResponse {
28 pub archive_height: Option<u64>,
30 pub next_block: u64,
34 pub total_execution_time: u64,
36 pub data: QueryResponseData,
38}
39
40#[derive(Debug, Clone)]
41pub struct QueryResponseTyped {
42 pub archive_height: Option<u64>,
44 pub next_block: u64,
48 pub total_execution_time: u64,
50 pub data: QueryResponseDataTyped,
52}
53
54#[derive(Debug, Clone)]
55pub struct ArrowBatch {
56 pub chunk: ArrowChunk,
57 pub schema: SchemaRef,
58}
59
60impl ArrowBatch {
61 pub fn column<T: 'static>(&self, name: &str) -> Result<&T> {
62 match self
63 .schema
64 .fields
65 .iter()
66 .enumerate()
67 .find(|(_, f)| f.name == name)
68 {
69 Some((idx, _)) => {
70 let col = self.chunk.columns()[idx]
71 .as_any()
72 .downcast_ref::<T>()
73 .unwrap();
74 Ok(col)
75 }
76 None => Err(anyhow!("field {} not found in schema", name)),
77 }
78 }
79}
80
81#[derive(Debug, Clone)]
82pub struct LogResponse {
83 pub archive_height: Option<u64>,
85 pub next_block: u64,
89 pub total_execution_time: u64,
91 pub data: Vec<LogContext>,
93}
94
95#[derive(Debug, Clone)]
98pub struct LogContext {
99 pub block_height: UInt,
100 pub tx_id: Hash,
101 pub receipt_index: UInt,
102 pub receipt_type: ReceiptType,
103 pub contract_id: Option<Hash>,
104 pub root_contract_id: Option<Hash>,
105 pub ra: Option<UInt>,
106 pub rb: Option<UInt>,
107 pub rc: Option<UInt>,
108 pub rd: Option<UInt>,
109 pub pc: Option<UInt>,
110 pub is: Option<UInt>,
111 pub ptr: Option<UInt>,
112 pub len: Option<UInt>,
113 pub digest: Option<Hash>,
114 pub data: Option<Data>,
115}
116
117impl From<Receipt> for LogContext {
118 fn from(value: Receipt) -> Self {
119 Self {
120 block_height: value.block_height,
121 tx_id: value.tx_id,
122 receipt_index: value.receipt_index,
123 receipt_type: value.receipt_type,
124 contract_id: value.contract_id,
125 root_contract_id: value.root_contract_id,
126 ra: value.ra,
127 rb: value.rb,
128 rc: value.rc,
129 rd: value.rd,
130 pc: value.pc,
131 is: value.is,
132 ptr: value.ptr,
133 len: value.len,
134 digest: value.digest,
135 data: value.data,
136 }
137 }
138}