@@ -16,12 +16,18 @@ use crate::{
16
16
base64,
17
17
config:: get_env_var_or_default,
18
18
error:: LDNError ,
19
- external_services:: { filecoin:: get_multisig_threshold_for_actor, github:: {
20
- github_async_new, CreateMergeRequestData , CreateRefillMergeRequestData , GithubWrapper ,
21
- } } ,
19
+ external_services:: {
20
+ filecoin:: get_multisig_threshold_for_actor,
21
+ github:: {
22
+ github_async_new, CreateMergeRequestData , CreateRefillMergeRequestData , GithubWrapper ,
23
+ } ,
24
+ } ,
22
25
parsers:: ParsedIssue ,
23
26
} ;
24
- use fplus_database:: database:: { self , allocators:: { get_allocator, update_allocator_threshold} } ;
27
+ use fplus_database:: database:: {
28
+ self ,
29
+ allocators:: { get_allocator, update_allocator_threshold} ,
30
+ } ;
25
31
use fplus_database:: models:: applications:: Model as ApplicationModel ;
26
32
27
33
use self :: application:: file:: {
@@ -155,8 +161,11 @@ pub struct ApplicationGithubInfo {
155
161
}
156
162
157
163
impl LDNApplication {
158
-
159
- pub async fn single_active ( pr_number : u64 , owner : String , repo : String ) -> Result < ApplicationFile , LDNError > {
164
+ pub async fn single_active (
165
+ pr_number : u64 ,
166
+ owner : String ,
167
+ repo : String ,
168
+ ) -> Result < ApplicationFile , LDNError > {
160
169
let gh = github_async_new ( owner, repo) . await ;
161
170
let ( _, pull_request) = gh. get_pull_request_files ( pr_number) . await . unwrap ( ) ;
162
171
let pull_request = pull_request. get ( 0 ) . unwrap ( ) ;
@@ -261,8 +270,11 @@ impl LDNApplication {
261
270
Ok ( app)
262
271
}
263
272
264
- pub async fn load ( application_id : String , owner : String , repo : String ) -> Result < Self , LDNError > {
265
-
273
+ pub async fn load (
274
+ application_id : String ,
275
+ owner : String ,
276
+ repo : String ,
277
+ ) -> Result < Self , LDNError > {
266
278
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
267
279
let pull_requests = gh. list_pull_requests ( ) . await . unwrap ( ) ;
268
280
let pull_requests = future:: try_join_all (
@@ -370,7 +382,11 @@ impl LDNApplication {
370
382
Ok ( apps)
371
383
}
372
384
373
- pub async fn active_apps_with_last_update ( owner : String , repo : String , filter : Option < String > ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
385
+ pub async fn active_apps_with_last_update (
386
+ owner : String ,
387
+ repo : String ,
388
+ filter : Option < String > ,
389
+ ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
374
390
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
375
391
let mut apps: Vec < ApplicationFileWithDate > = Vec :: new ( ) ;
376
392
let pull_requests = gh. list_pull_requests ( ) . await . unwrap ( ) ;
@@ -404,9 +420,13 @@ impl LDNApplication {
404
420
Ok ( apps)
405
421
}
406
422
407
- pub async fn merged_apps_with_last_update ( owner : String , repo : String , filter : Option < String > ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
423
+ pub async fn merged_apps_with_last_update (
424
+ owner : String ,
425
+ repo : String ,
426
+ filter : Option < String > ,
427
+ ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
408
428
let gh = Arc :: new ( github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ) ;
409
-
429
+
410
430
let applications_path = "applications" ;
411
431
let mut all_files_result = gh. get_files ( applications_path) . await . map_err ( |e| {
412
432
LDNError :: Load ( format ! (
@@ -673,7 +693,7 @@ impl LDNApplication {
673
693
}
674
694
} ;
675
695
let db_threshold: u64 = db_allocator. unwrap ( ) . multisig_threshold . unwrap_or ( 2 ) as u64 ;
676
-
696
+
677
697
// If blockchain threshold is available and different from DB, update DB (placeholder for update logic)
678
698
if let Some ( blockchain_threshold) = blockchain_threshold {
679
699
if blockchain_threshold != db_threshold {
@@ -958,7 +978,8 @@ impl LDNApplication {
958
978
if app. is_some ( ) && app. unwrap ( ) . 1 . lifecycle . get_state ( ) == AppState :: Granted {
959
979
let app = app. unwrap ( ) . 1 . reached_total_datacap ( ) ;
960
980
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
961
- let ldn_app = LDNApplication :: load ( application_id. clone ( ) , owner. clone ( ) , repo. clone ( ) ) . await ?;
981
+ let ldn_app =
982
+ LDNApplication :: load ( application_id. clone ( ) , owner. clone ( ) , repo. clone ( ) ) . await ?;
962
983
let ContentItems { items } = gh. get_file ( & ldn_app. file_name , "main" ) . await . unwrap ( ) ;
963
984
Self :: issue_full_dc ( app. issue_number . clone ( ) , owner. clone ( ) , repo. clone ( ) ) . await ?;
964
985
Self :: update_issue_labels (
@@ -1228,7 +1249,11 @@ impl LDNApplication {
1228
1249
return Ok ( false ) ;
1229
1250
}
1230
1251
1231
- pub async fn merge_application ( pr_number : u64 , owner : String , repo : String ) -> Result < bool , LDNError > {
1252
+ pub async fn merge_application (
1253
+ pr_number : u64 ,
1254
+ owner : String ,
1255
+ repo : String ,
1256
+ ) -> Result < bool , LDNError > {
1232
1257
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
1233
1258
1234
1259
gh. merge_pull_request ( pr_number) . await . map_err ( |e| {
@@ -1421,13 +1446,19 @@ impl LDNApplication {
1421
1446
log:: warn!( "Val Trigger (RtS) - Active allocation has signers" ) ;
1422
1447
false
1423
1448
} else if validated_at. is_empty ( ) {
1424
- log:: warn!( "Val Trigger (RtS) - Not ready to sign - validated_at is empty" ) ;
1449
+ log:: warn!(
1450
+ "Val Trigger (RtS) - Not ready to sign - validated_at is empty"
1451
+ ) ;
1425
1452
false
1426
1453
} else if validated_by. is_empty ( ) {
1427
- log:: warn!( "Val Trigger (RtS) - Not ready to sign - validated_by is empty" ) ;
1454
+ log:: warn!(
1455
+ "Val Trigger (RtS) - Not ready to sign - validated_by is empty"
1456
+ ) ;
1428
1457
false
1429
1458
} else if actor != bot_user {
1430
- log:: warn!( "Val Trigger (RtS) - Not ready to sign - actor is not the bot user" ) ;
1459
+ log:: warn!(
1460
+ "Val Trigger (RtS) - Not ready to sign - actor is not the bot user"
1461
+ ) ;
1431
1462
false
1432
1463
} else if !valid_verifier_list. is_valid ( & validated_by) {
1433
1464
log:: warn!( "Val Trigger (RtS) - Not ready to sign - valid_verifier_list is not valid" ) ;
@@ -1536,7 +1567,10 @@ impl LDNApplication {
1536
1567
{
1537
1568
Some ( ( ) ) => {
1538
1569
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
1539
- match gh. get_pull_request_by_head ( & ldn_application. branch_name ) . await {
1570
+ match gh
1571
+ . get_pull_request_by_head ( & ldn_application. branch_name )
1572
+ . await
1573
+ {
1540
1574
Ok ( prs) => {
1541
1575
if let Some ( pr) = prs. get ( 0 ) {
1542
1576
let number = pr. number ;
@@ -1605,10 +1639,30 @@ impl LDNApplication {
1605
1639
}
1606
1640
} ;
1607
1641
let signers: application:: file:: Verifiers = active_request. signers . clone ( ) ;
1608
- if signers. 0 . len ( ) != 2 {
1609
- log:: warn!( "Val Approval (G) - Not enough signers" ) ;
1642
+
1643
+ // Try getting the multisig threshold from the blockchain
1644
+ let blockchain_threshold =
1645
+ get_multisig_threshold_for_actor ( "actor_address" ) . await ;
1646
+
1647
+ // Fallback to database value if blockchain query fails
1648
+ let multisig_threshold = match blockchain_threshold {
1649
+ Ok ( threshold) => threshold as usize ,
1650
+ Err ( _) => {
1651
+ let db_allocator = get_allocator ( & owner, & repo) . await
1652
+ . map_err ( |e| LDNError :: Load ( format ! ( "Database error: {}" , e) ) ) ?;
1653
+ db_allocator
1654
+ . as_ref ( )
1655
+ . and_then ( |allocator| allocator. multisig_threshold )
1656
+ . unwrap_or ( 2 ) as usize
1657
+ }
1658
+ } ;
1659
+
1660
+ // Check if the number of signers meets or exceeds the multisig threshold
1661
+ if signers. 0 . len ( ) < multisig_threshold {
1662
+ log:: warn!( "Not enough signers for approval" ) ;
1610
1663
return Ok ( false ) ;
1611
1664
}
1665
+
1612
1666
let signer = signers. 0 . get ( 1 ) . unwrap ( ) ;
1613
1667
let signer_gh_handle = signer. github_username . clone ( ) ;
1614
1668
let valid_verifiers =
@@ -1725,7 +1779,11 @@ impl LDNApplication {
1725
1779
}
1726
1780
}
1727
1781
1728
- async fn issue_waiting_for_gov_review ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
1782
+ async fn issue_waiting_for_gov_review (
1783
+ issue_number : String ,
1784
+ owner : String ,
1785
+ repo : String ,
1786
+ ) -> Result < bool , LDNError > {
1729
1787
let gh = github_async_new ( owner, repo) . await ;
1730
1788
gh. add_comment_to_issue (
1731
1789
issue_number. parse ( ) . unwrap ( ) ,
@@ -1742,7 +1800,11 @@ impl LDNApplication {
1742
1800
Ok ( true )
1743
1801
}
1744
1802
1745
- async fn issue_datacap_request_trigger ( application_file : ApplicationFile , owner : String , repo : String ) -> Result < bool , LDNError > {
1803
+ async fn issue_datacap_request_trigger (
1804
+ application_file : ApplicationFile ,
1805
+ owner : String ,
1806
+ repo : String ,
1807
+ ) -> Result < bool , LDNError > {
1746
1808
let gh = github_async_new ( owner, repo) . await ;
1747
1809
1748
1810
let client_address = application_file. lifecycle . client_on_chain_address . clone ( ) ;
@@ -1922,7 +1984,11 @@ Your Datacap Allocation Request has been {} by the Notary
1922
1984
Ok ( true )
1923
1985
}
1924
1986
1925
- async fn issue_start_sign_dc ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
1987
+ async fn issue_start_sign_dc (
1988
+ issue_number : String ,
1989
+ owner : String ,
1990
+ repo : String ,
1991
+ ) -> Result < bool , LDNError > {
1926
1992
let gh = github_async_new ( owner, repo) . await ;
1927
1993
gh. add_comment_to_issue (
1928
1994
issue_number. parse ( ) . unwrap ( ) ,
@@ -1938,7 +2004,11 @@ Your Datacap Allocation Request has been {} by the Notary
1938
2004
. unwrap ( ) ;
1939
2005
Ok ( true )
1940
2006
}
1941
- async fn issue_granted ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
2007
+ async fn issue_granted (
2008
+ issue_number : String ,
2009
+ owner : String ,
2010
+ repo : String ,
2011
+ ) -> Result < bool , LDNError > {
1942
2012
let gh = github_async_new ( owner, repo) . await ;
1943
2013
gh. add_comment_to_issue ( issue_number. parse ( ) . unwrap ( ) , "Application is Granted" )
1944
2014
. await
@@ -1951,7 +2021,11 @@ Your Datacap Allocation Request has been {} by the Notary
1951
2021
. unwrap ( ) ;
1952
2022
Ok ( true )
1953
2023
}
1954
- async fn issue_refill ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
2024
+ async fn issue_refill (
2025
+ issue_number : String ,
2026
+ owner : String ,
2027
+ repo : String ,
2028
+ ) -> Result < bool , LDNError > {
1955
2029
let gh = github_async_new ( owner, repo) . await ;
1956
2030
gh. add_comment_to_issue ( issue_number. parse ( ) . unwrap ( ) , "Application is in Refill" )
1957
2031
. await
@@ -1973,7 +2047,11 @@ Your Datacap Allocation Request has been {} by the Notary
1973
2047
. unwrap ( ) ;
1974
2048
Ok ( true )
1975
2049
}
1976
- async fn issue_full_dc ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
2050
+ async fn issue_full_dc (
2051
+ issue_number : String ,
2052
+ owner : String ,
2053
+ repo : String ,
2054
+ ) -> Result < bool , LDNError > {
1977
2055
let gh = github_async_new ( owner, repo) . await ;
1978
2056
gh. add_comment_to_issue ( issue_number. parse ( ) . unwrap ( ) , "Application is Completed" )
1979
2057
. await
@@ -1987,7 +2065,12 @@ Your Datacap Allocation Request has been {} by the Notary
1987
2065
Ok ( true )
1988
2066
}
1989
2067
1990
- async fn add_error_label ( issue_number : String , comment : String , owner : String , repo : String ) -> Result < ( ) , LDNError > {
2068
+ async fn add_error_label (
2069
+ issue_number : String ,
2070
+ comment : String ,
2071
+ owner : String ,
2072
+ repo : String ,
2073
+ ) -> Result < ( ) , LDNError > {
1991
2074
let gh = github_async_new ( owner, repo) . await ;
1992
2075
let num: u64 = issue_number. parse ( ) . expect ( "Not a valid integer" ) ;
1993
2076
gh. add_error_label ( num, comment)
@@ -2003,8 +2086,13 @@ Your Datacap Allocation Request has been {} by the Notary
2003
2086
Ok ( ( ) )
2004
2087
}
2005
2088
2006
- async fn update_issue_labels ( issue_number : String , new_labels : & [ & str ] , owner : String , repo : String ) -> Result < ( ) , LDNError > {
2007
- let gh = github_async_new ( owner, repo) . await ;
2089
+ async fn update_issue_labels (
2090
+ issue_number : String ,
2091
+ new_labels : & [ & str ] ,
2092
+ owner : String ,
2093
+ repo : String ,
2094
+ ) -> Result < ( ) , LDNError > {
2095
+ let gh = github_async_new ( owner, repo) . await ;
2008
2096
let num: u64 = issue_number. parse ( ) . expect ( "Not a valid integer" ) ;
2009
2097
gh. update_issue_labels ( num, new_labels)
2010
2098
. await
@@ -2440,8 +2528,8 @@ pub fn get_file_sha(content: &ContentItems) -> Option<String> {
2440
2528
// }
2441
2529
2442
2530
// let ldn_application_after_trigger = match LDNApplication::load(
2443
- // application_id.clone(),
2444
- // OWNER.to_string(),
2531
+ // application_id.clone(),
2532
+ // OWNER.to_string(),
2445
2533
// REPO.to_string()
2446
2534
// ).await
2447
2535
// {
0 commit comments