skar_client_fuel/
types.rs

1use 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    /// Current height of the source hypersync instance
29    pub archive_height: Option<u64>,
30    /// Next block to query for, the responses are paginated so
31    /// the caller should continue the query from this block if they
32    /// didn't get responses up to the to_block they specified in the Query.
33    pub next_block: u64,
34    /// Total time it took the hypersync instance to execute the query.
35    pub total_execution_time: u64,
36    /// Response data
37    pub data: QueryResponseData,
38}
39
40#[derive(Debug, Clone)]
41pub struct QueryResponseTyped {
42    /// Current height of the source hypersync instance
43    pub archive_height: Option<u64>,
44    /// Next block to query for, the responses are paginated so
45    /// the caller should continue the query from this block if they
46    /// didn't get responses up to the to_block they specified in the Query.
47    pub next_block: u64,
48    /// Total time it took the hypersync instance to execute the query.
49    pub total_execution_time: u64,
50    /// Response data
51    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    /// Current height of the source hypersync instance
84    pub archive_height: Option<u64>,
85    /// Next block to query for, the responses are paginated so
86    /// the caller should continue the query from this block if they
87    /// didn't get responses up to the to_block they specified in the Query.
88    pub next_block: u64,
89    /// Total time it took the hypersync instance to execute the query.
90    pub total_execution_time: u64,
91    /// Response data
92    pub data: Vec<LogContext>,
93}
94
95/// Contains all the fields needed for decoding plus some additional fields
96/// for context.
97#[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}