Block indexer for Melscan (and possibly more)

The block indexer pulls blocks from the network one by one using a ValClient and indexes them.

SQLite schema overview

coins table

The main data structure is a SQLite table that tracks the state of all coins seen with the following columns:

The spending information is denormalized into this table to improve the performance of e.g. balance queries ("which coins were created")

"Tricky" cases (Melswap transactions, mostly) are handled by actually asking for more information from the network, rather than by reimplementating all the nuances of the state transition function. This is a big reason why we use a pull-based rather than an I/O-free, push-based API.

headvars table

stakes table

stores all stakedocs ever, which is all we really need

txvars table

Query API

Query facts about coins

rust // iterator over all coins with value above 100 µMEL let i: impl Iterator<Item = CoinInfo> = indexer.query_coins() .value_range(CoinValue(100)..) .denom(Denom::Mel) .iter()

```rust pub struct CoinInfo { pub createtxhash: TxHash, pub createindex: u8, pub createheight: BlockHeight, pub coindata: CoinData, pub spend_info: Option }

pub struct CoinSpendInfo { pub spendtxhash: TxHash, pub spendindex: u8, pub spend_height: BlockHeight } ```