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
use anchor_lang::prelude::*;

/// Event that signals a new randomness request.
#[event]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Request {
    /// Randomness request seed.
    pub seed: [u8; 32],
    /// Client address.
    pub client: Pubkey,
    /// True if request is paid with SPL token.
    pub paid_with_spl: bool,
}

#[cfg(feature = "sdk")]
impl std::fmt::Display for Request {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "Request: seed={} client={} paid_with_spl={}",
            anchor_client::solana_sdk::bs58::encode(&self.seed[..]).into_string(),
            self.client,
            self.paid_with_spl,
        )
    }
}

/// Event that signals a fulfilled randomness request.
#[event]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Fulfill {
    /// Randomness request seed.
    pub seed: [u8; 32],
    /// Generated randomness.
    pub randomness: [u8; 64],
}

#[cfg(feature = "sdk")]
impl std::fmt::Display for Fulfill {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "Fulfill: seed={} randomness={}",
            anchor_client::solana_sdk::bs58::encode(&self.seed[..]).into_string(),
            anchor_client::solana_sdk::bs58::encode(&self.randomness[..]).into_string(),
        )
    }
}

/// Event that signals that a request was fulfilled by a single authority.
#[event]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Response {
    /// Randomness request seed.
    pub seed: [u8; 32],
    /// An authority that fulfilled the request.
    pub authority: Pubkey,
    /// An authority's randomness (for the final generated randomness see [`Fulfilled::randomness`]).
    pub randomness: [u8; 64],
}

#[cfg(feature = "sdk")]
impl std::fmt::Display for Response {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "Response: seed={} authority={} randomness={}",
            anchor_client::solana_sdk::bs58::encode(&self.seed[..]).into_string(),
            self.authority,
            anchor_client::solana_sdk::bs58::encode(&self.randomness[..]).into_string(),
        )
    }
}