Skip to content

Commit

Permalink
Merge pull request #3 from enviodev/query-tx-type
Browse files Browse the repository at this point in the history
feat: Query tx type
  • Loading branch information
JossDuff authored Jun 6, 2024
2 parents 500b1e2 + b0aee8a commit 93884ef
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 10 deletions.
8 changes: 4 additions & 4 deletions hyperfuel-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperfuel-client"
version = "2.0.0"
version = "2.1.0"
edition = "2021"
description = "client library for Envio's HyperSync support of the Fuel Network"
license = "MIT"
Expand Down Expand Up @@ -35,9 +35,9 @@ alloy-dyn-abi = "0.5.0"
alloy-json-abi = "0.5.0"
xxhash-rust = { version = "0.8", features = ["xxh3"] }

hyperfuel-net-types = { package = "hyperfuel-net-types", path = "../hyperfuel-net-types", version = "2.0.0" }
hyperfuel-format = { package = "hyperfuel-format", path = "../hyperfuel-format", version = "2.0.0" }
hyperfuel-schema = { package = "hyperfuel-schema", path = "../hyperfuel-schema", version = "2.0.0" }
hyperfuel-net-types = { package = "hyperfuel-net-types", path = "../hyperfuel-net-types", version = "3.0.0" }
hyperfuel-format = { package = "hyperfuel-format", path = "../hyperfuel-format", version = "3.0.0" }
hyperfuel-schema = { package = "hyperfuel-schema", path = "../hyperfuel-schema", version = "3.0.0" }

[dependencies.reqwest]
version = "0.11"
Expand Down
23 changes: 21 additions & 2 deletions hyperfuel-client/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ fn receipt_selections_to_filter(
let rc = batch.column::<UInt64Array>("rc").ok();
let rd = batch.column::<UInt64Array>("rd").ok();
let tx_status = batch.column::<UInt8Array>("tx_status").ok();
let tx_type = batch.column::<UInt8Array>("tx_type").ok();

let chunk_len = batch.chunk.len();
let mut filter = unset_bool_array(chunk_len);
Expand All @@ -119,6 +120,7 @@ fn receipt_selections_to_filter(
rc,
rd,
tx_status,
tx_type,
selection,
chunk_len,
);
Expand All @@ -142,6 +144,7 @@ fn receipt_selection_to_filter(
rc: Option<&UInt64Array>,
rd: Option<&UInt64Array>,
tx_status: Option<&UInt8Array>,
tx_type: Option<&UInt8Array>,
selection: &ReceiptSelection,
chunk_len: usize,
) -> BooleanArray {
Expand Down Expand Up @@ -214,6 +217,10 @@ fn receipt_selection_to_filter(
);
}

if !selection.tx_type.is_empty() && tx_type.is_some() {
filter = compute::boolean::and(&filter, &in_set_u8(tx_type.unwrap(), &selection.tx_type));
}

filter
}

Expand Down Expand Up @@ -269,14 +276,15 @@ fn input_selections_to_filter(
let recipient = batch.column::<BinaryArray<i32>>("recipient").ok();
let input_type = batch.column::<UInt8Array>("input_type").ok();
let tx_status = batch.column::<UInt8Array>("tx_status").ok();
let tx_type = batch.column::<UInt8Array>("tx_type").ok();

let chunk_len = batch.chunk.len();
let mut filter = unset_bool_array(chunk_len);

for selection in selections.iter() {
let selection = input_selection_to_filter(
owner, asset_id, contract, sender, recipient, input_type, tx_status, selection,
chunk_len,
owner, asset_id, contract, sender, recipient, input_type, tx_status, tx_type,
selection, chunk_len,
);
filter = compute::boolean::or(&filter, &selection);
}
Expand All @@ -293,6 +301,7 @@ fn input_selection_to_filter(
recipient: Option<&BinaryArray<i32>>,
input_type: Option<&UInt8Array>,
tx_status: Option<&UInt8Array>,
tx_type: Option<&UInt8Array>,
selection: &InputSelection,
chunk_len: usize,
) -> BooleanArray {
Expand Down Expand Up @@ -335,6 +344,10 @@ fn input_selection_to_filter(
);
}

if !selection.tx_type.is_empty() && tx_type.is_some() {
filter = compute::boolean::and(&filter, &in_set_u8(tx_type.unwrap(), &selection.tx_type));
}

filter
}

