Modules
Definition
A Module has a very specific meaning in the context of this SDK. A Module is something between a library and a small state machine. It is built on top of the BaseApp abstraction in the sense that all Modules must be explicitly interpeted in terms of BaseApp in order to compile the application. The full type definition is
data Module (name :: Symbol) (h :: *) (q :: *) (s :: EffectRow) (r :: EffectRow) = Module
{ moduleTxDeliverer :: T.RouteTx h r 'DeliverTx
, moduleTxChecker :: T.RouteTx h r 'CheckTx
, moduleQueryServer :: Q.RouteQ q r
, moduleEval :: forall deps. Members BaseAppEffs deps => forall a. Sem (s :& deps) a -> Sem deps a
}
where the type parameters
nameis the name of the module, e.g."bank".his the transaction router api type.qis the query api type for querying state in the url format (more on this later).sis the set of effects introduced by this module.ris the global set of effects that this module will run in when part of a larger application (more on this later).
Below that line we see the fields for the Module data type, where
moduleTxDelivererspecifies how the module processes transactions in order to update the application state duringdeliverTxmessages.moduleTxCheckeris used duringcheckTxmessages to check if a transaction in the mempool is a valid transaction.moduleQueryServeris responsible for handling queries for application state from thequerymessage.moduleEvalis the natural transformation that specifies how to interpet theModulein terms ofBaseApp.
Note that in the event that a Module is abstract, meaning it doesn't have any messages to respond to, then we have msg ~ Void.
Composition
Modules are meant to be composed to create larger applications. We will see examples of this with the Nameservice application. The way to do this is easy, as the Modules data type allows you to simply combine them in a heterogeneous list:
data Modules (ms :: [*]) r where
NilModules :: Modules '[] r
(:+) :: Module name msg api s r -> Modules ms r -> Modules (Module name msg api s r ': ms) r
When you are ready to create your application, you simply specify a value of type Modules and some other configuration data, and the SDK will create an App for you.
