1use crate::types::AccountAddress;
15use crate::types::events::EventHandle;
16use serde::{Deserialize, Serialize};
17
18#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
28pub struct AccountResource {
29 #[serde(with = "crate::types::string_num")]
31 pub sequence_number: u64,
32 pub authentication_key: String,
35 #[serde(default, with = "crate::types::string_num")]
37 pub guid_creation_num: u64,
38}
39
40impl AccountResource {
41 pub const TYPE: &'static str = "0x1::account::Account";
43}
44
45#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
49pub struct CoinStoreResource {
50 pub coin: CoinInfo,
52 pub frozen: bool,
54 pub deposit_events: EventHandle,
56 pub withdraw_events: EventHandle,
58}
59
60#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
62pub struct CoinInfo {
63 #[serde(with = "crate::types::string_num")]
65 pub value: u64,
66}
67
68impl CoinStoreResource {
69 pub fn balance(&self) -> u64 {
71 self.coin.value
72 }
73}
74
75#[allow(dead_code)]
77pub const APT_COIN_STORE_TYPE: &str = "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>";
78
79#[allow(dead_code)] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
82pub struct FungibleAssetBalance {
83 #[serde(with = "crate::types::string_num")]
85 pub balance: u64,
86 pub frozen: bool,
88}
89
90#[allow(dead_code)] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
93pub struct FungibleAssetMetadata {
94 pub name: String,
96 pub symbol: String,
98 pub decimals: u8,
100}
101
102#[allow(dead_code)] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
105pub struct CollectionData {
106 pub name: String,
108 pub description: String,
110 pub uri: String,
112 #[serde(with = "crate::types::string_num")]
114 pub current_supply: u64,
115 #[serde(with = "crate::types::string_num")]
117 pub maximum_supply: u64,
118}
119
120#[allow(dead_code)] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
123pub struct TokenData {
124 pub name: String,
126 pub description: String,
128 pub uri: String,
130 pub collection: AccountAddress,
132}
133
134#[allow(dead_code)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
137pub struct StakePool {
138 #[serde(with = "crate::types::string_num")]
140 pub active: u64,
141 #[serde(with = "crate::types::string_num")]
143 pub inactive: u64,
144 #[serde(with = "crate::types::string_num")]
146 pub pending_active: u64,
147 #[serde(with = "crate::types::string_num")]
149 pub pending_inactive: u64,
150 pub operator_address: AccountAddress,
152 pub delegated_voter: AccountAddress,
154}
155
156#[allow(dead_code)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
159pub struct StakingConfig {
160 #[serde(with = "crate::types::string_num")]
162 pub minimum_stake: u64,
163 #[serde(with = "crate::types::string_num")]
165 pub maximum_stake: u64,
166 #[serde(with = "crate::types::string_num")]
168 pub recurring_lockup_duration_secs: u64,
169 #[serde(with = "crate::types::string_num")]
171 pub rewards_rate: u64,
172 #[serde(with = "crate::types::string_num")]
174 pub rewards_rate_denominator: u64,
175}
176
177#[cfg(test)]
178mod tests {
179 use super::*;
180
181 #[test]
182 fn test_account_resource_type() {
183 assert_eq!(AccountResource::TYPE, "0x1::account::Account");
184 }
185
186 #[test]
187 fn test_coin_store_balance() {
188 use crate::types::events::{EventHandleGuid, EventHandleGuidId};
189 let handle = |creation_num| EventHandle {
190 counter: 0,
191 guid: EventHandleGuid {
192 id: EventHandleGuidId {
193 addr: AccountAddress::ONE,
194 creation_num,
195 },
196 },
197 };
198 let coin_store = CoinStoreResource {
199 coin: CoinInfo { value: 1000 },
200 frozen: false,
201 deposit_events: handle(0),
202 withdraw_events: handle(1),
203 };
204 assert_eq!(coin_store.balance(), 1000);
205 }
206
207 #[test]
208 fn test_account_resource_api_json() {
209 let json = r#"{
212 "authentication_key": "0x0000000000000000000000000000000000000000000000000000000000000001",
213 "coin_register_events": {
214 "counter": "1",
215 "guid": {"id": {"addr": "0x1", "creation_num": "0"}}
216 },
217 "guid_creation_num": "4",
218 "key_rotation_events": {
219 "counter": "0",
220 "guid": {"id": {"addr": "0x1", "creation_num": "1"}}
221 },
222 "rotation_capability_offer": {"for": {"vec": []}},
223 "sequence_number": "42",
224 "signer_capability_offer": {"for": {"vec": []}}
225 }"#;
226
227 let account: AccountResource = serde_json::from_str(json).unwrap();
228 assert_eq!(account.sequence_number, 42);
229 assert_eq!(account.guid_creation_num, 4);
230 assert_eq!(
231 account.authentication_key,
232 "0x0000000000000000000000000000000000000000000000000000000000000001"
233 );
234 }
235
236 #[test]
237 fn test_coin_store_resource_api_json() {
238 let json = r#"{
240 "coin": {"value": "999999"},
241 "deposit_events": {
242 "counter": "3",
243 "guid": {"id": {"addr": "0x1", "creation_num": "2"}}
244 },
245 "frozen": false,
246 "withdraw_events": {
247 "counter": "0",
248 "guid": {"id": {"addr": "0x1", "creation_num": "3"}}
249 }
250 }"#;
251
252 let store: CoinStoreResource = serde_json::from_str(json).unwrap();
253 assert_eq!(store.balance(), 999_999);
254 assert!(!store.frozen);
255 assert_eq!(store.deposit_events.counter, 3);
256 assert_eq!(store.deposit_events.guid.id.creation_num, 2);
257 assert_eq!(store.deposit_events.guid.id.addr, AccountAddress::ONE);
258 }
259}