diff --git a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/indexer.rs b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/indexer.rs index 2792698a1..cc555afef 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/indexer.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/indexer.rs @@ -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, @@ -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(), @@ -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, - })) + }) } } diff --git a/user-ops-indexer/user-ops-indexer-logic/src/repository/user_op.rs b/user-ops-indexer/user-ops-indexer-logic/src/repository/user_op.rs index 743583592..671765290 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/repository/user_op.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/repository/user_op.rs @@ -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, @@ -22,6 +22,9 @@ pub struct ListUserOpDB { pub sender: Vec, pub transaction_hash: Vec, pub timestamp: DateTime, + pub status: bool, + pub gas_price: BigDecimal, + pub gas_used: BigDecimal, } pub fn user_ops_blocks_rel() -> RelationDef { @@ -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()); @@ -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; @@ -307,6 +314,8 @@ 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), @@ -314,6 +323,8 @@ mod tests { sender: Address::from_low_u64_be(0x0502), transaction_hash: H256::from_low_u64_be(0x0504), timestamp: 1704067200, + status: true, + fee: U256::from(56000075000025u64), } ] ); diff --git a/user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs b/user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs index 63f1e8074..9ea7b56e3 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/types/user_op.rs @@ -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 { @@ -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, pub timestamp: Option, @@ -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 for Model { @@ -127,6 +131,7 @@ impl From 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, @@ -168,6 +173,7 @@ impl From 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, @@ -183,6 +189,8 @@ impl From 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)), } } } @@ -195,6 +203,8 @@ impl From 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(), } } } diff --git a/user-ops-indexer/user-ops-indexer-proto/proto/user-ops-indexer.proto b/user-ops-indexer/user-ops-indexer-proto/proto/user-ops-indexer.proto index df6118749..ff2c8afaf 100644 --- a/user-ops-indexer/user-ops-indexer-proto/proto/user-ops-indexer.proto +++ b/user-ops-indexer/user-ops-indexer-proto/proto/user-ops-indexer.proto @@ -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 { @@ -187,4 +188,6 @@ message ListUserOp { string transaction_hash = 3; string address = 4; uint64 timestamp = 5; + bool status = 6; + string fee = 7; } diff --git a/user-ops-indexer/user-ops-indexer-proto/swagger/user-ops-indexer.swagger.yaml b/user-ops-indexer/user-ops-indexer-proto/swagger/user-ops-indexer.swagger.yaml index f19786833..71651d905 100644 --- a/user-ops-indexer/user-ops-indexer-proto/swagger/user-ops-indexer.swagger.yaml +++ b/user-ops-indexer/user-ops-indexer-proto/swagger/user-ops-indexer.swagger.yaml @@ -465,6 +465,10 @@ definitions: timestamp: type: string format: uint64 + status: + type: boolean + fee: + type: string v1ListUserOpsResponse: type: object properties: @@ -557,6 +561,8 @@ definitions: userLogsCount: type: string format: uint64 + fee: + type: string consensus: type: boolean timestamp: