use serde::{Deserialize, Serialize};
use thiserror::Error;
pub const ADDRESS_SIZE: usize = 12;
pub const HASH_SIZE: usize = 32;
pub const SLOT_SIZE: usize = 64;
pub const NODE_ACTIVITY_SIZE: usize = 16;
pub const HISTORY_SIZE: usize = 29;
pub const PULSE_INTERVAL_MS: u64 = 1500;
pub const DEFAULT_LADDER_HEIGHT: usize = 100_000;
pub const ROLE_SHUFFLE_PULSES: u64 = 4800;
pub const DIAMOND_REWARD_PERC: u64 = 60;
pub const GOLD_REWARD_PERC: u64 = 30;
pub const REGULAR_REWARD_PERC: u64 = 10;
pub const COIN_DECIMALS: u32 = 8;
pub const ONE_YD: u64 = 100_000_000;
pub const MAX_SUPPLY: u64 = 19_000_000 * ONE_YD;
pub const INITIAL_PULSE_REWARD: u64 = 12_500_000;
pub const HALVING_PULSES: u64 = 1_000_000;
pub type Address = [u8; ADDRESS_SIZE];
pub type Hash = [u8; HASH_SIZE];
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Slot {
pub pulse_id: u64,
pub user_address: Address,
pub step_number: u32,
pub ladder_id: u32,
pub balance: u64,
pub last_hash: Hash,
}
impl Slot {
pub fn new(user_address: Address, ladder_id: u32, step_number: u32, last_hash: Hash) -> Self {
Self {
pulse_id: 1,
user_address,
step_number,
ladder_id,
balance: 0,
last_hash,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SlotKey {
pub user_address: String,
pub ladder_id: u32,
pub last_hash: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Transaction {
pub timestamp: u64,
pub from: Address,
pub to: Address,
pub amount: u64,
pub proof: Hash,
pub ots_pk: Hash,
pub signature: Hash,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct HistoryRecordRaw {
pub tx_type: u8,
pub peer_address: Address,
pub amount: u64,
pub timestamp: u64,
}
#[derive(Error, Debug, Clone, Serialize, Deserialize)]
pub enum YedadError {
#[error("IO/DB Error: {0}")]
Io(String),
#[error("Account not found")]
AccountNotFound,
#[error("Account already exists")]
AccountAlreadyExists,
#[error("Arithmetic overflow")]
ArithmeticOverflow,
#[error("Insufficient balance")]
InsufficientBalance,
#[error("Invalid transaction proof")]
InvalidProof,
#[error("Ladder exhausted")]
LadderExhausted,
#[error("Invalid ladder index")]
InvalidLadderIndex,
#[error("Step out of range")]
StepOutOfRange,
#[error("Hash not found")]
HashNotFound,
#[error("Invalid OTS signature")]
InvalidSignature,
#[error("Internal RNG failure")]
Rng,
#[error("Invalid input size")]
InvalidInputSize,
}