cosmos-sdk/schema/appdata
Aaron Craelius e7844e640c
feat(schema): testing utilities (#20705)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-07-31 06:58:30 +00:00
..
async_test.go feat(schema/appdata): async listener mux'ing (#20879) 2024-07-25 13:53:26 +00:00
async.go fix(stf): fixes to make init genesis pass (#21088) 2024-07-27 18:11:24 +00:00
data.go feat(schema/appdata)!: packet support and small refactorings (#20860) 2024-07-04 13:43:49 +00:00
forwarder_test.go feat(schema): testing utilities (#20705) 2024-07-31 06:58:30 +00:00
forwarder.go feat(schema): testing utilities (#20705) 2024-07-31 06:58:30 +00:00
listener.go feat(schema/appdata)!: packet support and small refactorings (#20860) 2024-07-04 13:43:49 +00:00
mux_test.go feat(serverv2): integrate gRPC (#21038) 2024-07-30 09:26:16 +00:00
mux.go feat(schema/appdata): async listener mux'ing (#20879) 2024-07-25 13:53:26 +00:00
packet.go feat(schema/appdata)!: packet support and small refactorings (#20860) 2024-07-04 13:43:49 +00:00
README.md refactor(indexer/base): move to cosmossdk.io/schema (#20744) 2024-06-26 15:46:08 +00:00

App Data

The appdata package defines the basic types for streaming blockchain event and state data to external listeners, with a specific focus on supporting logical decoding and indexing of state.

A blockchain data source should accept a Listener instance and invoke the provided callbacks in the correct order. A downstream listener should provide a Listener instance and perform operations based on the data passed to its callbacks.

Listener Callback Order

Listener callbacks should be called in this order

sequenceDiagram
    actor Source
    actor Target    
    Source ->> Target: Initialize
    Source -->> Target: InitializeModuleSchema
    loop Block
        Source ->> Target: StartBlock
        Source ->> Target: OnBlockHeader
        Source -->> Target: OnTx
        Source -->> Target: OnEvent
        Source -->> Target: OnKVPair
        Source -->> Target: OnObjectUpdate
        Source ->> Target: Commit
    end

Initialize must be called before any other method and should only be invoked once. InitializeModuleSchema should be called at most once for every module with logical data.

Sources will generally only call InitializeModuleSchema and OnObjectUpdate if they have native logical decoding capabilities. Usually, the indexer framework will provide this functionality based on OnKVPair data and schema.HasModuleCodec implementations.

StartBlock and OnBlockHeader should be called only once at the beginning of a block, and Commit should be called only once at the end of a block. The OnTx, OnEvent, OnKVPair and OnObjectUpdate must be called after OnBlockHeader, may be called multiple times within a block and indexers should not assume that the order is logical unless InitializationData.HasEventAlignedWrites is true.