- Workspace: core/ (blockchain library) + node/ (REST API) - Core: block, chain, wallet, transaction, mining, persistence, state - Node: axum 0.8 REST API with full endpoint set - SHA-256 hashing, Ed25519 signatures, account-based model - Unit tests for all core modules
31 lines
607 B
Rust
31 lines
607 B
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
/// Account state in the account-based model.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
pub struct AccountState {
|
|
pub balance: u64,
|
|
pub nonce: u64,
|
|
}
|
|
|
|
impl AccountState {
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
pub fn with_balance(balance: u64) -> Self {
|
|
AccountState { balance, nonce: 0 }
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_default_account() {
|
|
let account = AccountState::new();
|
|
assert_eq!(account.balance, 0);
|
|
assert_eq!(account.nonce, 0);
|
|
}
|
|
}
|