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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
mod builder;
mod template;

pub use builder::MainnetWalletStateBuilder;
use std::fmt::{Debug, Formatter};
pub use template::{build, build_default, Actor, Error as TemplateError, ExternalProvider};

use cardano_serialization_lib::address::Address;
use cardano_serialization_lib::Transaction;
use jormungandr_lib::crypto::account::Identifier;

/// Represents wallet candidate for registration. Defines wallet role (delegator/direct-voter/representative)
pub struct MainnetWalletState {
    /// Possible identifier which define representative id
    pub rep: Option<Identifier>,
    /// Possible valid registration transaction
    pub registration_tx: Option<Transaction>,
    /// Ada amount account hold on snapshot time
    pub stake: u64,
    /// Stake address
    pub stake_address: Address,
}

impl Debug for MainnetWalletState {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        let mut fmt = f.debug_struct("MainnetWalletState");
        fmt.field("rep", &self.rep);
        fmt.field("stake", &self.stake);
        fmt.field("stake_address", &self.stake_address.to_hex());
        fmt.field(
            "metadata",
            &self
                .registration_tx
                .as_ref()
                .map(Transaction::auxiliary_data),
        );
        fmt.finish()
    }
}

impl MainnetWalletState {
    /// get representative information
    #[must_use]
    pub fn rep(&self) -> &Option<Identifier> {
        &self.rep
    }
    /// get registration metadata
    #[must_use]
    pub fn registration(&self) -> &Option<Transaction> {
        &self.registration_tx
    }
    /// get wallet stake
    #[must_use]
    pub fn stake(&self) -> u64 {
        self.stake
    }
    /// get stake address for wallet
    #[must_use]
    pub fn stake_address(&self) -> &Address {
        &self.stake_address
    }
}