psibase 0.29.0

Library and command-line tool for interacting with psibase networks
Documentation
pub mod constants;
pub mod distribute;
pub mod weighted_normalization;

use crate::abort_message;

#[crate::service(
    name = "eval-hooks",
    actions = "hooks_actions",
    wrapper = "hooks_wrapper",
    structs = "hooks_structs",
    dispatch = false,
    pub_constant = false,
    psibase_mod = "crate"
)]
#[allow(non_snake_case, unused_variables)]
pub mod Hooks {
    use crate::AccountNumber;

    #[action]
    fn on_ev_reg(evaluation_id: u32, account: AccountNumber) {
        unimplemented!()
    }

    #[action]
    fn on_ev_unreg(evaluation_id: u32, account: AccountNumber) {
        unimplemented!()
    }

    #[action]
    fn on_grp_fin(evaluation_id: u32, group_number: u32, result: Vec<u8>) {
        unimplemented!()
    }

    #[action]
    fn on_attest(evaluation_id: u32, group_number: u32, user: AccountNumber, attestation: Vec<u8>) {
        unimplemented!()
    }

    #[action]
    fn on_eval_fin(evaluation_id: u32) {
        unimplemented!()
    }
}

#[crate::service(
    name = "occupation",
    actions = "occu_actions",
    wrapper = "occu_wrapper",
    structs = "occu_structs",
    dispatch = false,
    pub_constant = false,
    psibase_mod = "crate"
)]
#[allow(non_snake_case, unused_variables)]
pub mod Occupation {
    use crate::{services::auth_dyn, AccountNumber};

    /// Get scores for a fractal
    ///
    /// Returns a vector of accounts and their corresponding scores for a fractal.
    /// Scores are PPM shares (parts per million) and must not sum to more than 1,000,000.
    /// These scores are used by the Fractals service to determine distribution amounts for each member.
    ///
    /// # Arguments
    /// * `fractal` - The account of the fractal.
    #[action]
    fn get_scores(fractal: AccountNumber) -> Vec<(AccountNumber, u32)> {
        unimplemented!()
    }

    /// Check if an account is considered active in an occupation
    ///
    /// # Arguments
    /// * `fractal` - The account of the fractal.
    /// * `member` - The member account to check.
    #[action]
    fn is_active(fractal: AccountNumber, member: AccountNumber) -> bool {
        unimplemented!()
    }

    /// Check if a role ID is supported for a fractal.
    ///
    /// Returning false will cause the Fractals service to reject changing a role to this occupation.
    ///
    /// # Arguments
    /// * `fractal` - The account number of the fractal.
    /// * `role_id` - Role ID to check.
    #[action]
    fn is_role_ok(fractal: AccountNumber, role_id: u8) -> bool {
        unimplemented!()
    }

    /// Get policy action used by AuthDyn service.
    ///
    /// Returns authorisers for a given role in a fractal.
    ///
    /// # Arguments
    /// * `fractal` - The account of the fractal.
    /// * `role_id` - The role ID to check.
    #[action]
    fn role_policy(fractal: AccountNumber, role_id: u8) -> auth_dyn::policy::DynamicAuthPolicy {
        unimplemented!()
    }
}

#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FractalRole {
    Legislature = 1,
    Judiciary = 2,
    Executive = 3,
    Recruitment = 4,
}

impl From<u8> for FractalRole {
    fn from(value: u8) -> Self {
        match value {
            1 => FractalRole::Legislature,
            2 => FractalRole::Judiciary,
            3 => FractalRole::Executive,
            4 => FractalRole::Recruitment,
            _ => abort_message(&format!("Invalid FractalRole value: {}", value)),
        }
    }
}

impl From<FractalRole> for u8 {
    fn from(value: FractalRole) -> Self {
        value as u8
    }
}

#[crate::service(name = "fractals", dispatch = false, psibase_mod = "crate")]
#[allow(non_snake_case, unused_variables)]
pub mod Service {
    use crate::services::auth_dyn::policy::DynamicAuthPolicy;
    use crate::services::transact::ServiceMethod;
    use crate::AccountNumber;

