@@ -4,9 +4,15 @@ use near_sdk::{
4
4
serde:: { Deserialize , Serialize } ,
5
5
serde_json, AccountId ,
6
6
} ;
7
- use sweat_jar_model:: { jar:: JarId , ProductId } ;
8
-
9
- use crate :: { common:: Timestamp , env, jar:: model:: Jar , product:: model:: Product , PACKAGE_NAME , VERSION } ;
7
+ use sweat_jar_model:: { jar:: JarId , ProductId , TokenAmount } ;
8
+
9
+ use crate :: {
10
+ common:: Timestamp ,
11
+ env,
12
+ jar:: model:: { JarCache , JarV1 } ,
13
+ product:: model:: Product ,
14
+ PACKAGE_NAME , VERSION ,
15
+ } ;
10
16
11
17
#[ derive( Serialize , Deserialize , Debug ) ]
12
18
#[ serde(
@@ -17,7 +23,7 @@ use crate::{common::Timestamp, env, jar::model::Jar, product::model::Product, PA
17
23
) ]
18
24
pub enum EventKind {
19
25
RegisterProduct ( Product ) ,
20
- CreateJar ( Jar ) ,
26
+ CreateJar ( EventJar ) ,
21
27
Claim ( Vec < ClaimEventItem > ) ,
22
28
Withdraw ( WithdrawData ) ,
23
29
Migration ( Vec < MigrationEventItem > ) ,
@@ -29,6 +35,36 @@ pub enum EventKind {
29
35
TopUp ( TopUpData ) ,
30
36
}
31
37
38
+ #[ derive( Serialize , Deserialize , Debug ) ]
39
+ #[ serde( crate = "near_sdk::serde" , rename_all = "snake_case" ) ]
40
+ pub struct EventJar {
41
+ id : JarId ,
42
+ account_id : AccountId ,
43
+ product_id : ProductId ,
44
+ created_at : Timestamp ,
45
+ principal : TokenAmount ,
46
+ cache : Option < JarCache > ,
47
+ claimed_balance : TokenAmount ,
48
+ is_pending_withdraw : bool ,
49
+ is_penalty_applied : bool ,
50
+ }
51
+
52
+ impl From < JarV1 > for EventJar {
53
+ fn from ( value : JarV1 ) -> Self {
54
+ Self {
55
+ id : value. id ,
56
+ account_id : value. account_id ,
57
+ product_id : value. product_id ,
58
+ created_at : value. created_at ,
59
+ principal : value. principal ,
60
+ cache : value. cache ,
61
+ claimed_balance : value. claimed_balance ,
62
+ is_pending_withdraw : value. is_pending_withdraw ,
63
+ is_penalty_applied : value. is_penalty_applied ,
64
+ }
65
+ }
66
+ }
67
+
32
68
#[ derive( Serialize , Deserialize , Debug ) ]
33
69
#[ serde( crate = "near_sdk::serde" , rename_all = "snake_case" ) ]
34
70
struct SweatJarEvent {
@@ -142,16 +178,19 @@ impl SweatJarEvent {
142
178
143
179
#[ cfg( test) ]
144
180
mod test {
145
- use near_sdk:: json_types:: U128 ;
181
+ use near_sdk:: { json_types:: U128 , AccountId } ;
146
182
147
- use crate :: event:: { EventKind , SweatJarEvent , TopUpData } ;
183
+ use crate :: {
184
+ event:: { EventKind , SweatJarEvent , TopUpData } ,
185
+ jar:: model:: JarV1 ,
186
+ } ;
148
187
149
188
#[ test]
150
189
fn event_to_string ( ) {
151
190
assert_eq ! (
152
191
SweatJarEvent :: from( EventKind :: TopUp ( TopUpData {
153
192
id: 10 ,
154
- amount: U128 ( 50 )
193
+ amount: U128 ( 50 ) ,
155
194
} ) )
156
195
. to_json_event_string( ) ,
157
196
r#"EVENT_JSON:{
@@ -163,6 +202,41 @@ mod test {
163
202
"amount": "50"
164
203
}
165
204
}"#
166
- )
205
+ ) ;
206
+
207
+ assert_eq ! (
208
+ SweatJarEvent :: from( EventKind :: CreateJar (
209
+ JarV1 {
210
+ id: 555 ,
211
+ account_id: AccountId :: new_unchecked( "bob.near" . to_string( ) ) ,
212
+ product_id: "some_product" . to_string( ) ,
213
+ created_at: 1234324235 ,
214
+ principal: 78685678567 ,
215
+ cache: None ,
216
+ claimed_balance: 4324 ,
217
+ is_pending_withdraw: false ,
218
+ is_penalty_applied: false ,
219
+ claim_remainder: 55555 ,
220
+ }
221
+ . into( )
222
+ ) )
223
+ . to_json_event_string( ) ,
224
+ r#"EVENT_JSON:{
225
+ "standard": "sweat_jar",
226
+ "version": "1.0.0",
227
+ "event": "create_jar",
228
+ "data": {
229
+ "id": 555,
230
+ "account_id": "bob.near",
231
+ "product_id": "some_product",
232
+ "created_at": 1234324235,
233
+ "principal": 78685678567,
234
+ "cache": null,
235
+ "claimed_balance": 4324,
236
+ "is_pending_withdraw": false,
237
+ "is_penalty_applied": false
238
+ }
239
+ }"#
240
+ ) ;
167
241
}
168
242
}
0 commit comments