1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
use starknet::core::types::Felt;
use crate::app::state::SourceStatus;
use crate::app::views::address_info::{UnfilledCallGap, UnfilledGap};
use crate::data::pathfinder::ClassHashEntry;
use crate::data::types::{
AddressTxSummary, ClassContractEntry, ClassDeclareInfo, ContractCallSummary,
MetaTxIntenderSummary, SnAddressInfo, SnBlock, SnEvent, SnReceipt, SnTransaction, TokenBalance,
TokenTransfer, VoyagerLabelInfo,
};
use crate::decode::events::DecodedEvent;
use crate::decode::functions::RawCall;
use crate::decode::outside_execution::OutsideExecutionInfo;
use crate::network::dune::AddressActivityProbe;
/// Actions dispatched from the UI to the network task, or responses back.
#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub enum Action {
// --- Requests (UI → network) ---
/// Fetch the N most recent blocks.
FetchRecentBlocks {
count: usize,
},
/// Fetch a block with all its transactions.
FetchBlockDetail {
number: u64,
},
/// Fetch a transaction and its receipt.
FetchTransaction {
hash: Felt,
},
/// Fetch address info (nonce, class hash, etc.).
FetchAddressInfo {
address: Felt,
},
/// Periodic 60s tick that triggers an RPC-only refresh of the currently
/// viewed address when WS is not `Live`. No payload — the reducer checks
/// the current view/address/ws status before dispatching work.
PeriodicAddressPollTick,
/// Lightweight RPC-only refresh of an address: re-reads nonce and scans
/// the top of the chain for new activity. Distinct from `FetchAddressInfo`
/// which also fires Dune + Pathfinder.
RefreshAddressRpc {
address: Felt,
},
/// Navigate to address view immediately (before data loads).
NavigateToAddress {
address: Felt,
},
/// Resolve a search query (may need RPC to disambiguate tx vs address).
ResolveSearch {
query: String,
},
/// Fetch the next/prev tx by nonce for a given sender address.
FetchTxByNonce {
sender: Felt,
current_nonce: u64,
direction: i64,
},
/// Enrich visible address txs that are missing endpoint/timestamp data.
EnrichAddressTxs {
address: Felt,
hashes: Vec<Felt>,
},
/// Post-load enrichment: fill small nonce gaps + enrich missing endpoint names.
/// Fires automatically once initial sources settle. Large gaps are handled by
/// `FillAddressNonceGaps` instead (on-demand, issue #10).
EnrichAddressEndpoints {
address: Felt,
current_nonce: u64,
known_txs: Vec<AddressTxSummary>,
},
/// On-demand large-gap fill: triggered when the user scrolls toward the gap.
FillAddressNonceGaps {
address: Felt,
known_txs: Vec<AddressTxSummary>,
gap: UnfilledGap,
},
/// On-demand Calls-tab block-range gap fill: dispatched when the user
/// presses Enter on a call-gap row. Backfills the `[lo_block, hi_block]`
/// window (contract → Dune `starknet.calls`; account → pf event window)
/// and merges the result, shrinking the gap from its newer edge.
FillAddressCallGap {
address: Felt,
gap: UnfilledCallGap,
is_contract: bool,
},
/// Transfers tab entry / poll: scan from the top scanned block to head
/// (from `floor_block` on a cold cache).
FetchAddressTransfers {
address: Felt,
floor_block: u64,
},
/// Enter on a Transfers-tab gap row: backfill `[lo_block, hi_block]`.
FillAddressTransferGap {
address: Felt,
lo_block: u64,
hi_block: u64,
},
/// Persist WS-streamed transfer rows.
PersistAddressTransfers {
address: Felt,
rows: Vec<TokenTransfer>,
},
/// Enrich WS-streamed call stubs (missing sender/function/fee/timestamp).
EnrichAddressCalls {
address: Felt,
hashes_with_blocks: Vec<(Felt, u64)>,
},
/// Fetch older blocks (pagination: blocks before `before` block number).
FetchOlderBlocks {
before: u64,
count: usize,
},
/// Fetch more address transactions from before a given block (pagination).
FetchMoreAddressTxs {
address: Felt,
before_block: u64,
is_contract: bool,
},
/// Fetch meta-transactions (SNIP-9 outside executions) where `address` is
/// the intender (issue #11). Paginates via pf-query's event continuation
/// token — opaque u64 from the previous response, or `None` for first page.
///
/// `from_block` is the absolute scan floor (typically deploy block); the
/// backend stops paginating once `min_searched <= from_block` so we don't
/// time out walking chunks older than the account. `window_size` is the
/// per-page ExtendDown block range, adapted across calls (double on empty,
/// halve on full) — see `event_window::suggest_next_window`.
FetchAddressMetaTxs {
address: Felt,
from_block: u64,
continuation_token: Option<u64>,
window_size: u64,
limit: u32,
},
/// Classify a single tx as a potential meta-tx where `address` is the
/// intender. Dispatched from the WS event handler on every
/// `TRANSACTION_EXECUTED` event for the currently-viewed account so the
/// MetaTxs tab updates in real time. Requires pf-query (tx_type +
/// calldata decoding); no-op when unavailable.
ClassifyPotentialMetaTx {
address: Felt,
tx_hash: Felt,
},
/// Decode a WS-received event using the ABI of its `from_address`, then
/// emit [`Action::AddressEventStreamed`] so the Events tab merges the
/// decoded row in real time. Dispatched from the `AddressWsEvent`
/// reducer — the reducer can't call the async ABI registry itself, so it
/// delegates here. A best-effort decode returns the raw event wrapped in
/// a [`DecodedEvent`] when no ABI is available, so the tab still reflects
/// live activity.
DecodeAddressWsEvent {
address: Felt,
event: SnEvent,
},
/// Fetch class hash info (ABI, declaration, deployed contracts).
FetchClassInfo {
class_hash: Felt,
},
/// Persist enriched address txs to cache (sent after enrichment completes).
PersistAddressTxs {
address: Felt,
txs: Vec<AddressTxSummary>,
},
/// Persist enriched address calls to cache (sent after enrichment completes).
PersistAddressCalls {
address: Felt,
calls: Vec<ContractCallSummary>,
},
FetchTokenPricesToday {
tokens: Vec<Felt>,
},
FetchTokenPricesHistoric {
requests: Vec<(Felt, u64)>,
},
// --- Responses (network → UI) ---
/// Recent blocks loaded.
BlocksLoaded(Vec<SnBlock>),
/// A single new block header arrived (from WebSocket or polling).
NewBlock(SnBlock),
/// Block detail with transactions loaded.
BlockDetailLoaded {
block: SnBlock,
transactions: Vec<SnTransaction>,
/// Decoded function name per tx (by index). None if not yet resolved.
endpoint_names: Vec<Option<String>>,
/// Execution status per tx: "OK", "REV", or "?"
tx_statuses: Vec<String>,
/// Outside execution summary per tx. Some for meta txs, None otherwise.
meta_tx_info: Vec<Option<crate::app::views::block_detail::MetaTxSummary>>,
/// True for any tx that touches the privacy pool — top-level call
/// or OE-inner call. Drives the "Prv" column shield marker on the
/// block tx list.
is_privacy_tx: Vec<bool>,
},
/// Transaction + receipt + decoded events loaded.
TransactionLoaded {
transaction: SnTransaction,
receipt: SnReceipt,
decoded_events: Vec<DecodedEvent>,
decoded_calls: Vec<RawCall>,
/// Detected outside executions: (call_index, parsed_info).
outside_executions: Vec<(usize, OutsideExecutionInfo)>,
block_timestamp: Option<u64>,
/// Block-level gas prices in FRI: (L1, L2, L1-Data). Optional in
/// case the block fetch fails; the fee view then falls back to 0.
block_gas_prices_fri: Option<(u128, u128, u128)>,
/// Block finality status, sourced from the (re-probed) block rather
/// than the immutably-cached receipt so it reflects L2 -> L1
/// transitions. `None` if the block fetch failed.
block_status: Option<String>,
},
/// Decoded execution trace for a transaction (recursive call tree).
/// Sent after TransactionLoaded so the user sees the rest of the view
/// immediately while the trace populates lazily. `trace = None` signals
/// a fetch/decode failure so the UI can clear the "loading…" state.
TransactionTraceLoaded {
tx_hash: Felt,
trace: Option<crate::decode::trace::DecodedTrace>,
},
/// Forward-decrypted Privacy Pool notes for a labelled user. Posted by
/// the privacy-sync background task; the reducer merges these into
/// `app.private_notes` so the Privacy tab can annotate
/// `EncNoteCreated` events that match. `nullifiers` carries the
/// `(spend_nullifier → note_id)` pairs for incoming notes only — the
/// reducer puts them into `app.private_nullifiers` so `NoteUsed`
/// events can be labelled "user spent note X". `notes = empty` is a
/// valid signal that the user has nothing in the pool yet (or the
/// sync ran against a wrong key) — caller should NOT treat empty as
/// failure.
PrivateNotesIndexed {
user: Felt,
notes: Vec<crate::decode::privacy_sync::DecryptedNote>,
nullifiers: Vec<(Felt, Felt)>,
},
/// Kick off a privacy-pool storage sync for a labelled user. Sent by
/// the App reducer when a tx with `EncNoteCreated` events is opened
/// for a user with a viewing key, and we haven't yet synced this
/// session. The network task picks it up, runs `sync_user_notes`
/// (~hundreds of pf-query slot reads, both incoming and outgoing
/// channel walks), and posts `Action::PrivateNotesIndexed` when done.
FetchPrivateNotes {
user: Felt,
/// Raw private viewing key felt. Treated as a secret in handlers
/// (re-wrapped in `SecretFelt` at the call site to get
/// zeroize-on-drop + `[REDACTED]` Debug).
viewing_key: Felt,
},
/// Kick off an on-chain ERC-20 metadata lookup (decimals + symbol)
/// for a token we haven't seen before. Dispatched by the App
/// reducer when a Privacy or Address load surfaces an unknown
/// token; deduped via `App::token_metadata_dispatched`.
FetchTokenMetadata {
token: Felt,
},
/// Result of a metadata fetch. `meta = None` means the call failed
/// (token doesn't expose ERC-20 entrypoints, RPC error, etc.) — the
/// reducer still records the attempt so we don't keep retrying in
/// the same session.
TokenMetadataLoaded {
token: Felt,
meta: Option<crate::data::token_metadata::TokenMeta>,
},
/// Address info loaded.
AddressInfoLoaded {
info: SnAddressInfo,
decoded_events: Vec<DecodedEvent>,
tx_summaries: Vec<AddressTxSummary>,
contract_calls: Vec<ContractCallSummary>,
},
/// Class hash history loaded for an address.
ClassHistoryLoaded {
address: Felt,
entries: Vec<ClassHashEntry>,
},
/// Enriched endpoint/timestamp data for a subset of address txs.
AddressTxsEnriched {
address: Felt,
updates: Vec<AddressTxSummary>,
},
/// Enriched call data (sender/function/fee/timestamp) for WS-streamed calls.
AddressCallsEnriched {
address: Felt,
calls: Vec<ContractCallSummary>,
},
/// Supplementary Calls rows derived from a pf-query tx_rows scan (plan §2).
///
/// The meta-tx keyed-event scan walks the same tx_rows the Calls tab needs
/// — every row is a tx that called this address via `execute_from_outside`.
/// Dune is still the completeness authority (LIMIT 500 after dedup), but
/// merging these rows closes the invariant gap where MetaTxs (keyed,
/// unbounded) could exceed Calls (Dune-only, capped).
AddressCallsMerged {
address: Felt,
calls: Vec<ContractCallSummary>,
},
/// A Dune page or gap fill fully scanned `[lo_block, hi_block]` for calls.
/// The reducer records it so `detect_unfilled_call_gaps` stops surfacing a
/// genuinely-sparse hole; `tracked_from` lowers the Dune-tracked floor.
AddressCallRangeScanned {
address: Felt,
lo_block: u64,
hi_block: u64,
tracked_from: Option<u64>,
},
/// An on-demand Calls-tab gap fill finished (success, no-op, or error). The
/// reducer clears the matching gap's `fill_dispatched` so the row leaves the
/// "loading" state and Enter can re-dispatch — without this a failed fill
/// would leave the gap stuck forever.
AddressCallGapFillFinished {
address: Felt,
lo_block: u64,
},
/// Persisted fully-scanned call ranges for an address, loaded from cache at
/// address entry. Seeds `scanned_call_ranges` so a previously-closed
/// (genuinely-sparse) gap stays suppressed across re-navigation/restart.
AddressCallScannedRangesLoaded {
address: Felt,
ranges: Vec<(u64, u64)>,
tracked_from: Option<u64>,
},
/// Transfer rows to merge; `scanned` is the block range this batch
/// fully covers (recorded so the App can derive unscanned gaps).
AddressTransfersLoaded {
address: Felt,
rows: Vec<TokenTransfer>,
scanned: Option<(u64, u64)>,
},
AddressTransferScannedRangesLoaded {
address: Felt,
ranges: Vec<(u64, u64)>,
},
/// A transfers fill ended (any outcome). `None` = the top-delta fetch;
/// `Some(lo)` = the gap row identified by its lower block.
AddressTransferFillFinished {
address: Felt,
lo_block: Option<u64>,
},
/// Older blocks loaded (appended to block list).
OlderBlocksLoaded(Vec<SnBlock>),
/// More address transactions loaded (appended to address tx list).
MoreAddressTxsLoaded {
address: Felt,
tx_summaries: Vec<AddressTxSummary>,
contract_calls: Vec<ContractCallSummary>,
/// The earliest block number in this batch (for further pagination).
oldest_block: u64,
/// Whether there is likely more data beyond this batch.
has_more: bool,
},
/// Meta-transaction summaries loaded for an address (issue #11).
AddressMetaTxsLoaded {
address: Felt,
summaries: Vec<MetaTxIntenderSummary>,
/// Opaque continuation token from pf-query, if more pages remain.
/// Pass back via `FetchAddressMetaTxs::continuation_token` to resume.
next_token: Option<u64>,
/// Adaptive next ExtendDown window size (blocks) suggested by the
/// backend based on this page's hit density. `None` when no further
/// paging is expected (we hit the floor) or on non-ExtendDown calls.
/// The UI persists this as `meta_tx_last_window` and feeds it into
/// the next `FetchAddressMetaTxs` dispatch.
next_window_size: Option<u64>,
},
/// Cached meta-tx rows delivered synchronously at tab-entry time. Merges
/// into the visible list but does NOT touch the loading flag / cursor — a
/// live pf-query fetch may still be in-flight behind this.
AddressMetaTxsCacheLoaded {
address: Felt,
summaries: Vec<MetaTxIntenderSummary>,
},
/// Streaming single-tx meta-tx classification result from the WS path.
/// Merges into the visible list without touching pagination state (live
/// pf-query fetches may still be in-flight in parallel).
AddressMetaTxsStreamed {
address: Felt,
summaries: Vec<MetaTxIntenderSummary>,
},
/// Streaming single decoded event from the WS path (response to
/// [`Action::DecodeAddressWsEvent`]). Merges into the Events tab list
/// newest-first, deduping by `(tx_hash, event_index)`.
AddressEventStreamed {
address: Felt,
decoded_event: DecodedEvent,
},
/// Cached events decoded off the critical path. Emitted by a spawned task
/// after `AddressInfoLoaded` so the initial UI paint doesn't block on
/// per-event ABI fetches. Replaces the events list iff non-empty and the
/// address context still matches.
AddressEventsCacheLoaded {
address: Felt,
decoded_events: Vec<DecodedEvent>,
},
/// Dune activity probe result delivered to UI for pagination window sizing.
AddressProbeLoaded {
address: Felt,
probe: AddressActivityProbe,
},
/// Tells the UI which data sources will be streaming tx data for this address load.
AddressSourcesPending {
address: Felt,
sources: Vec<Source>,
},
/// Passive update of the shared event-window hint (min/max scanned block,
/// deferred gap) driven by `ensure_address_events_window`. Consumed by
/// the Calls / Events / MetaTxs tab titles to surface gap state. Fires
/// from every event-window fetch path so all three tabs stay aligned.
AddressEventWindowUpdated {
address: Felt,
min_searched: u64,
max_searched: u64,
deferred_gap: Option<(u64, u64)>,
},
/// Streaming partial tx results from a specific data source (merges, never replaces).
AddressTxsStreamed {
address: Felt,
source: Source,
tx_summaries: Vec<AddressTxSummary>,
/// When true, this source has delivered all its data.
complete: bool,
},
/// Single broadcast of a WS-received event. Emitted once per event; the
/// reducer fans it out to:
/// - the Events tab via [`Action::DecodeAddressWsEvent`] (async decode);
/// - the Calls tab (builds a `ContractCallSummary` stub + dispatches
/// `EnrichAddressCalls`);
/// - the MetaTxs tab for `TRANSACTION_EXECUTED` events via
/// `ClassifyPotentialMetaTx`.
///
/// The event itself has already been persisted into the address event
/// cache in the WS handler.
AddressWsEvent {
address: Felt,
event: SnEvent,
},
/// Token balances loaded for an address (sent early for accounts).
AddressBalancesLoaded {
address: Felt,
balances: Vec<TokenBalance>,
},
/// The address has no class at the latest block (`get_class_hash`
/// errored) — it exists on-chain only as a token-transfer recipient.
/// The header shows a red "not deployed" note (gated on non-zero
/// balances) instead of a class/deploy line.
AddressNotDeployed {
address: Felt,
},
/// Voyager label loaded for an address.
VoyagerLabelLoaded {
address: Felt,
label: VoyagerLabelInfo,
},
/// Update the status of a named data source.
SourceUpdate {
source: Source,
status: SourceStatus,
},
/// Latest block number updated.
LatestBlockNumber(u64),
/// Update the loading status message shown in the status bar.
LoadingStatus(String),
/// Per-query status registry update: `Some(label)` starts/updates an entry
/// for `key`, `None` removes it. Keys are opaque strings owned by the
/// dispatcher (e.g. `"meta:41420f"` for the MetaTxs scan on an address).
/// Rendered alongside `loading_detail` in the status bar.
SetActiveQuery {
key: String,
label: Option<String>,
},
/// Navigate to class info view immediately (before data loads).
NavigateToClassInfo {
class_hash: Felt,
},
/// Class ABI loaded from RPC/cache.
ClassAbiLoaded {
class_hash: Felt,
abi: Option<std::sync::Arc<crate::decode::abi::ParsedAbi>>,
},
/// Class declaration info loaded (from PF+RPC or Dune).
ClassDeclareLoaded {
class_hash: Felt,
declare_info: Option<ClassDeclareInfo>,
},
/// Contracts deployed with this class hash (from PF).
ClassContractsLoaded {
class_hash: Felt,
contracts: Vec<ClassContractEntry>,
declaration_block: Option<u64>,
},
PricesUpdated,
/// An error occurred in the network task.
Error(String),
}
/// Identifies a data source for status updates.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Source {
Rpc,
Ws,
Pathfinder,
Dune,
Voyager,
Starkscan,
}