Skip to content

Commit

Permalink
feat: status & fee in user ops list
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Dec 20, 2023
1 parent 970ba2e commit 68af319
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ fn build_user_op_model(
.first()
.map_or(0, |l| l.log_index.map_or(0, |v| v.as_u64())),
user_logs_count: user_logs_count as u64,
fee: user_op_event.actual_gas_cost,

consensus: None,
timestamp: None,
Expand Down Expand Up @@ -496,12 +497,13 @@ mod tests {
indexer.handle_tx(tx_hash).await.unwrap();

let op_hash =
H256::from_str("2D5F7A884E9A99CFE2445DB2AF140A8851FBD860852B668F2F199190F68ADF87")
H256::from_str("0x2d5f7a884e9a99cfe2445db2af140a8851fbd860852b668f2f199190f68adf87")
.unwrap();
let user_op = repository::user_op::find_user_op_by_op_hash(&db, op_hash)
.await
.unwrap()
.unwrap();
assert_eq!(user_op, Some(UserOp {
assert_eq!(user_op, UserOp {
hash: op_hash,
sender: Address::from_str("0xeae4d85f7733ad522f601ce7ad4f595704a2d677").unwrap(),
nonce: H256::zero(),
Expand Down Expand Up @@ -533,8 +535,9 @@ mod tests {
sponsor_type: SponsorType::WalletDeposit,
user_logs_start_index: 268,
user_logs_count: 1,
fee: U256::from(6172156091732370u64),
consensus: None,
timestamp: None,
}))
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use blockscout_db::entity::blocks;
use entity::user_operations::{ActiveModel, Column, Entity, Model};
use ethers::prelude::{Address, H256};
use sea_orm::{
prelude::DateTime,
prelude::{BigDecimal, DateTime},
sea_query::{Expr, IntoCondition, OnConflict},
ActiveValue, ColumnTrait, ConnectionTrait, DatabaseConnection, DbBackend, EntityTrait,
FromQueryResult, IntoSimpleExpr, Iterable, JoinType, QueryFilter, QueryOrder, QuerySelect,
Expand All @@ -22,6 +22,9 @@ pub struct ListUserOpDB {
pub sender: Vec<u8>,
pub transaction_hash: Vec<u8>,
pub timestamp: DateTime,
pub status: bool,
pub gas_price: BigDecimal,
pub gas_used: BigDecimal,
}

pub fn user_ops_blocks_rel() -> RelationDef {
Expand Down Expand Up @@ -94,6 +97,9 @@ pub async fn list_user_ops(
Column::BlockNumber,
Column::Sender,
Column::TransactionHash,
Column::Status,
Column::GasPrice,
Column::GasUsed,
])
.column(blocks::Column::Timestamp)
.join_rev(JoinType::Join, user_ops_blocks_rel());
Expand Down Expand Up @@ -213,6 +219,7 @@ WHERE logs.address_hash = $1
mod tests {
use super::*;
use crate::repository::tests::get_shared_db;
use ethers::prelude::U256;
use pretty_assertions::assert_eq;
use std::str::FromStr;

Expand Down Expand Up @@ -307,13 +314,17 @@ mod tests {
sender: Address::from_low_u64_be(0x0502),
transaction_hash: H256::from_low_u64_be(0x0504),
timestamp: 1704067200,
status: true,
fee: U256::from(56001575011025u64),
},
ListUserOp {
hash: H256::from_low_u64_be(0x0501),
block_number: 0,
sender: Address::from_low_u64_be(0x0502),
transaction_hash: H256::from_low_u64_be(0x0504),
timestamp: 1704067200,
status: true,
fee: U256::from(56000075000025u64),
}
]
);
Expand Down
10 changes: 10 additions & 0 deletions user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ethers::prelude::{Address, Bytes, H256, U256};
use ethers_core::{abi::AbiEncode, utils::to_checksum};
use num_traits::cast::ToPrimitive;
use sea_orm::{prelude::BigDecimal, ActiveEnum};
use std::ops::Mul;

#[derive(Clone, Debug, PartialEq)]
pub struct UserOp {
Expand Down Expand Up @@ -39,6 +40,7 @@ pub struct UserOp {
pub sponsor_type: SponsorType,
pub user_logs_start_index: u64,
pub user_logs_count: u64,
pub fee: U256,

pub consensus: Option<bool>,
pub timestamp: Option<u64>,
Expand All @@ -51,6 +53,8 @@ pub struct ListUserOp {
pub sender: Address,
pub transaction_hash: H256,
pub timestamp: u64,
pub status: bool,
pub fee: U256,
}

impl From<UserOp> for Model {
Expand Down Expand Up @@ -127,6 +131,7 @@ impl From<Model> for UserOp {
sponsor_type: v.sponsor_type.clone(),
user_logs_start_index: v.user_logs_start_index as u64,
user_logs_count: v.user_logs_count as u64,
fee: U256::from(v.gas_price.mul(v.gas_used).to_u128().unwrap_or(0)),

consensus: None,
timestamp: None,
Expand Down Expand Up @@ -168,6 +173,7 @@ impl From<UserOp> for user_ops_indexer_proto::blockscout::user_ops_indexer::v1::
sponsor_type: v.sponsor_type.to_value().to_string(),
user_logs_start_index: v.user_logs_start_index,
user_logs_count: v.user_logs_count,
fee: v.fee.to_string(),

consensus: v.consensus,
timestamp: v.timestamp,
Expand All @@ -183,6 +189,8 @@ impl From<ListUserOpDB> for ListUserOp {
sender: Address::from_slice(&v.sender),
transaction_hash: H256::from_slice(&v.transaction_hash),
timestamp: v.timestamp.timestamp() as u64,
status: v.status,
fee: U256::from(v.gas_price.mul(v.gas_used).to_u128().unwrap_or(0)),
}
}
}
Expand All @@ -195,6 +203,8 @@ impl From<ListUserOp> for user_ops_indexer_proto::blockscout::user_ops_indexer::
transaction_hash: v.transaction_hash.encode_hex(),
address: to_checksum(&v.sender, None),
timestamp: v.timestamp,
status: v.status,
fee: v.fee.to_string(),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ message UserOp {
string sponsor_type = 29;
uint64 user_logs_start_index = 30;
uint64 user_logs_count = 31;
string fee = 32;

optional bool consensus = 32;
optional uint64 timestamp = 33;
optional bool consensus = 33;
optional uint64 timestamp = 34;
}

message ListUserOp {
Expand All @@ -187,4 +188,6 @@ message ListUserOp {
string transaction_hash = 3;
string address = 4;
uint64 timestamp = 5;
bool status = 6;
string fee = 7;
}
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ definitions:
timestamp:
type: string
format: uint64
status:
type: boolean
fee:
type: string
v1ListUserOpsResponse:
type: object
properties:
Expand Down Expand Up @@ -557,6 +561,8 @@ definitions:
userLogsCount:
type: string
format: uint64
fee:
type: string
consensus:
type: boolean
timestamp:
Expand Down

0 comments on commit 68af319

Please sign in to comment.