use crate::wallet_state::MainnetWalletState;
use crate::CardanoWallet;
pub trait MainnetWalletStateBuilder {
fn as_representative(&self) -> MainnetWalletState;
fn as_direct_voter(&self) -> MainnetWalletState;
fn as_direct_voter_on_slot_no(&self, slot_no: u64) -> MainnetWalletState;
fn as_delegator(&self, delegations: Vec<(&CardanoWallet, u8)>) -> MainnetWalletState;
fn as_delegator_on_slot_no(
&self,
delegations: Vec<(&CardanoWallet, u8)>,
slot_no: u64,
) -> MainnetWalletState;
}
impl MainnetWalletStateBuilder for CardanoWallet {
fn as_representative(&self) -> MainnetWalletState {
MainnetWalletState {
rep: Some(self.catalyst_public_key()),
registration_tx: None,
stake: self.stake(),
stake_address: self.reward_address().to_address(),
}
}
fn as_direct_voter(&self) -> MainnetWalletState {
self.as_direct_voter_on_slot_no(0)
}
fn as_direct_voter_on_slot_no(&self, slot_no: u64) -> MainnetWalletState {
MainnetWalletState {
rep: None,
registration_tx: Some(self.generate_direct_voting_registration(slot_no)),
stake: self.stake(),
stake_address: self.reward_address().to_address(),
}
}
fn as_delegator(&self, delegations: Vec<(&CardanoWallet, u8)>) -> MainnetWalletState {
self.as_delegator_on_slot_no(delegations, 0)
}
fn as_delegator_on_slot_no(
&self,
delegations: Vec<(&CardanoWallet, u8)>,
slot_no: u64,
) -> MainnetWalletState {
MainnetWalletState {
rep: None,
registration_tx: Some(
self.generate_delegated_voting_registration(
delegations
.into_iter()
.map(|(wallet, weight)| (wallet.catalyst_public_key(), u32::from(weight)))
.collect(),
slot_no,
),
),
stake: self.stake(),
stake_address: self.reward_address().to_address(),
}
}
}