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
//! <https://github.com/EOSIO/eosio.cdt/blob/796ff8bee9a0fc864f665a0a4d018e0ff18ac383/libraries/eosiolib/contracts/eosio/producer_schedule.hpp#L54-L69>
use crate::{AccountName, NumBytes, PublicKey, Read, Write};
use alloc::{vec, vec::Vec};

/// Maps producer with its signing key, used for producer schedule
/// <https://github.com/EOSIO/eosio.cdt/blob/796ff8bee9a0fc864f665a0a4d018e0ff18ac383/libraries/eosiolib/contracts/eosio/producer_schedule.hpp#L15-L45>
#[derive(Read, Write, NumBytes, Clone, Default, Debug)]
#[eosio(crate_path = "crate::bytes")]
pub struct ProducerKey {
    /// Name of the producer
    pub producer_name: AccountName,
    /// Block signing key used by this producer
    pub block_signing_key: PublicKey,
}

/// Defines both the order, account name, and signing keys of the active set
/// of producers.
#[derive(Read, Write, NumBytes, Clone, Default, Debug)]
#[eosio(crate_path = "crate::bytes")]
pub struct ProducerSchedule {
    /// Version number of the schedule. It is sequentially incrementing
    /// version number.
    pub version: u32,
    /// List of producers for this schedule, including its signing key
    pub producers: Vec<ProducerKey>,
}

/// pairs a public key with an integer weight
#[derive(Read, Write, NumBytes, Clone, Default, Debug)]
#[eosio(crate_path = "crate::bytes")]
pub struct KeyWeight {
    /// public key used in a weighted threshold multi-sig authority
    pub key: PublicKey,
    /// weight associated with a signature from the private key associated with
    /// the accompanying public key
    pub weight: u64,
}

impl From<PublicKey> for KeyWeight {
    fn from(key: PublicKey) -> Self {
        Self { key, weight: 1 }
    }
}

/// block signing authority version 0
/// this authority allows for a weighted threshold multi-sig per-producer
#[derive(Read, Write, NumBytes, Clone, Default, Debug)]
#[eosio(crate_path = "crate::bytes")]
pub struct BlockSigningAuthority {
    /// minimum threshold of accumulated weights from component keys that
    /// satisfies this authority
    pub threshold: u32,
    /// component keys and their associated weights
    pub keys: Vec<KeyWeight>,
}

impl From<PublicKey> for BlockSigningAuthority {
    #[inline]
    fn from(key: PublicKey) -> Self {
        Self {
            threshold: 1,
            keys: vec![key.into()],
        }
    }
}

/// Maps producer with its signing key, used for producer schedule
#[derive(Read, Write, NumBytes, Clone, Default, Debug)]
#[eosio(crate_path = "crate::bytes")]
pub struct ProducerAuthority {
    /// Name of the producer
    pub producer_name: AccountName,
    /// The block signing authority used by this producer
    pub authority: BlockSigningAuthority,
}