1
1
pub mod receiver;
2
2
3
+ use anyhow:: anyhow;
4
+ use cid:: Cid ;
5
+
6
+ use fvm_ipld_blockstore:: Blockstore ;
7
+ use fvm_ipld_encoding:: tuple:: * ;
8
+ use fvm_ipld_encoding:: Cbor ;
9
+ use fvm_ipld_hamt:: Hamt ;
10
+
3
11
use fvm_shared:: address:: Address ;
12
+ use fvm_shared:: bigint:: bigint_ser;
4
13
pub use fvm_shared:: econ:: TokenAmount ;
14
+ use fvm_shared:: HAMT_BIT_WIDTH ;
5
15
6
16
pub type Result < T > = std:: result:: Result < T , TokenError > ;
7
17
pub enum TokenError { }
@@ -28,3 +38,82 @@ pub trait Token {
28
38
29
39
fn burn_from ( from : Address , amount : TokenAmount , data : & [ u8 ] ) -> Result < TokenAmount > ;
30
40
}
41
+
42
+ /// Token actor state
43
+ #[ derive( Serialize_tuple , Deserialize_tuple , Clone ) ]
44
+ pub struct DefaultToken {
45
+ #[ serde( with = "bigint_ser" ) ]
46
+ supply : TokenAmount ,
47
+ name : String ,
48
+ symbol : String ,
49
+
50
+ balances : Cid ,
51
+ allowances : Cid ,
52
+ }
53
+
54
+ /// Default token implementation
55
+ impl DefaultToken {
56
+ pub fn new < BS > ( name : & str , symbol : & str , store : & BS ) -> anyhow:: Result < Self >
57
+ where
58
+ BS : Blockstore ,
59
+ {
60
+ let empty_balance_map = Hamt :: < _ , ( ) > :: new_with_bit_width ( store, HAMT_BIT_WIDTH )
61
+ . flush ( )
62
+ . map_err ( |e| anyhow ! ( "Failed to create empty balances map state {}" , e) ) ?;
63
+ let empty_allowances_map = Hamt :: < _ , ( ) > :: new_with_bit_width ( store, HAMT_BIT_WIDTH )
64
+ . flush ( )
65
+ . map_err ( |e| anyhow ! ( "Failed to create empty balances map state {}" , e) ) ?;
66
+
67
+ Ok ( Self {
68
+ supply : Default :: default ( ) ,
69
+ name : name. to_string ( ) ,
70
+ symbol : symbol. to_string ( ) ,
71
+ balances : empty_balance_map,
72
+ allowances : empty_allowances_map,
73
+ } )
74
+ }
75
+ }
76
+
77
+ impl Cbor for DefaultToken { }
78
+
79
+ impl Token for DefaultToken {
80
+ fn name ( ) -> String {
81
+ todo ! ( )
82
+ }
83
+
84
+ fn symbol ( ) -> String {
85
+ todo ! ( )
86
+ }
87
+
88
+ fn total_supply ( ) -> TokenAmount {
89
+ todo ! ( )
90
+ }
91
+
92
+ fn balance_of ( holder : Address ) -> Result < TokenAmount > {
93
+ todo ! ( )
94
+ }
95
+
96
+ fn increase_allowance ( spender : Address , value : TokenAmount ) -> Result < TokenAmount > {
97
+ todo ! ( )
98
+ }
99
+
100
+ fn decrease_allowance ( spender : Address , value : TokenAmount ) -> Result < TokenAmount > {
101
+ todo ! ( )
102
+ }
103
+
104
+ fn revoke_allowance ( spender : Address ) -> Result < ( ) > {
105
+ todo ! ( )
106
+ }
107
+
108
+ fn allowance ( owner : Address , spender : Address ) -> Result < TokenAmount > {
109
+ todo ! ( )
110
+ }
111
+
112
+ fn burn ( amount : TokenAmount , data : & [ u8 ] ) -> Result < TokenAmount > {
113
+ todo ! ( )
114
+ }
115
+
116
+ fn burn_from ( from : Address , amount : TokenAmount , data : & [ u8 ] ) -> Result < TokenAmount > {
117
+ todo ! ( )
118
+ }
119
+ }
0 commit comments