Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[USER_OPS_INDEXER] frontend fixes #742

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions user-ops-indexer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions user-ops-indexer/user-ops-indexer-logic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
ethers = { version = "2.0.11", features = ["ws"] }
num-traits = "0.2.17"
itertools = "0.11.0"
chrono = "0.4.31"

[dev-dependencies]
async-trait = "0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ impl<'a, C: PubsubClient> IndexerV06<'a, C> {
.filter_map(|(j, (raw_user_op, logs))| {
match build_user_op_model(
bundler,
i as u64,
j as u64,
i as u32,
j as u32,
raw_user_op,
logs,
&tx_deposits,
Expand Down Expand Up @@ -322,8 +322,8 @@ impl<'a, C: PubsubClient> IndexerV06<'a, C> {

fn build_user_op_model(
bundler: Address,
bundle_index: u64,
index: u64,
bundle_index: u32,
index: u32,
raw_user_op: RawUserOperation,
logs: &[Log],
tx_deposits: &[DepositedFilter],
Expand Down Expand Up @@ -411,8 +411,8 @@ fn build_user_op_model(
sponsor_type,
user_logs_start_index: logs
.first()
.map_or(0, |l| l.log_index.map_or(0, |v| v.as_u64())),
user_logs_count: user_logs_count as u64,
.map_or(0, |l| l.log_index.map_or(0, |v| v.as_u32())),
user_logs_count: user_logs_count as u32,
fee: user_op_event.actual_gas_cost,

consensus: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ mod tests {
factory: Some(Address::from_low_u64_be(0xf1)),
creation_transaction_hash: Some(H256::from_low_u64_be(0x3204)),
creation_op_hash: Some(H256::from_low_u64_be(0x3201)),
creation_timestamp: Some(1704067260),
creation_timestamp: Some("2024-01-01T00:01:00.000000Z".to_string()),
total_ops: 100,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub async fn list_bundles(
db: &DatabaseConnection,
bundler_filter: Option<Address>,
entry_point_filter: Option<Address>,
page_token: Option<(u64, H256, u64)>,
page_token: Option<(u64, H256, u32)>,
limit: u64,
) -> Result<(Vec<Bundle>, Option<(u64, H256, u64)>), anyhow::Error> {
) -> Result<(Vec<Bundle>, Option<(u64, H256, u32)>), anyhow::Error> {
let page_token = page_token.unwrap_or((i64::MAX as u64, H256::zero(), 0));
let bundles: Vec<Bundle> = BundleDB::find_by_statement(Statement::from_sql_and_values(
db.get_database_backend(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ pub async fn find_user_op_by_op_hash(
let user_op = Model::from_query_result(&res, "")?;
let mut user_op = UserOp::from(user_op);
user_op.consensus = res.try_get("", "consensus")?;
user_op.timestamp = res
.try_get::<Option<DateTime>>("", "timestamp")?
.map(|t| t.timestamp() as u64);
user_op.timestamp = res.try_get::<Option<DateTime>>("", "timestamp")?.map(|t| {
t.and_utc()
.to_rfc3339_opts(chrono::SecondsFormat::Micros, true)
});
Some(user_op)
}
};
Expand All @@ -84,7 +85,7 @@ pub async fn list_user_ops(
factory_filter: Option<Address>,
tx_hash_filter: Option<H256>,
entry_point_filter: Option<Address>,
bundle_index_filter: Option<u64>,
bundle_index_filter: Option<u32>,
block_number_filter: Option<u64>,
page_token: Option<(u64, H256)>,
limit: u64,
Expand Down Expand Up @@ -318,7 +319,7 @@ mod tests {
block_number: 0,
sender: Address::from_low_u64_be(0x0502),
transaction_hash: H256::from_low_u64_be(0x0504),
timestamp: 1704067200,
timestamp: "2024-01-01T00:00:00.000000Z".to_string(),
status: true,
fee: U256::from(56001575011025u64),
},
Expand All @@ -327,7 +328,7 @@ mod tests {
block_number: 0,
sender: Address::from_low_u64_be(0x0502),
transaction_hash: H256::from_low_u64_be(0x0504),
timestamp: 1704067200,
timestamp: "2024-01-01T00:00:00.000000Z".to_string(),
status: true,
fee: U256::from(56000075000025u64),
}
Expand Down
7 changes: 5 additions & 2 deletions user-ops-indexer/user-ops-indexer-logic/src/types/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Account {
pub factory: Option<Address>,
pub creation_transaction_hash: Option<H256>,
pub creation_op_hash: Option<H256>,
pub creation_timestamp: Option<u64>,
pub creation_timestamp: Option<String>,
pub total_ops: u32,
}

Expand All @@ -20,7 +20,10 @@ impl From<AccountDB> for Account {
factory: v.factory.map(|a| Address::from_slice(&a)),
creation_transaction_hash: v.creation_transaction_hash.map(|a| H256::from_slice(&a)),
creation_op_hash: v.creation_op_hash.map(|a| H256::from_slice(&a)),
creation_timestamp: v.creation_timestamp.map(|t| t.timestamp() as u64),
creation_timestamp: v.creation_timestamp.map(|t| {
t.and_utc()
.to_rfc3339_opts(chrono::SecondsFormat::Micros, true)
}),
total_ops: v.total_ops as u32,
}
}
Expand Down
11 changes: 7 additions & 4 deletions user-ops-indexer/user-ops-indexer-logic/src/types/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ use ethers_core::{abi::AbiEncode, utils::to_checksum};
#[derive(Clone, Debug, PartialEq)]
pub struct Bundle {
pub transaction_hash: H256,
pub bundle_index: u64,
pub bundle_index: u32,
pub block_number: u64,
pub bundler: Address,
pub timestamp: u64,
pub timestamp: String,
pub total_ops: u32,
}

impl From<BundleDB> for Bundle {
fn from(v: BundleDB) -> Self {
Self {
transaction_hash: H256::from_slice(&v.transaction_hash),
bundle_index: v.bundle_index as u64,
bundle_index: v.bundle_index as u32,
block_number: v.block_number as u64,
bundler: Address::from_slice(&v.bundler),
total_ops: v.total_ops as u32,
timestamp: v.timestamp.timestamp() as u64,
timestamp: v
.timestamp
.and_utc()
.to_rfc3339_opts(chrono::SecondsFormat::Micros, true),
}
}
}
Expand Down
45 changes: 32 additions & 13 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 @@ -28,8 +28,8 @@ pub struct UserOp {
pub block_number: u64,
pub block_hash: H256,
pub bundler: Address,
pub bundle_index: u64,
pub index: u64,
pub bundle_index: u32,
pub index: u32,
pub factory: Option<Address>,
pub paymaster: Option<Address>,
pub status: bool,
Expand All @@ -38,12 +38,12 @@ pub struct UserOp {
pub gas_price: U256,
pub gas_used: u64,
pub sponsor_type: SponsorType,
pub user_logs_start_index: u64,
pub user_logs_count: u64,
pub user_logs_start_index: u32,
pub user_logs_count: u32,
pub fee: U256,

pub consensus: Option<bool>,
pub timestamp: Option<u64>,
pub timestamp: Option<String>,
}

#[derive(Clone, Debug, PartialEq)]
Expand All @@ -52,7 +52,7 @@ pub struct ListUserOp {
pub block_number: u64,
pub sender: Address,
pub transaction_hash: H256,
pub timestamp: u64,
pub timestamp: String,
pub status: bool,
pub fee: U256,
}
Expand Down Expand Up @@ -119,8 +119,8 @@ impl From<Model> for UserOp {
block_number: v.block_number as u64,
block_hash: H256::from_slice(&v.block_hash),
bundler: Address::from_slice(&v.bundler),
bundle_index: v.bundle_index as u64,
index: v.index as u64,
bundle_index: v.bundle_index as u32,
index: v.index as u32,
factory: v.factory.clone().map(|a| Address::from_slice(&a)),
paymaster: v.paymaster.clone().map(|a| Address::from_slice(&a)),
status: v.status,
Expand All @@ -129,8 +129,8 @@ impl From<Model> for UserOp {
gas_price: U256::from(v.gas_price.to_u128().unwrap_or(0)),
gas_used: v.gas_used.to_u64().unwrap_or(0),
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,
user_logs_start_index: v.user_logs_start_index as u32,
user_logs_count: v.user_logs_count as u32,
fee: U256::from(v.gas_price.mul(v.gas_used).to_u128().unwrap_or(0)),

consensus: None,
Expand All @@ -145,18 +145,34 @@ impl From<UserOp> for user_ops_indexer_proto::blockscout::user_ops_indexer::v1::
hash: v.hash.encode_hex(),
sender: to_checksum(&v.sender, None),
nonce: v.nonce.encode_hex(),
init_code: v.init_code.map(|b| b.to_string()),
call_data: v.call_data.to_string(),
call_gas_limit: v.call_gas_limit,
verification_gas_limit: v.verification_gas_limit,
pre_verification_gas: v.pre_verification_gas,
max_fee_per_gas: v.max_fee_per_gas.to_string(),
max_priority_fee_per_gas: v.max_priority_fee_per_gas.to_string(),
paymaster_and_data: v.paymaster_and_data.map(|b| b.to_string()),
signature: v.signature.to_string(),
raw: Some(
user_ops_indexer_proto::blockscout::user_ops_indexer::v1::RawUserOp {
sender: to_checksum(&v.sender, None),
nonce: U256::from(v.nonce.as_fixed_bytes()).to_string(),
init_code: v.init_code.map_or("0x".to_string(), |b| b.to_string()),
call_data: v.call_data.to_string(),
call_gas_limit: v.call_gas_limit,
verification_gas_limit: v.verification_gas_limit,
pre_verification_gas: v.pre_verification_gas,
max_fee_per_gas: v.max_fee_per_gas.to_string(),
max_priority_fee_per_gas: v.max_priority_fee_per_gas.to_string(),
paymaster_and_data: v
.paymaster_and_data
.map_or("0x".to_string(), |b| b.to_string()),
signature: v.signature.to_string(),
},
),
aggregator: v.aggregator.map(|a| to_checksum(&a, None)),
aggregator_signature: v.aggregator_signature.map(|b| b.to_string()),
entry_point: to_checksum(&v.entry_point, None),
entry_point_version: "v0.6".to_string(),
transaction_hash: v.transaction_hash.encode_hex(),
block_number: v.block_number,
block_hash: v.block_hash.encode_hex(),
Expand Down Expand Up @@ -188,7 +204,10 @@ impl From<ListUserOpDB> for ListUserOp {
block_number: v.block_number as u64,
sender: Address::from_slice(&v.sender),
transaction_hash: H256::from_slice(&v.transaction_hash),
timestamp: v.timestamp.timestamp() as u64,
timestamp: v
.timestamp
.and_utc()
.to_rfc3339_opts(chrono::SecondsFormat::Micros, true),
status: v.status,
fee: U256::from(v.gas_price.mul(v.gas_used).to_u128().unwrap_or(0)),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package blockscout.userOpsIndexer.v1;

import "google/protobuf/struct.proto";

option go_package = "github.com/blockscout/blockscout-rs/user-ops-indexer";

service UserOpsService {
Expand Down Expand Up @@ -74,7 +76,7 @@ message ListUserOpsRequest {
optional string factory = 4;
optional string transaction_hash = 5;
optional string entry_point = 6;
optional uint64 bundle_index = 7;
optional uint32 bundle_index = 7;
optional uint64 block_number = 8;
optional uint32 page_size = 9;
optional string page_token = 10;
Expand Down Expand Up @@ -120,16 +122,16 @@ message Account {
optional string factory = 2;
optional string creation_transaction_hash = 3;
optional string creation_op_hash = 4;
optional uint64 creation_timestamp = 5;
optional string creation_timestamp = 5;
uint32 total_ops = 6;
}

message Bundle {
string transaction_hash = 1;
string bundler = 2;
uint64 block_number = 3;
uint64 bundle_index = 4;
uint64 timestamp = 5;
uint32 bundle_index = 4;
string timestamp = 5;
uint32 total_ops = 6;
}

Expand All @@ -149,28 +151,42 @@ message Factory {
uint32 total_accounts = 2;
}

message RawUserOp {
string sender = 1;
string nonce = 2;
string init_code = 3;
string call_data = 4;
uint64 call_gas_limit = 5;
uint64 verification_gas_limit = 6;
uint64 pre_verification_gas = 7;
string max_fee_per_gas = 8;
string max_priority_fee_per_gas = 9;
string paymaster_and_data = 10;
string signature = 11;
}

message UserOp {
string hash = 1;
string sender = 2;
string nonce = 3;
optional string init_code = 4;
string call_data = 5;
uint64 call_gas_limit = 6;
uint64 verification_gas_limit = 7;
uint64 pre_verification_gas = 8;
string max_fee_per_gas = 9;
string max_priority_fee_per_gas = 10;
optional string paymaster_and_data = 11;
string signature = 12;
optional string aggregator = 13;
optional string aggregator_signature = 14;
string entry_point = 15;
string call_data = 4;
uint64 call_gas_limit = 5;
uint64 verification_gas_limit = 6;
uint64 pre_verification_gas = 7;
string max_fee_per_gas = 8;
string max_priority_fee_per_gas = 9;
string signature = 10;
RawUserOp raw = 11;
optional string aggregator = 12;
optional string aggregator_signature = 13;
string entry_point = 14;
string entry_point_version = 15;
string transaction_hash = 16;
uint64 block_number = 17;
string block_hash = 18;
string bundler = 19;
uint64 bundle_index = 20;
uint64 index = 21;
uint32 bundle_index = 20;
uint32 index = 21;
optional string factory = 22;
optional string paymaster = 23;
bool status = 24;
Expand All @@ -179,20 +195,20 @@ message UserOp {
string gas_price = 27;
uint64 gas_used = 28;
string sponsor_type = 29;
uint64 user_logs_start_index = 30;
uint64 user_logs_count = 31;
uint32 user_logs_start_index = 30;
uint32 user_logs_count = 31;
string fee = 32;

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

message ListUserOp {
string hash = 1;
uint64 block_number = 2;
string transaction_hash = 3;
string address = 4;
uint64 timestamp = 5;
string timestamp = 5;
bool status = 6;
string fee = 7;
}
Loading
Loading