    /// Creates a new account and fractal.
    ///
    /// # Arguments
    /// * `fractal_account` - The account number for the new fractal.
    /// * `legislature` - Legislature role account.
    /// * `judiciary` - Judiciary role account.
    /// * `executive` - Executive role account
    /// * `recruitment` - Recruitment role account.
    /// * `name` - The name of the fractal.
    /// * `mission` - The mission statement of the fractal.
    #[action]
    fn create_frac(
        fractal_account: AccountNumber,
        legislature: AccountNumber,
        judiciary: AccountNumber,
        executive: AccountNumber,
        recruitment: AccountNumber,
        name: String,
        mission: String,
    ) {
        unimplemented!()
    }

    /// Add fractal member
    ///
    /// Adds an account to a fractal.
    ///
    /// # Arguments
    /// * `member` - Account to be added as a member
    /// * `recruiter` - Account of the fractal member that recruited this new member, if applicable.
    #[action]
    fn add_mem(member: AccountNumber, recruiter: Option<AccountNumber>) {
        unimplemented!()
    }

    /// Claim member rewards
    ///
    /// Sends any vested token rewards to the fractal member after applying any pending levies.
    ///
    /// # Arguments
    /// * `fractal` - The account number of the fractal.
    /// * `member` - The fractal member claiming rewards.
    #[action]
    fn claim_rew(fractal: AccountNumber, member: AccountNumber) {
        unimplemented!()
    }

    /// Set genesis time for a fractal
    ///
    /// Genesis time sets the starting point of when fractal token rewards can be claimed.
    /// Subsequent claims are according to the distribution interval set for the fractal.
    ///
    /// # Arguments
    /// * `genesis_time` - New genesis time for the fractal.
    #[action]
    fn set_gen_time(genesis_time: u64) {
        unimplemented!()
    }

    /// Check if an account is a member of a fractal.
    ///
    /// # Arguments
    /// * `fractal` - The account number of the fractal.
    /// * `member` - The account to check.
    #[action]
    fn is_member(fractal: AccountNumber, member: AccountNumber) -> bool {
        unimplemented!()
    }

    /// Set ordered occupations
    ///
    /// Payment for each ordered occupation will be according to the fractals payment strategy.
    ///
    /// # Arguments
    /// * `paid_occupations` - Ordered occupations to set for the fractal
    #[action]
    fn set_paid_occ(paid_occupations: Vec<AccountNumber>) {
        unimplemented!()
    }

    /// Set Fractal distribution interval
    ///
    /// Used in conjunction with genesis time to determine when fractal token distribution can be triggered.
    ///
    /// # Arguments
    /// * `distribution_interval_secs` - New fractal distribution interval in seconds.
    #[action]
    fn set_dist_int(distribution_interval_secs: u32) {
        unimplemented!()
    }

    /// Exile a fractal member.
    ///
    /// # Arguments
    /// * `member` - The fractal member to be exiled.
    #[action]
    fn exile_member(member: AccountNumber) {
        unimplemented!()
    }

    /// Sets the occupation used to authorize the specified fractal role.
    ///
    /// # Arguments
    /// * `role_id` - Role ID for fractal
    /// * `new_occupation` - New occupation to set for role
    #[action]
    fn set_r_occ(role_id: u8, new_occupation: AccountNumber) {
        unimplemented!()
    }

    /// Set distribution strategy
    ///
    /// # Arguments
    /// * `distribution_strategy` - Algorithm for weighted distribution.
    #[action]
    fn set_dstrat(distribution_strategy: u8) {
        unimplemented!()
    }

    /// Get policy action used by AuthDyn service.
    ///
    /// # Arguments
    /// * `account` - Account being checked.
    /// * `method` - Optional method being checked.
    #[action]
    fn get_policy(account: AccountNumber, method: Option<ServiceMethod>) -> DynamicAuthPolicy {
        unimplemented!()
    }

    /// Has policy action used by AuthDyn service.
    ///
    /// # Arguments
    /// * `account` - Account being checked.
    #[action]
    fn has_policy(account: AccountNumber) -> bool {
        unimplemented!()
    }

    /// Distribute token for a fractal.
    #[action]
    fn dist_token(fractal: AccountNumber) {
        unimplemented!()
    }

    /// Initialise a token for a fractal.
    ///
    /// Called only once per fractal.
    /// Must be called by fractal.
    #[action]
    fn init_token() {
        unimplemented!()
    }

    #[event(history)]
    pub fn created_fractal(fractal_account: AccountNumber) {}

    #[event(history)]
    pub fn joined_fractal(fractal_account: AccountNumber, account: AccountNumber) {}
}

#[test]
fn verify_schema() {
    crate::assert_schema_matches_package::<Wrapper>();
}