-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.rs
More file actions
644 lines (600 loc) · 27.5 KB
/
main.rs
File metadata and controls
644 lines (600 loc) · 27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
mod verify;
use std::{collections::HashSet, f64::consts::E, str::FromStr};
use cosmrs::tendermint::signature;
use futures::stream::TryBufferUnordered;
use jito_merkle_tree::csv_entry::AirdropCategory;
use solana_sdk::pubkey::Pubkey;
use sp_core::H160;
use verify::{get_signed_message, validate_eth_signature};
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use utoipa_swagger_ui::SwaggerUi;
use utoipa::{
openapi::security::{ApiKey, ApiKeyValue, SecurityScheme},
Modify, OpenApi,
};
#[derive(Serialize, Deserialize, ToSchema, Clone)]
pub struct SignatureParams {
signatures: String,
pubkey: String,
message: String,
network: u8, //0 eth, 1 cosmos,2 polkadot
signatures_bytes: Option<Vec<u8>>,
message_bytes: Option<Vec<u8>>,
cosmos_public_without_prefix: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Debug, ToSchema)]
pub struct VestingResp {
pub is_success: bool,
pub error_message: Option<String>,
pub page_index: Option<u8>,
pub amount_unlocked: u64,
pub amount_locked: u64,
}
//post method to store new CmcSymbols
#[utoipa::path(
post,
path = "/vesting/domain/submitsignature",
params(
("cmc_symbol" = CmcSymbolsStoreParams, description = "The Signatures to be stored")
),
responses(
(status = 200, description = "Successfully accept signatures", body = String),
(status = 400, description = "Invalid request parameters")
)
)]
pub async fn submit_signature(
signature_params: web::Json<SignatureParams>,
) -> impl Responder {
use jito_merkle_tree::csv_entry::CsvEntry;
use std::path::PathBuf;
let post_params = signature_params.into_inner();
let path_to_drop_file = "/data/mantis-indexer/mantis-indexer/dropped.json";
let file_to_drop_csv = "/data/mantis-indexer/mantis-indexer/ethcosmosclaimprod.csv";
println!("{}", file_to_drop_csv);
let distribution_file = &PathBuf::from(file_to_drop_csv);
let entity = CsvEntry::new_from_file(&distribution_file).expect("Failed to parse CSV");
//find the claimant in the csv file
let claimant_entity = entity.iter().find(|x| x.pubkey == post_params.pubkey);
if claimant_entity == None {
let ret = VestingResp {
is_success: false,
error_message: Some("Claimant not found".to_string()),
page_index: None,
amount_locked: 0,
amount_unlocked: 0,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
let amount_unlocked = ui_amount_to_token_amount(claimant_entity.unwrap().amount_unlocked);
let amount_locked = ui_amount_to_token_amount(claimant_entity.unwrap().amount_locked);
//read data from json file
let json_data_from_file = std::fs::read_to_string(path_to_drop_file).expect("Unable to read file");
//deserialize the json data
let mut dropped_data: Vec<DroppedItem> = serde_json::from_str(&json_data_from_file).expect("Unable to deserialize");
//validate that no dublicate claimant is in the dropped list
//better to use hashmap for this but already started with vector so need to validate that no dublicate claimant is in the dropped list
let mut seen = HashSet::new();
for item in dropped_data.iter() {
if !seen.insert(item.address.clone()) {
println!("Dublicate entry: {:?}", item);
let ret = VestingResp {
is_success: false,
error_message: Some("Dublicate entry".to_string()),
page_index: None,
amount_locked: 0,
amount_unlocked: 0,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
}
fn exists_data_in_file(path_to_drop_file: &str, search: String) -> bool{
let json_data_from_file = std::fs::read_to_string(path_to_drop_file).expect("Unable to read file");
//deserialize the json data
let dropped_data: Vec<DroppedItem> = serde_json::from_str(&json_data_from_file).expect("Unable to deserialize");
let dropped_entity = dropped_data.iter().any(|x| x.address == search);
dropped_entity
}
fn update_data_in_file(path_to_drop_file: &str, updated_item: DroppedItem){
let json_data_from_file = std::fs::read_to_string(path_to_drop_file).expect("Unable to read file");
//deserialize the json data
let mut dropped_data: Vec<DroppedItem> = serde_json::from_str(&json_data_from_file).expect("Unable to deserialize");
let dropped_entity = dropped_data.iter().find(|x| x.address == updated_item.address).unwrap();
let index = dropped_data.iter().position(|x| x.address == updated_item.address).unwrap();
dropped_data[index] = updated_item;
let json_data = serde_json::to_string(&dropped_data).expect("Unable to serialize");
std::fs::write(path_to_drop_file, json_data).expect("Unable to write file");
}
//find the claimant in the dropped list
let dropped_entity = dropped_data.iter().find(|x| x.address == post_params.pubkey);
if dropped_entity.is_some() && (dropped_entity.unwrap().success || dropped_entity.unwrap().signature.is_some() ){
println!("Claimant already recieved airdrop: {:?}", dropped_entity.unwrap());
let ret = VestingResp {
is_success: false,
error_message: Some("Claimant already recieved airdrop".to_string()),
page_index: Some(1),
amount_locked: amount_locked,
amount_unlocked: amount_unlocked,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
let dropped_entity = dropped_data.iter().find(|x| x.solana_address == post_params.message);
if dropped_entity.is_some() && (dropped_entity.unwrap().success || dropped_entity.unwrap().signature.is_some() ){
let error = format!("This solana wallet already linked to this address: {}. Please use another solana wallet", dropped_entity.unwrap().address);
println!("{}", error.clone());
let ret = VestingResp {
is_success: false,
error_message: Some(error),
page_index: Some(1),
amount_locked: amount_locked,
amount_unlocked: amount_unlocked,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
if post_params.network == 0 {
let address_str: H160 = post_params.pubkey.parse().unwrap();
let signed_message = get_signed_message(post_params.message.clone());
let result = validate_eth_signature(&post_params.signatures, address_str, &signed_message);
if result.is_err() {
let ret = VestingResp {
is_success: false,
error_message: Some("Invalid ethereum signature".to_string()),
page_index: None,
amount_locked: 0,
amount_unlocked: 0,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
use cli::call_process_admin_claim;
let claimant = Pubkey::from_str(&post_params.message).unwrap();
let mut dropped_item = DroppedItem{
address: post_params.pubkey.clone(),
solana_address: post_params.message.clone(),
// page_index: (dropped_data.len() / 200) as u8 + 1,
page_index: 1,
success: false,
signature: None,
// page_index: dropped_data.len() as u8 % 200 + 1,
};
if !exists_data_in_file(path_to_drop_file, dropped_item.address.clone()){
dropped_data.push(dropped_item.clone());
let json_data = serde_json::to_string(&dropped_data).expect("Unable to serialize");
std::fs::write(path_to_drop_file, json_data).expect("Unable to write file");
}
let result = call_process_admin_claim(claimant, amount_unlocked, amount_locked, dropped_item.page_index);
if !result.0{
let ret = VestingResp {
is_success: false,
error_message: Some("Claim/vesting already exists".to_string()),
page_index: None,
amount_locked: amount_locked,
amount_unlocked: amount_unlocked,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
let ret = VestingResp {
is_success: true,
error_message: None,
page_index: Some(1),
amount_locked: amount_locked,
amount_unlocked: amount_unlocked,
};
dropped_item.success = true;
dropped_item.signature = Some(result.1);
update_data_in_file(path_to_drop_file, dropped_item);
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// }
} else if post_params.network == 1 {
let cosmos_public_without_prefix = post_params.cosmos_public_without_prefix.clone().unwrap();
let cosmos_address_with_prefix = post_params.pubkey.clone();
let message = post_params.message.clone();
let signatures = post_params.signatures.clone();
let result = verify::cosmos_verify_keplr_sign(cosmos_address_with_prefix, cosmos_public_without_prefix, signatures, message);
if result {
let mut droped_item = DroppedItem{
address: post_params.pubkey.clone(),
solana_address: post_params.message.clone(),
// page_index: (dropped_data.len() / 200) as u8 + 1,
page_index: 1,
success: false,
signature: None,
};
if !exists_data_in_file(path_to_drop_file, droped_item.address.clone()){
dropped_data.push(droped_item.clone());
let json_data = serde_json::to_string(&dropped_data).expect("Unable to serialize");
std::fs::write(path_to_drop_file, json_data).expect("Unable to write file");
}
use cli::call_process_admin_claim;
let claimant = Pubkey::from_str(&post_params.message).unwrap();
let result = call_process_admin_claim(claimant, amount_unlocked, amount_locked, droped_item.page_index);
if !result.0{
let ret = VestingResp {
is_success: false,
error_message: Some("Claim/vesting already exists".to_string()),
page_index: None,
amount_locked: amount_locked,
amount_unlocked: amount_unlocked,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
let ret = VestingResp {
is_success: true,
error_message: None,
page_index: Some(1),
amount_locked: amount_locked,
amount_unlocked: amount_unlocked,
};
droped_item.success = true;
droped_item.signature = Some(result.1);
update_data_in_file(path_to_drop_file, droped_item);
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
else{
let ret = VestingResp {
is_success: false,
error_message: Some("Invalid cosmos signature".to_string()),
page_index: Some(1),
amount_locked: 0,
amount_unlocked: 0,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
}
else if post_params.network == 2 {
let result = verify::verify_polkadot_signature(post_params.message.as_bytes(), post_params.signatures_bytes.unwrap().as_slice(), &post_params.pubkey);
if result {
let mut dropped_item = DroppedItem{
address: post_params.pubkey.clone(),
solana_address: post_params.message.clone(),
// page_index: (dropped_data.len() / 200) as u8 + 1,
page_index: 1,
success: false,
signature: None,
};
if !exists_data_in_file(path_to_drop_file, dropped_item.address.clone()){
dropped_data.push(dropped_item.clone());
let json_data = serde_json::to_string(&dropped_data).expect("Unable to serialize");
std::fs::write(path_to_drop_file, json_data).expect("Unable to write file");
}
use cli::call_process_admin_claim;
let claimant = Pubkey::from_str(&post_params.message).unwrap();
let result = call_process_admin_claim(claimant, amount_unlocked, amount_locked, dropped_item.page_index);
if !result.0{
let ret = VestingResp {
is_success: false,
error_message: Some("Claim/vesting already exists".to_string()),
page_index: None,
amount_locked: amount_locked,
amount_unlocked: amount_unlocked,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
let ret = VestingResp {
is_success: true,
error_message: None,
page_index: Some(1),
amount_locked: amount_locked,
amount_unlocked: amount_unlocked,
};
dropped_item.success = true;
dropped_item.signature = Some(result.1);
update_data_in_file(path_to_drop_file, dropped_item);
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
else{
let ret = VestingResp {
is_success: false,
error_message: Some("Invalid polkadot signature".to_string()),
page_index: Some(1),
amount_locked: 0,
amount_unlocked: 0,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
}
let ret = VestingResp {
is_success: false,
error_message: Some("Invalid network. 0 for ethereum, 1 for cosmos, 2 for polkadot".to_string()),
page_index: Some(1),
amount_locked: 0,
amount_unlocked: 0,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct DroppedItem{
pub address: String, //cosmos/eth/polkadot address
pub solana_address: String,
pub success: bool,
pub signature: Option<String>,
pub page_index: u8,
}
fn ui_amount_to_token_amount(amount: f64) -> u64 {
(amount * 10u64.checked_pow(9).unwrap() as f64) as u64
}
//post method to store new CmcSymbols
#[utoipa::path(
get,
path = "/vesting/domain/getsubmitsignature",
params(
("cmc_symbol" = CmcSymbolsStoreParams, description = "The Signatures to be stored")
),
responses(
(status = 200, description = "Successfully accept signatures", body = String),
(status = 400, description = "Invalid request parameters")
)
)]
pub async fn get_submit_signature(
query: web::Query<SignatureParams>,
) -> impl Responder {
// let path_to_drop_file = "/data/mantis-indexer/mantis-indexer/dropped.json";
// let file_to_drop_csv = "/data/mantis-indexer/mantis-indexer/ethcosmosclaimprod.csv";
// let post_params = query.into_inner();
// println!("{}", file_to_drop_csv);
// if post_params.network == 0 {
// let address_str: H160 = post_params.pubkey.parse().unwrap();
// let signed_message = get_signed_message(post_params.message.clone());
// let result = validate_eth_signature(&post_params.signatures, address_str, &signed_message);
// if result.is_ok() {
// use cli::call_process_admin_claim;
// let claimant = Pubkey::from_str(&post_params.message).unwrap();
// use jito_merkle_tree::csv_entry::CsvEntry;
// use std::path::PathBuf;
// let distribution_file = &PathBuf::from(file_to_drop_csv);
// println!("distribution_file: {:?}", distribution_file);
// let entity = CsvEntry::new_from_file(&distribution_file).expect("Failed to parse CSV");
// //find the claimant in the csv file
// let claimant_entity = entity.iter().find(|x| x.pubkey == post_params.pubkey);
// if claimant_entity == None {
// let ret = VestingResp {
// is_success: false,
// error_message: Some("Claimant not found".to_string()),
// page_index: Some(1),
// amount_locked: 0,
// amount_unlocked: 0,
// };
// return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// }
// //read data from json file
// let json_data_from_file = std::fs::read_to_string(path_to_drop_file).expect("Unable to read file");
// //deserialize the json data
// let mut dropped_data: Vec<DroppedItem> = serde_json::from_str(&json_data_from_file).expect("Unable to deserialize");
// //find the claimant in the dropped list
// let dropped_entity = dropped_data.iter().find(|x| x.address == post_params.pubkey);
// if dropped_entity.is_some(){
// let ret = VestingResp {
// is_success: false,
// error_message: Some("Claimant already recieved airdrop".to_string()),
// page_index: Some(1),
// amount_locked: 0,
// amount_unlocked: 0,
// };
// return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// }
// dropped_data.push(DroppedItem{
// address: post_params.pubkey.clone(),
// solana_address: post_params.message,
// page_index: (dropped_data.len() / 200) as u8 + 1,
// });
// //store the updated dropped list
// let json_data = serde_json::to_string(&dropped_data).expect("Unable to serialize");
// let amount_unlocked = ui_amount_to_token_amount(claimant_entity.unwrap().amount_unlocked);
// let amount_locked = ui_amount_to_token_amount(claimant_entity.unwrap().amount_locked);
// std::fs::write(path_to_drop_file, json_data).expect("Unable to write file");
// let result = call_process_admin_claim(claimant, amount_unlocked, amount_locked, 1);
// if !result{
// let ret = VestingResp {
// is_success: false,
// error_message: Some("Claim/vesting already exists".to_string()),
// page_index: Some(1),
// amount_locked: amount_locked,
// amount_unlocked: amount_unlocked,
// };
// return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// }
// let ret = VestingResp {
// is_success: true,
// error_message: None,
// page_index: Some(1),
// amount_locked: amount_locked,
// amount_unlocked: amount_unlocked,
// };
// return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// }
// else{
// let ret = VestingResp {
// is_success: false,
// error_message: Some("Invalid ethereum signature".to_string()),
// page_index: Some(1),
// amount_locked: 0,
// amount_unlocked: 0,
// };
// return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// }
// }
// // else if post_params.network == 2 {
// // let result = verify::verify_polkadot_signature(&post_params.message.as_bytes(), &post_params.signatures.as_bytes(), &post_params.pubkey);
// // let result2 = verify::verify_polkadot_signature_ed25519(&post_params.message.as_bytes(), &post_params.signatures.as_bytes(), &post_params.pubkey);
// // if result || result2 {
// // use cli::call_process_admin_claim;
// // let claimant = Pubkey::from_str(&post_params.message).unwrap();
// // let result = call_process_admin_claim(claimant, 1500, 1500, 1);
// // if !result{
// // let ret = VestingResp {
// // is_success: false,
// // error_message: Some("Claim/vesting already exists".to_string()),
// // page_index: Some(1),
// // amount_locked: 1500,
// // amount_unlocked: 1500,
// // };
// // return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// // }
// // let ret = VestingResp {
// // is_success: true,
// // error_message: None,
// // page_index: Some(1),
// // amount_locked: 1500,
// // amount_unlocked: 1500,
// // };
// // return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// // }
// // else{
// // let ret = VestingResp {
// // is_success: false,
// // error_message: Some("Invalid polkadot signature".to_string()),
// // page_index: Some(1),
// // amount_locked: 0,
// // amount_unlocked: 0,
// // };
// // return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// // }
// // } else if post_params.network == 1 {
// // let sig_bytes = hex::decode(post_params.signatures);
// // let pub_bytes = hex::decode(post_params.pubkey);
// // if sig_bytes.is_err() {
// // let ret = VestingResp {
// // is_success: false,
// // error_message: Some("Invalid cosmos signature hex".to_string()),
// // page_index: Some(1),
// // amount_locked: 0,
// // amount_unlocked: 0,
// // };
// // return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// // }
// // if pub_bytes.is_err() {
// // let ret = VestingResp {
// // is_success: false,
// // error_message: Some("Invalid cosmos public key hex".to_string()),
// // page_index: Some(1),
// // amount_locked: 0,
// // amount_unlocked: 0,
// // };
// // return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// // }
// // let result = verify::verify_cosmos_signature(post_params.message.as_bytes(), &sig_bytes.unwrap(), &pub_bytes.unwrap());
// // if result {
// // use cli::call_process_admin_claim;
// // let claimant = Pubkey::from_str(&post_params.message).unwrap();
// // let result = call_process_admin_claim(claimant, 1500, 1500, 1);
// // if !result{
// // let ret = VestingResp {
// // is_success: false,
// // error_message: Some("Claim/vesting already exists".to_string()),
// // page_index: Some(1),
// // amount_locked: 1500,
// // amount_unlocked: 1500,
// // };
// // return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// // }
// // let ret = VestingResp {
// // is_success: true,
// // error_message: None,
// // page_index: Some(1),
// // amount_locked: 1500,
// // amount_unlocked: 1500,
// // };
// // return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// // }
// // else{
// // let ret = VestingResp {
// // is_success: false,
// // error_message: Some("Invalid cosmos signature".to_string()),
// // page_index: Some(1),
// // amount_locked: 0,
// // amount_unlocked: 0,
// // };
// // return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
// // }
// // }
// // } else if post_params.network == 1 {
// // let result = signature::verify(&post_params.signatures.as_bytes(), &post_params.message.as_bytes(), &post_params.pubkey.as_bytes());
// // if result {
// // return HttpResponse::Ok().body("Successfully stored parsed signature");
// // }
// // }
let ret = VestingResp {
is_success: false,
error_message: Some("Invalid network. 0 for ethereum, 1 for cosmos, 2 for polkadot".to_string()),
page_index: Some(1),
amount_locked: 0,
amount_unlocked: 0,
};
return HttpResponse::Ok().body(serde_json::to_string(&ret).unwrap());
}
#[utoipa::path(
get,
path = "/vesting/domain/status",
params(
),
responses(
)
)]
pub async fn status(
) -> impl Responder {
return HttpResponse::Ok().body("Vesting Service are active and ready to accept requests");
}
#[utoipa::path(
get,
path = "/vesting/domain/settestvesting",
params(
),
responses(
)
)]
pub async fn set_test_vesting(
) -> impl Responder {
use cli::call_process_admin_claim;
let claimant = Pubkey::from_str("5pT9ijgv2Qpxn4ux4u4crCCJhgAe4w7GoeaCPJKgP4NW").unwrap();
call_process_admin_claim(claimant, 1500, 1500, 1);
return HttpResponse::Ok().body("Service are active and ready to accept requests");
}
#[actix_web::main(flavor = "multi_thread", thread_count = 4)]
async fn main() -> std::io::Result<()> {
dotenv::dotenv().ok();
let port = std::env::var("PORT").unwrap_or("3125".to_string()).parse().unwrap();
let address = std::env::var("ADDRESS").unwrap_or("0.0.0.0".to_string());
println!("Address: {}", address);
println!("Port: {}", port);
#[derive(OpenApi)]
#[openapi(
paths(
get_submit_signature,
submit_signature,
status,
set_test_vesting
),
components(
schemas(SignatureParams),
),
tags(
(name = "todo", description = "Todo management endpoints.")
)
)]
struct ApiDoc;
use actix_cors::Cors;
let openapi = ApiDoc::openapi();
HttpServer::new(move || {
App::new()
.wrap(
Cors::default()
.allow_any_origin() // Allow requests from any origin
.allow_any_method() // Allow any HTTP method (GET, POST, etc.)
.allow_any_header() // Allow any header
.max_age(3600), // Cache the CORS preflight response for 1 hour
)
.service(web::resource("/vesting/domain/submitsignature").route(web::post().to(submit_signature)))
.service(web::resource("/vesting/domain/status").route(web::get().to(status)))
.service(web::resource("/vesting/domain/settestvesting").route(web::get().to(set_test_vesting)))
.service(web::resource("/vesting/domain/getsubmitsignature").route(web::get().to(get_submit_signature)))
/* Swagger is working only with >= actix 4 https://docs.rs/utoipa-swagger-ui/latest/utoipa_swagger_ui/ */
/* Can't change actix version for now */
// .service(
// SwaggerUi::new("/swagger-ui/{_:.*}").url("/api-docs/openapi.json", openapi.clone()),
// )
})
// .bind(("127.0.0.1", 8080))?
.bind((address, port))?
.run()
.await
}