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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crate::{
    account::{DelegationType, Identifier},
    certificate::{
        Certificate, OwnerStakeDelegation, PoolId, PoolRegistration, PoolRetirement, PoolUpdate,
        StakeDelegation, UpdateProposal, UpdateProposalId, UpdateProposerId, UpdateVote,
        UpdateVoterId, VotePlanId, VoteTally,
    },
    config::ConfigParam,
    fragment::ConfigParams,
    testing::data::AddressData,
    transaction::UnspecifiedAccountIdentifier,
};
use chain_time::units::DurationSeconds;

pub fn build_stake_delegation_cert(
    stake_pool: &PoolRegistration,
    delegate_from: &AddressData,
) -> Certificate {
    let account_id = UnspecifiedAccountIdentifier::from_single_account(Identifier::from(
        delegate_from.delegation_key(),
    ));
    Certificate::StakeDelegation(StakeDelegation {
        account_id,
        delegation: DelegationType::Full(stake_pool.to_id()),
    })
}

pub fn build_stake_pool_registration_cert(stake_pool: &PoolRegistration) -> Certificate {
    Certificate::PoolRegistration(stake_pool.clone())
}

pub fn build_stake_pool_update_cert(stake_pool: &PoolUpdate) -> Certificate {
    Certificate::PoolUpdate(stake_pool.clone())
}

pub fn build_owner_stake_full_delegation(stake_pool: PoolId) -> Certificate {
    Certificate::OwnerStakeDelegation(OwnerStakeDelegation {
        delegation: DelegationType::Full(stake_pool),
    })
}

pub fn build_no_stake_delegation() -> Certificate {
    Certificate::OwnerStakeDelegation(OwnerStakeDelegation {
        delegation: DelegationType::NonDelegated,
    })
}

pub fn build_owner_stake_delegation(delegation_type: DelegationType) -> Certificate {
    Certificate::OwnerStakeDelegation(OwnerStakeDelegation {
        delegation: delegation_type,
    })
}

pub fn build_stake_pool_retirement_cert(pool_id: PoolId, start_validity: u64) -> Certificate {
    let retirement = PoolRetirement {
        pool_id,
        retirement_time: DurationSeconds(start_validity).into(),
    };

    Certificate::PoolRetirement(retirement)
}

pub fn build_vote_tally_cert(vote_id: VotePlanId) -> Certificate {
    Certificate::VoteTally(VoteTally::new_public(vote_id))
}

pub fn build_update_proposal_cert(
    proposer_id: UpdateProposerId,
    config_params: Vec<ConfigParam>,
) -> Certificate {
    let update_proposal = UpdateProposal::new(ConfigParams(config_params), proposer_id);
    Certificate::UpdateProposal(update_proposal)
}

pub fn build_update_vote_cert(
    proposal_id: UpdateProposalId,
    voter_id: UpdateVoterId,
) -> Certificate {
    let update_vote = UpdateVote::new(proposal_id, voter_id);
    Certificate::UpdateVote(update_vote)
}