From 8b16318c38b53ac5bf5048e57e7f3022d708ba5b Mon Sep 17 00:00:00 2001 From: Daniil Polyakov Date: Fri, 13 Feb 2026 23:54:50 +0300 Subject: [PATCH] fix: use base58 encoding for account in Explorer & some formatting chores --- Cargo.lock | 6 +- explorer_service/Cargo.toml | 3 - explorer_service/src/api.rs | 28 ++--- .../src/components/account_preview.rs | 6 +- .../src/components/block_preview.rs | 4 +- .../src/components/transaction_preview.rs | 2 +- explorer_service/src/format_utils.rs | 24 ---- explorer_service/src/pages/account_page.rs | 19 +-- explorer_service/src/pages/block_page.rs | 15 ++- .../src/pages/transaction_page.rs | 28 ++--- indexer/service/protocol/Cargo.toml | 4 + indexer/service/protocol/src/convert.rs | 20 ++- indexer/service/protocol/src/lib.rs | 114 +++++++++++++++--- indexer/service/src/mock_service.rs | 10 +- wallet/Cargo.toml | 1 - wallet/src/cli/account.rs | 4 +- 16 files changed, 169 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 157d25ab..9ef3c7a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2484,7 +2484,6 @@ dependencies = [ "console_error_panic_hook", "console_log", "env_logger", - "hex", "indexer_service_protocol", "indexer_service_rpc", "jsonrpsee", @@ -3427,12 +3426,16 @@ dependencies = [ name = "indexer_service_protocol" version = "0.1.0" dependencies = [ + "anyhow", + "base58", "base64 0.22.1", "common", + "hex", "nssa", "nssa_core", "schemars 1.2.0", "serde", + "serde_with", ] [[package]] @@ -8257,7 +8260,6 @@ dependencies = [ "amm_core", "anyhow", "async-stream", - "base58", "base64 0.22.1", "borsh", "bytemuck", diff --git a/explorer_service/Cargo.toml b/explorer_service/Cargo.toml index 49d1ddce..219f2bc0 100644 --- a/explorer_service/Cargo.toml +++ b/explorer_service/Cargo.toml @@ -26,9 +26,6 @@ console_log = "1.0" # Date/Time chrono.workspace = true -# Hex encoding/decoding -hex.workspace = true - # URL encoding urlencoding = "2.1" diff --git a/explorer_service/src/api.rs b/explorer_service/src/api.rs index c3360c01..c489c827 100644 --- a/explorer_service/src/api.rs +++ b/explorer_service/src/api.rs @@ -1,3 +1,5 @@ +use std::str::FromStr as _; + use indexer_service_protocol::{Account, AccountId, Block, BlockId, HashType, Transaction}; use leptos::prelude::*; use serde::{Deserialize, Serialize}; @@ -25,13 +27,6 @@ pub async fn get_account(account_id: AccountId) -> Result Option> { - let s = s.trim().trim_start_matches("0x"); - hex::decode(s).ok() -} - /// Search for a block, transaction, or account by query string #[server] pub async fn search(query: String) -> Result { @@ -42,12 +37,8 @@ pub async fn search(query: String) -> Result { let mut transactions = Vec::new(); let mut accounts = Vec::new(); - // Try to parse as hash (32 bytes) - if let Some(bytes) = parse_hex(&query) - && let Ok(hash_array) = <[u8; 32]>::try_from(bytes) - { - let hash = HashType(hash_array); - + // Try as hash + if let Ok(hash) = HashType::from_str(&query) { // Try as block hash if let Ok(block) = client.get_block_by_hash(hash).await { blocks.push(block); @@ -57,12 +48,13 @@ pub async fn search(query: String) -> Result { if let Ok(tx) = client.get_transaction(hash).await { transactions.push(tx); } + } - // Try as account ID - let account_id = AccountId { value: hash_array }; - if let Ok(account) = client.get_account(account_id).await { - accounts.push((account_id, account)); - } + // Try as account ID + if let Ok(account_id) = AccountId::from_str(&query) + && let Ok(account) = client.get_account(account_id).await + { + accounts.push((account_id, account)); } // Try as block ID diff --git a/explorer_service/src/components/account_preview.rs b/explorer_service/src/components/account_preview.rs index 3a99eeb8..bbe59c0f 100644 --- a/explorer_service/src/components/account_preview.rs +++ b/explorer_service/src/components/account_preview.rs @@ -2,12 +2,10 @@ use indexer_service_protocol::{Account, AccountId}; use leptos::prelude::*; use leptos_router::components::A; -use crate::format_utils; - /// Account preview component #[component] pub fn AccountPreview(account_id: AccountId, account: Account) -> impl IntoView { - let account_id_str = format_utils::format_account_id(&account_id); + let account_id_str = account_id.to_string(); view! { {move || { let Account { program_owner, balance, data, nonce } = &account; - let program_id = format_utils::format_program_id(program_owner); + let program_id = program_owner.to_string(); view! {