dpp/data_contract/accessors/v1/
mod.rs

1use crate::block::epoch::EpochIndex;
2use crate::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters};
3use crate::data_contract::associated_token::token_configuration::TokenConfiguration;
4use crate::data_contract::group::Group;
5use crate::data_contract::{GroupContractPosition, TokenContractPosition};
6use crate::identity::TimestampMillis;
7use crate::prelude::BlockHeight;
8use crate::ProtocolError;
9use platform_value::Identifier;
10use std::collections::BTreeMap;
11
12pub trait DataContractV1Getters: DataContractV0Getters {
13    /// Returns a reference to the groups map.
14    fn groups(&self) -> &BTreeMap<GroupContractPosition, Group>;
15
16    /// Returns a mutable reference to the groups map.
17    fn groups_mut(&mut self) -> Option<&mut BTreeMap<GroupContractPosition, Group>>;
18
19    /// Returns a reference to a group or an error.
20    /// Returns an error for V0 since it doesn't have groups.
21    fn expected_group(&self, position: GroupContractPosition) -> Result<&Group, ProtocolError>;
22
23    /// Returns a reference to the tokens map.
24    fn tokens(&self) -> &BTreeMap<TokenContractPosition, TokenConfiguration>;
25
26    /// Returns a mutable reference to the tokens map.
27    fn tokens_mut(&mut self) -> Option<&mut BTreeMap<TokenContractPosition, TokenConfiguration>>;
28
29    /// Returns a mutable reference to a token configuration or an error.
30    /// Returns an error for V0 since it doesn't have tokens.
31    fn expected_token_configuration(
32        &self,
33        position: TokenContractPosition,
34    ) -> Result<&TokenConfiguration, ProtocolError>;
35
36    /// Returns a mutable reference to a token configuration.
37    /// Returns `None` for V0 since it doesn't have tokens.
38    fn token_configuration_mut(
39        &mut self,
40        position: TokenContractPosition,
41    ) -> Option<&mut TokenConfiguration>;
42
43    /// Returns the token id at a certain position.
44    fn token_id(&self, position: TokenContractPosition) -> Option<Identifier>;
45
46    /// Returns the timestamp in milliseconds when the contract was created.
47    fn created_at(&self) -> Option<TimestampMillis>;
48
49    /// Returns the timestamp in milliseconds when the contract was last updated.
50    fn updated_at(&self) -> Option<TimestampMillis>;
51
52    /// Returns the block height at which the contract was created.
53    fn created_at_block_height(&self) -> Option<BlockHeight>;
54
55    /// Returns the block height at which the contract was last updated.
56    fn updated_at_block_height(&self) -> Option<BlockHeight>;
57
58    /// Returns the epoch at which the contract was created.
59    fn created_at_epoch(&self) -> Option<EpochIndex>;
60
61    /// Returns the epoch at which the contract was last updated.
62    fn updated_at_epoch(&self) -> Option<EpochIndex>;
63
64    /// Returns the keywords for the contract.
65    fn keywords(&self) -> &Vec<String>;
66
67    /// Returns a mutable reference to the keywords for the contract.
68    fn keywords_mut(&mut self) -> Option<&mut Vec<String>>;
69
70    /// Returns the description for the contract.
71    fn description(&self) -> Option<&String>;
72
73    /// Returns a mutable reference to the description for the contract.
74    fn description_mut(&mut self) -> Option<&mut String>;
75}
76
77pub trait DataContractV1Setters: DataContractV0Setters {
78    /// Sets the groups map for the data contract.
79    fn set_groups(&mut self, groups: BTreeMap<GroupContractPosition, Group>);
80
81    /// Sets the tokens map for the data contract.
82    fn set_tokens(&mut self, tokens: BTreeMap<TokenContractPosition, TokenConfiguration>);
83
84    /// Adds or updates a single group in the groups map.
85    fn add_group(&mut self, pos: GroupContractPosition, group: Group);
86
87    /// Adds or updates a single token configuration in the tokens map.
88    fn add_token(&mut self, pos: TokenContractPosition, token: TokenConfiguration);
89
90    /// Sets the timestamp in milliseconds when the contract was created.
91    fn set_created_at(&mut self, created_at: Option<TimestampMillis>);
92
93    /// Sets the timestamp in milliseconds when the contract was last updated.
94    fn set_updated_at(&mut self, updated_at: Option<TimestampMillis>);
95
96    /// Sets the block height at which the contract was created.
97    fn set_created_at_block_height(&mut self, block_height: Option<BlockHeight>);
98
99    /// Sets the block height at which the contract was last updated.
100    fn set_updated_at_block_height(&mut self, block_height: Option<BlockHeight>);
101
102    /// Sets the epoch at which the contract was created.
103    fn set_created_at_epoch(&mut self, epoch: Option<EpochIndex>);
104
105    /// Sets the block height at which the contract was last updated.
106    fn set_updated_at_epoch(&mut self, epoch: Option<EpochIndex>);
107
108    /// Sets the keywords for the contract.
109    fn set_keywords(&mut self, keywords: Vec<String>);
110
111    /// Sets the description for the contract.
112    fn set_description(&mut self, description: Option<String>);
113}