1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! The methods that an implementor must provide for the Mina 'ledger' primitive in order to
//! use this implementation.
//!
//! For more detail on these types and the implementation of these functions, refer to existing
//! documentation and specification for the Mina protocol.

use crate::account;
use crate::primitives::*;

/// Interface for ledgers
pub trait Ledger {
    /// Type of positions in the ledger
    type Index;

    /// Return the root hash of the ledger
    fn root_hash(ledger: &Self) -> Hash;

    /// Find the position in the ledger for the account with public key `public_key`.
    ///
    /// If there is no account in the ledger with public key `public_key`, `find_index(public_key)`
    /// must return `None`.
    fn find_index(ledger: &Self, public_key: PublicKey) -> Option<Self::Index>;

    /// Return the next unused index in the ledger.
    ///
    /// If there are no unused indexes remaining in the ledger, this function must raise an error
    /// that aborts the transaction as invalid.
    fn next_index(ledger: &Self) -> Self::Index;

    /// Return the account in the ledger at the given index.
    fn get_account<'a>(ledger: &Self, index: &Self::Index) -> account::Account<'a>;

    /// Set the contents of the account in the ledger at the specified index.
    fn set_account(ledger: &mut Self, index: &Self::Index, account: account::Account);
}