Skip to content

Commit 7299960

Browse files
committed
add tempo fields
1 parent cb58e8f commit 7299960

4 files changed

Lines changed: 39 additions & 19 deletions

File tree

be/src/query.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ impl UserQuery {
460460
if let Some(lit) = expr_to_bytes(right) {
461461
if let Some(param) = self.get_param(left) {
462462
*right = match param {
463+
abi::Parameter::Tuple { .. } => right.clone(),
463464
abi::Parameter::Address { .. } | abi::Parameter::Uint { .. } => {
464465
ast::Expr::Value(ast::Value::SingleQuotedString(format!(
465466
r#"\x{}"#,
@@ -596,24 +597,15 @@ impl UserQuery {
596597
ast::Expr::IsNotFalse(_) => Ok(()),
597598
ast::Expr::IsTrue(_) => Ok(()),
598599
ast::Expr::IsNotTrue(_) => Ok(()),
599-
ast::Expr::IsNull(_) => Ok(()),
600-
ast::Expr::IsNotNull(_) => Ok(()),
600+
ast::Expr::IsNull(expr) => self.validate_expression(expr),
601+
ast::Expr::IsNotNull(expr) => self.validate_expression(expr),
601602
ast::Expr::Ceil { expr, field: _ } => self.validate_expression(expr),
602603
ast::Expr::Floor { expr, field: _ } => self.validate_expression(expr),
603604
ast::Expr::Value(_) => Ok(()),
604605
ast::Expr::Exists { subquery, .. } => self.validate_query(subquery),
605606
ast::Expr::Subquery(subquery) => self.validate_query(subquery),
606607
ast::Expr::Tuple(exprs) => self.validate_expressions(exprs),
607608
ast::Expr::UnaryOp { expr, .. } => self.validate_expression(expr),
608-
ast::Expr::BinaryOp {
609-
left,
610-
right,
611-
op: ast::BinaryOperator::LongArrow | ast::BinaryOperator::Arrow,
612-
..
613-
} => {
614-
self.validate_expression(left)?;
615-
self.validate_expression(right)
616-
}
617609
ast::Expr::BinaryOp { left, right, .. } => {
618610
self.set_chain(left, right);
619611
self.rewrite_binary_expr(left, right)?;
@@ -658,7 +650,7 @@ impl UserQuery {
658650

659651
fn validate_function(&mut self, function: &mut ast::Function) -> Result<(), api::Error> {
660652
let name = function.name.to_string().to_lowercase();
661-
const VALID_FUNCS: [&str; 14] = [
653+
const VALID_FUNCS: [&str; 15] = [
662654
"coalesce",
663655
"min",
664656
"max",
@@ -673,6 +665,7 @@ impl UserQuery {
673665
"abi_uint",
674666
"abi_int",
675667
"abi_string",
668+
"jsonb_path_query_array",
676669
];
677670
if !VALID_FUNCS.contains(&name.as_str()) {
678671
return no!(format!(r#"'{}' function"#, name));
@@ -810,6 +803,9 @@ fn bytes_to_expr(bytes: Vec<u8>, to: ast::DataType) -> Result<ast::Expr, api::Er
810803
value: s,
811804
})
812805
}
806+
ast::DataType::JSONB => Ok(ast::Expr::Value(ast::Value::SingleQuotedString(
807+
String::from_utf8(bytes).map_err(|_| api::Error::User("invalid JSONB".to_string()))?,
808+
))),
813809
_ => Err(api::Error::User(format!(
814810
"unable to convert {bytes:?} to {to:?}",
815811
))),
@@ -831,9 +827,10 @@ fn base_column_type(id: &Ident) -> Option<ast::DataType> {
831827

832828
// Txs
833829
"idx" | "type" => Some(ast::DataType::Int64),
834-
"from" | "to" | "input" => Some(ast::DataType::Bytea),
830+
"from" | "to" | "input" | "fee_token" => Some(ast::DataType::Bytea),
835831
"value" => Some(ast::DataType::Numeric(ast::ExactNumberInfo::None)),
836832
"gas" | "gas_price" => Some(ast::DataType::Numeric(ast::ExactNumberInfo::None)),
833+
"calls" => Some(ast::DataType::JSONB),
837834

838835
// Logs
839836
"tx_hash" | "address" | "topics" | "data" => Some(ast::DataType::Bytea),

be/src/sql/schema.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ create table if not exists txs (
3030
"from" bytea not null,
3131
"to" bytea not null,
3232
input bytea not null,
33-
value numeric not null
33+
value numeric not null,
34+
fee_token bytea,
35+
calls jsonb
3436
) partition by list(chain);
3537

3638
create table if not exists logs (

be/src/sync.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@ pub async fn copy_txs(
551551
"from",
552552
"to",
553553
input,
554-
value
554+
value,
555+
fee_token,
556+
calls
555557
)
556558
from stdin binary
557559
"#;
@@ -572,6 +574,8 @@ pub async fn copy_txs(
572574
tokio_postgres::types::Type::BYTEA,
573575
tokio_postgres::types::Type::BYTEA,
574576
tokio_postgres::types::Type::NUMERIC,
577+
tokio_postgres::types::Type::BYTEA,
578+
tokio_postgres::types::Type::JSONB,
575579
],
576580
);
577581
pin_mut!(writer);
@@ -595,6 +599,11 @@ pub async fn copy_txs(
595599
&tx.to.unwrap_or_default().to_vec(),
596600
&tx.input.to_vec(),
597601
&tx.value,
602+
&tx.fee_token.as_ref().map(|a| a.to_vec()),
603+
&tx.calls
604+
.as_ref()
605+
.filter(|v| !v.is_empty())
606+
.map(|v| tokio_postgres::types::Json(v.as_slice())),
598607
])
599608
.await?;
600609
}

shared/src/jrpc.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use alloy::primitives::{Address, BlockHash, Bytes, FixedBytes, U256, U64};
22
use itertools::Itertools;
3-
use serde::Deserialize;
3+
use serde::{Deserialize, Serialize};
44

55
use std::{fmt, time::Duration};
66

@@ -41,6 +41,14 @@ pub struct Log {
4141
pub data: Bytes,
4242
}
4343

44+
#[derive(Serialize, Deserialize, Debug, Clone)]
45+
pub struct Call {
46+
pub from: Option<Address>,
47+
pub to: Option<Address>,
48+
pub value: Option<U256>,
49+
pub data: Option<Bytes>,
50+
}
51+
4452
#[derive(Deserialize, Debug)]
4553
pub struct Tx {
4654
#[serde(rename = "type")]
@@ -61,6 +69,9 @@ pub struct Tx {
6169
pub gas: U256,
6270
#[serde(rename = "gasPrice")]
6371
pub gas_price: Option<U256>,
72+
pub calls: Option<Vec<Call>>,
73+
#[serde(rename = "feeToken")]
74+
pub fee_token: Option<Address>,
6475
}
6576

6677
#[derive(Deserialize, Debug)]
@@ -115,6 +126,7 @@ impl Client {
115126
}
116127
}
117128

129+
#[tracing::instrument(level="info" skip_all)]
118130
pub async fn chain_id(&self) -> Result<U64, Error> {
119131
let request = serde_json::json!({
120132
"id": 1,
@@ -196,13 +208,13 @@ impl Client {
196208
.collect())
197209
}
198210

199-
#[tracing::instrument(level="info" skip_all, fields(number))]
200-
pub async fn block(&self, param: String) -> Result<Block, Error> {
211+
#[tracing::instrument(level="info" skip_all, fields(number = %number))]
212+
pub async fn block(&self, number: String) -> Result<Block, Error> {
201213
let request = serde_json::json!({
202214
"id": "1",
203215
"jsonrpc": "2.0",
204216
"method": "eth_getBlockByNumber",
205-
"params": [param, true],
217+
"params": [number, true],
206218
});
207219
let response: RpcEither<Block> = self
208220
.http_client

0 commit comments

Comments
 (0)