Trait fedimint_core::module::ServerModule

source ·
pub trait ServerModule: Debug + Sized {
    type Common: ModuleCommon;
    type Init: ServerModuleInit;

    // Required methods
    fn consensus_proposal<'a, 'life0, 'life1, 'async_trait>(
        &'a self,
        dbtx: &'life0 mut DatabaseTransaction<'life1>,
    ) -> Pin<Box<dyn Future<Output = Vec<<Self::Common as ModuleCommon>::ConsensusItem>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn process_consensus_item<'a, 'b, 'life0, 'async_trait>(
        &'a self,
        dbtx: &'life0 mut DatabaseTransaction<'b>,
        consensus_item: <Self::Common as ModuleCommon>::ConsensusItem,
        peer_id: PeerId,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'b: 'async_trait,
             'life0: 'async_trait;
    fn process_input<'a, 'b, 'c, 'life0, 'async_trait>(
        &'a self,
        dbtx: &'life0 mut DatabaseTransaction<'c>,
        input: &'b <Self::Common as ModuleCommon>::Input,
    ) -> Pin<Box<dyn Future<Output = Result<InputMeta, <Self::Common as ModuleCommon>::InputError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'b: 'async_trait,
             'c: 'async_trait,
             'life0: 'async_trait;
    fn process_output<'a, 'b, 'life0, 'async_trait>(
        &'a self,
        dbtx: &'life0 mut DatabaseTransaction<'b>,
        output: &'a <Self::Common as ModuleCommon>::Output,
        out_point: OutPoint,
    ) -> Pin<Box<dyn Future<Output = Result<TransactionItemAmount, <Self::Common as ModuleCommon>::OutputError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'b: 'async_trait,
             'life0: 'async_trait;
    fn output_status<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        dbtx: &'life1 mut DatabaseTransaction<'life2>,
        out_point: OutPoint,
    ) -> Pin<Box<dyn Future<Output = Option<<Self::Common as ModuleCommon>::OutputOutcome>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn audit<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        dbtx: &'life1 mut DatabaseTransaction<'life2>,
        audit: &'life3 mut Audit,
        module_instance_id: ModuleInstanceId,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn api_endpoints(&self) -> Vec<ApiEndpoint<Self>>;

    // Provided methods
    fn module_kind() -> ModuleKind { ... }
    fn decoder() -> Decoder { ... }
}

Required Associated Types§

Required Methods§

source

fn consensus_proposal<'a, 'life0, 'life1, 'async_trait>( &'a self, dbtx: &'life0 mut DatabaseTransaction<'life1>, ) -> Pin<Box<dyn Future<Output = Vec<<Self::Common as ModuleCommon>::ConsensusItem>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

This module’s contribution to the next consensus proposal. This method is only guaranteed to be called once every few seconds. Consensus items are not meant to be latency critical; do not create them as a response to a processed transaction. Only use consensus items to establish consensus on a value that is required to verify transactions, like unix time, block heights and feerates, and model all other state changes trough transactions. The intention for this method is to always return all available consensus items even if they are redundant while process_consensus_item returns an error for the redundant proposals.

If you think you actually do require latency critical consensus items or have trouble designing your module in order to avoid them please contact the Fedimint developers.

source

fn process_consensus_item<'a, 'b, 'life0, 'async_trait>( &'a self, dbtx: &'life0 mut DatabaseTransaction<'b>, consensus_item: <Self::Common as ModuleCommon>::ConsensusItem, peer_id: PeerId, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'b: 'async_trait, 'life0: 'async_trait,

This function is called once for every consensus item. The function should return Ok if and only if the consensus item changes the system state. Therefore this method should return an error in case of merely redundant consensus items such that they will be purged from the history of the federation. This enables consensus_proposal to return all available consensus item without wasting disk space with redundant consensus items.

source

fn process_input<'a, 'b, 'c, 'life0, 'async_trait>( &'a self, dbtx: &'life0 mut DatabaseTransaction<'c>, input: &'b <Self::Common as ModuleCommon>::Input, ) -> Pin<Box<dyn Future<Output = Result<InputMeta, <Self::Common as ModuleCommon>::InputError>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'b: 'async_trait, 'c: 'async_trait, 'life0: 'async_trait,

Try to spend a transaction input. On success all necessary updates will be part of the database transaction. On failure (e.g. double spend) the database transaction is rolled back and the operation will take no effect.

source

fn process_output<'a, 'b, 'life0, 'async_trait>( &'a self, dbtx: &'life0 mut DatabaseTransaction<'b>, output: &'a <Self::Common as ModuleCommon>::Output, out_point: OutPoint, ) -> Pin<Box<dyn Future<Output = Result<TransactionItemAmount, <Self::Common as ModuleCommon>::OutputError>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'b: 'async_trait, 'life0: 'async_trait,

Try to create an output (e.g. issue notes, peg-out BTC, …). On success all necessary updates to the database will be part of the database transaction. On failure (e.g. double spend) the database transaction is rolled back and the operation will take no effect.

The supplied out_point identifies the operation (e.g. a peg-out or note issuance) and can be used to retrieve its outcome later using output_status.

source

fn output_status<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, dbtx: &'life1 mut DatabaseTransaction<'life2>, out_point: OutPoint, ) -> Pin<Box<dyn Future<Output = Option<<Self::Common as ModuleCommon>::OutputOutcome>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Retrieve the current status of the output. Depending on the module this might contain data needed by the client to access funds or give an estimate of when funds will be available. Returns None if the output is unknown, NOT if it is just not ready yet.

source

fn audit<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, dbtx: &'life1 mut DatabaseTransaction<'life2>, audit: &'life3 mut Audit, module_instance_id: ModuleInstanceId, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Queries the database and returns all assets and liabilities of the module.

Summing over all modules, if liabilities > assets then an error has occurred in the database and consensus should halt.

source

fn api_endpoints(&self) -> Vec<ApiEndpoint<Self>>

Returns a list of custom API endpoints defined by the module. These are made available both to users as well as to other modules. They thus should be deterministic, only dependant on their input and the current epoch.

Provided Methods§

source

fn module_kind() -> ModuleKind

source

fn decoder() -> Decoder

Returns a decoder for the following associated types of this module:

  • ClientConfig
  • Input
  • Output
  • OutputOutcome
  • ConsensusItem
  • InputError
  • OutputError

Object Safety§

This trait is not object safe.

Implementors§