Expand All @@ -347,6 +360,7 @@ fn output_selections_to_filter(
let contract = batch.column::<BinaryArray<i32>>("contract").ok();
let output_type = batch.column::<UInt8Array>("output_type").ok();
let tx_status = batch.column::<UInt8Array>("tx_status").ok();
let tx_type = batch.column::<UInt8Array>("tx_type").ok();

let chunk_len = batch.chunk.len();
let mut filter = unset_bool_array(chunk_len);
Expand All @@ -358,6 +372,7 @@ fn output_selections_to_filter(
contract,
output_type,
tx_status,
tx_type,
selection,
chunk_len,
);
Expand All @@ -373,6 +388,7 @@ fn output_selection_to_filter(
contract: Option<&BinaryArray<i32>>,
output_type: Option<&UInt8Array>,
tx_status: Option<&UInt8Array>,
tx_type: Option<&UInt8Array>,
selection: &OutputSelection,
chunk_len: usize,
) -> BooleanArray {
Expand Down Expand Up @@ -404,6 +420,9 @@ fn output_selection_to_filter(
&in_set_u8(tx_status.unwrap(), &selection.tx_status),
);
}
if !selection.tx_type.is_empty() && tx_type.is_some() {
filter = compute::boolean::and(&filter, &in_set_u8(tx_type.unwrap(), &selection.tx_type));
}

filter
}
16 changes: 16 additions & 0 deletions hyperfuel-client/src/from_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@ impl FromArrow for Receipt {
}
}

if let Ok(col) = batch.column::<UInt8Array>("tx_type") {
for (target, val) in out.iter_mut().zip(col.values_iter()) {
target.tx_type = TransactionType::from_u8(*val).unwrap();
}
}

