alephium_web3/token/
mod.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct Token {
9 pub id: String,
11 pub amount: String,
13}
14
15impl Token {
16 pub fn new(id: String, amount: String) -> Self {
18 Self { id, amount }
19 }
20
21 pub fn with_amount(id: String, amount: u128) -> Self {
23 Self {
24 id,
25 amount: amount.to_string(),
26 }
27 }
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct FungibleTokenMetadata {
33 pub symbol: String,
34 pub name: String,
35 pub decimals: u8,
36 #[serde(rename = "totalSupply")]
37 pub total_supply: String,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct NFTMetadata {
43 #[serde(rename = "tokenUri")]
44 pub token_uri: String,
45 #[serde(rename = "collectionId")]
46 pub collection_id: Option<String>,
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
51pub enum TokenType {
52 Fungible,
53 NonFungible,
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_token_creation() {
62 let token = Token::new("abc123".to_string(), "1000".to_string());
63 assert_eq!(token.id, "abc123");
64 assert_eq!(token.amount, "1000");
65 }
66
67 #[test]
68 fn test_token_with_amount() {
69 let token = Token::with_amount("xyz789".to_string(), 5000);
70 assert_eq!(token.amount, "5000");
71 }
72
73 #[test]
74 fn test_token_serialization() {
75 let token = Token::new("test_id".to_string(), "100".to_string());
76 let json = serde_json::to_string(&token).unwrap();
77 assert!(json.contains("test_id"));
78 assert!(json.contains("100"));
79 }
80}