#![deny(missing_docs)]
#![doc = include_str!("../README.md")]
mod call;
mod genesis;
#[cfg(test)]
mod tests;
#[cfg(feature = "native")]
mod query;
pub use call::CallMessage;
#[cfg(feature = "native")]
pub use query::Response;
use sov_modules_api::{Context, Error, ModuleInfo, Zkvm};
use sov_state::codec::BcsCodec;
use sov_state::WorkingSet;
pub struct ProverIncentivesConfig<C: Context, Vm: Zkvm> {
bonding_token_address: C::Address,
minimum_bond: u64,
commitment_of_allowed_verifier_method: Vm::CodeCommitment,
initial_provers: Vec<(C::Address, u64)>,
}
#[cfg_attr(feature = "native", derive(sov_modules_api::ModuleCallJsonSchema))]
#[derive(ModuleInfo)]
pub struct ProverIncentives<C: Context, Vm: Zkvm> {
#[address]
pub address: C::Address,
#[state]
pub bonding_token_address: sov_state::StateValue<C::Address>,
#[state]
pub commitment_of_allowed_verifier_method: sov_state::StateValue<Vm::CodeCommitment, BcsCodec>,
#[state]
pub bonded_provers: sov_state::StateMap<C::Address, u64>,
#[state]
pub minimum_bond: sov_state::StateValue<u64>,
#[module]
pub(crate) bank: sov_bank::Bank<C>,
}
impl<C: Context, Vm: Zkvm> sov_modules_api::Module for ProverIncentives<C, Vm> {
type Context = C;
type Config = ProverIncentivesConfig<C, Vm>;
type CallMessage = call::CallMessage;
fn genesis(
&self,
config: &Self::Config,
working_set: &mut WorkingSet<C::Storage>,
) -> Result<(), Error> {
Ok(self.init_module(config, working_set)?)
}
fn call(
&self,
msg: Self::CallMessage,
context: &Self::Context,
working_set: &mut WorkingSet<C::Storage>,
) -> Result<sov_modules_api::CallResponse, Error> {
match msg {
call::CallMessage::BondProver(bond_amount) => {
self.bond_prover(bond_amount, context, working_set)
}
call::CallMessage::UnbondProver => self.unbond_prover(context, working_set),
call::CallMessage::VerifyProof(proof) => {
self.process_proof(&proof, context, working_set)
}
}
.map_err(|e| e.into())
}
}