if let Ok(col) = batch.column::<UInt64Array>("block_height") {
for (target, &val) in out.iter_mut().zip(col.values_iter()) {
target.block_height = val.into();
Expand Down Expand Up @@ -622,6 +628,11 @@ impl FromArrow for Input {
target.tx_status = TransactionStatus::from_u8(*val).unwrap();
}
}
if let Ok(col) = batch.column::<UInt8Array>("tx_type") {
for (target, val) in out.iter_mut().zip(col.values_iter()) {
target.tx_type = TransactionType::from_u8(*val).unwrap();
}
}
if let Ok(col) = batch.column::<BinaryArray<i32>>("utxo_id") {
for (target, val) in out.iter_mut().zip(col.iter()) {
target.utxo_id = val.map(|v| v.try_into().unwrap());
Expand Down Expand Up @@ -736,6 +747,11 @@ impl FromArrow for Output {
target.tx_status = TransactionStatus::from_u8(*val).unwrap();
}
}
if let Ok(col) = batch.column::<UInt8Array>("tx_type") {
for (target, val) in out.iter_mut().zip(col.values_iter()) {
target.tx_type = TransactionType::from_u8(*val).unwrap();
}
}
if let Ok(col) = batch.column::<BinaryArray<i32>>("to") {
for (target, val) in out.iter_mut().zip(col.iter()) {
target.to = val.map(|v| v.try_into().unwrap());
Expand Down
18 changes: 18 additions & 0 deletions hyperfuel-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ fn add_selections_to_field_selection(query: &mut Query) -> Query {
if !selection.rd.is_empty() {
query.field_selection.receipt.insert("rd".into());
}
if !selection.tx_status.is_empty() {
query.field_selection.receipt.insert("tx_status".into());
}
if !selection.tx_type.is_empty() {
query.field_selection.receipt.insert("tx_type".into());
}
});

query.inputs.iter_mut().for_each(|selection| {
Expand All @@ -430,6 +436,12 @@ fn add_selections_to_field_selection(query: &mut Query) -> Query {
if !selection.input_type.is_empty() {
query.field_selection.input.insert("input_type".into());
}
if !selection.tx_status.is_empty() {
query.field_selection.input.insert("tx_status".into());
}
if !selection.tx_type.is_empty() {
query.field_selection.receipt.insert("tx_type".into());
}
});

query.outputs.iter_mut().for_each(|selection| {
Expand All @@ -445,6 +457,12 @@ fn add_selections_to_field_selection(query: &mut Query) -> Query {
if !selection.output_type.is_empty() {
query.field_selection.output.insert("output_type".into());
}
if !selection.tx_status.is_empty() {
query.field_selection.output.insert("tx_status".into());
}
if !selection.tx_type.is_empty() {
query.field_selection.receipt.insert("tx_type".into());
}
});

query.clone()
Expand Down
2 changes: 1 addition & 1 deletion hyperfuel-format/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperfuel-format"
version = "2.0.0"
version = "3.0.0"
edition = "2021"
description = "fuel network format library"
license = "MIT"
Expand Down
6 changes: 6 additions & 0 deletions hyperfuel-format/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ pub struct Receipt {
pub tx_id: Hash,
/// The status type of the transaction this receipt originated from
pub tx_status: TransactionStatus,
/// The type of the transaction this receipt originated from
pub tx_type: TransactionType,
/// block that the receipt originated in
pub block_height: UInt,
/// The value of the program counter register $pc, which is the memory address of the current instruction.
Expand Down Expand Up @@ -221,6 +223,8 @@ pub struct Input {
pub tx_id: Hash,
/// The status type of the transaction this input originated from
pub tx_status: TransactionStatus,
/// The type of the transaction this input originated from
pub tx_type: TransactionType,
/// block that the input originated in
pub block_height: UInt,
/// InputCoin, InputContract, or InputMessage
Expand Down Expand Up @@ -269,6 +273,8 @@ pub struct Output {
pub tx_id: Hash,
/// The status type of the transaction this output originated from
pub tx_status: TransactionStatus,
/// The type of the transaction this output originated from
pub tx_type: TransactionType,
/// block that the output originated in
pub block_height: UInt,
/// CoinOutput, ContractOutput, ChangeOutput, VariableOutput, or ContractCreated
Expand Down
4 changes: 2 additions & 2 deletions hyperfuel-net-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperfuel-net-types"
version = "2.0.0"
version = "3.0.0"
edition = "2021"
description = "hyperfuel types for transport over network"
license = "MIT"
Expand All @@ -10,7 +10,7 @@ capnp = "0.18"
serde = { version = "1", features = ["derive"] }
arrayvec = { version = "0.7", features = ["serde"] }

hyperfuel-format = { package = "hyperfuel-format", path = "../hyperfuel-format", version = "2.0.0" }
hyperfuel-format = { package = "hyperfuel-format", path = "../hyperfuel-format", version = "3.0.0" }

[build-dependencies]
capnpc = "0.18"
6 changes: 6 additions & 0 deletions hyperfuel-net-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct ReceiptSelection {
pub rd: Vec<u64>,
#[serde(default)]
pub tx_status: Vec<u8>,
#[serde(default)]
pub tx_type: Vec<u8>,
}

#[derive(Default, Serialize, Deserialize, Clone, Debug)]
Expand All @@ -53,6 +55,8 @@ pub struct InputSelection {
pub input_type: Vec<u8>,
#[serde(default)]
pub tx_status: Vec<u8>,
#[serde(default)]
pub tx_type: Vec<u8>,
}

#[derive(Default, Serialize, Deserialize, Clone, Debug)]
Expand All @@ -67,6 +71,8 @@ pub struct OutputSelection {
pub output_type: Vec<u8>,
#[serde(default)]
pub tx_status: Vec<u8>,
#[serde(default)]
pub tx_type: Vec<u8>,
}

#[derive(Default, Serialize, Deserialize, Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion hyperfuel-schema/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperfuel-schema"
version = "2.0.0"
version = "3.0.0"
edition = "2021"
description = "schema utilities for hyperfuel"
license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions hyperfuel-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub fn receipt() -> SchemaRef {
Field::new("root_contract_id", DataType::Binary, true),
Field::new("tx_id", DataType::Binary, false),
Field::new("tx_status", DataType::UInt8, false), // new
Field::new("tx_type", DataType::UInt8, false), // new
Field::new("block_height", DataType::UInt64, false),
Field::new("pc", DataType::UInt64, true),
Field::new("is", DataType::UInt64, true),
Expand Down Expand Up @@ -147,6 +148,7 @@ pub fn input() -> SchemaRef {
// for mapping
Field::new("tx_id", DataType::Binary, false),
Field::new("tx_status", DataType::UInt8, false), // new
Field::new("tx_type", DataType::UInt8, false), // new
Field::new("block_height", DataType::UInt64, false),
Field::new("input_type", DataType::UInt8, false),
Field::new("utxo_id", DataType::Binary, true),
Expand Down Expand Up @@ -175,6 +177,7 @@ pub fn output() -> SchemaRef {
// for mapping
Field::new("tx_id", DataType::Binary, false),
Field::new("tx_status", DataType::UInt8, false), // new
Field::new("tx_type", DataType::UInt8, false), // new
Field::new("block_height", DataType::UInt64, false),
Field::new("output_type", DataType::UInt8, false),
Field::new("to", DataType::Binary, true),
Expand Down

0 comments on commit 93884ef

Please sign in to comment.