@@ -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:: {
@@ -162,8 +168,11 @@ pub struct ApplicationGithubInfo {
162
168
}
163
169
164
170
impl LDNApplication {
165
-
166
- pub async fn single_active ( pr_number : u64 , owner : String , repo : String ) -> Result < ApplicationFile , LDNError > {
171
+ pub async fn single_active (
172
+ pr_number : u64 ,
173
+ owner : String ,
174
+ repo : String ,
175
+ ) -> Result < ApplicationFile , LDNError > {
167
176
let gh = github_async_new ( owner, repo) . await ;
168
177
let ( _, pull_request) = gh. get_pull_request_files ( pr_number) . await . unwrap ( ) ;
169
178
let pull_request = pull_request. get ( 0 ) . unwrap ( ) ;
@@ -268,8 +277,11 @@ impl LDNApplication {
268
277
Ok ( app)
269
278
}
270
279
271
- pub async fn load ( application_id : String , owner : String , repo : String ) -> Result < Self , LDNError > {
272
-
280
+ pub async fn load (
281
+ application_id : String ,
282
+ owner : String ,
283
+ repo : String ,
284
+ ) -> Result < Self , LDNError > {
273
285
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
274
286
let pull_requests = gh. list_pull_requests ( ) . await . unwrap ( ) ;
275
287
let pull_requests = future:: try_join_all (
@@ -377,7 +389,11 @@ impl LDNApplication {
377
389
Ok ( apps)
378
390
}
379
391
380
- pub async fn active_apps_with_last_update ( owner : String , repo : String , filter : Option < String > ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
392
+ pub async fn active_apps_with_last_update (
393
+ owner : String ,
394
+ repo : String ,
395
+ filter : Option < String > ,
396
+ ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
381
397
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
382
398
let mut apps: Vec < ApplicationFileWithDate > = Vec :: new ( ) ;
383
399
let pull_requests = gh. list_pull_requests ( ) . await . unwrap ( ) ;
@@ -411,9 +427,13 @@ impl LDNApplication {
411
427
Ok ( apps)
412
428
}
413
429
414
- pub async fn merged_apps_with_last_update ( owner : String , repo : String , filter : Option < String > ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
430
+ pub async fn merged_apps_with_last_update (
431
+ owner : String ,
432
+ repo : String ,
433
+ filter : Option < String > ,
434
+ ) -> Result < Vec < ApplicationFileWithDate > , LDNError > {
415
435
let gh = Arc :: new ( github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ) ;
416
-
436
+
417
437
let applications_path = "applications" ;
418
438
let mut all_files_result = gh. get_files ( applications_path) . await . map_err ( |e| {
419
439
LDNError :: Load ( format ! (
@@ -680,7 +700,7 @@ impl LDNApplication {
680
700
}
681
701
} ;
682
702
let db_threshold: u64 = db_allocator. unwrap ( ) . multisig_threshold . unwrap_or ( 2 ) as u64 ;
683
-
703
+
684
704
// If blockchain threshold is available and different from DB, update DB (placeholder for update logic)
685
705
if let Some ( blockchain_threshold) = blockchain_threshold {
686
706
if blockchain_threshold != db_threshold {
@@ -965,7 +985,8 @@ impl LDNApplication {
965
985
if app. is_some ( ) && app. unwrap ( ) . 1 . lifecycle . get_state ( ) == AppState :: Granted {
966
986
let app = app. unwrap ( ) . 1 . reached_total_datacap ( ) ;
967
987
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
968
- let ldn_app = LDNApplication :: load ( application_id. clone ( ) , owner. clone ( ) , repo. clone ( ) ) . await ?;
988
+ let ldn_app =
989
+ LDNApplication :: load ( application_id. clone ( ) , owner. clone ( ) , repo. clone ( ) ) . await ?;
969
990
let ContentItems { items } = gh. get_file ( & ldn_app. file_name , "main" ) . await . unwrap ( ) ;
970
991
Self :: issue_full_dc ( app. issue_number . clone ( ) , owner. clone ( ) , repo. clone ( ) ) . await ?;
971
992
Self :: update_issue_labels (
@@ -1235,7 +1256,11 @@ impl LDNApplication {
1235
1256
return Ok ( false ) ;
1236
1257
}
1237
1258
1238
- pub async fn merge_application ( pr_number : u64 , owner : String , repo : String ) -> Result < bool , LDNError > {
1259
+ pub async fn merge_application (
1260
+ pr_number : u64 ,
1261
+ owner : String ,
1262
+ repo : String ,
1263
+ ) -> Result < bool , LDNError > {
1239
1264
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
1240
1265
1241
1266
gh. merge_pull_request ( pr_number) . await . map_err ( |e| {
@@ -1428,13 +1453,19 @@ impl LDNApplication {
1428
1453
log:: warn!( "Val Trigger (RtS) - Active allocation has signers" ) ;
1429
1454
false
1430
1455
} else if validated_at. is_empty ( ) {
1431
- log:: warn!( "Val Trigger (RtS) - Not ready to sign - validated_at is empty" ) ;
1456
+ log:: warn!(
1457
+ "Val Trigger (RtS) - Not ready to sign - validated_at is empty"
1458
+ ) ;
1432
1459
false
1433
1460
} else if validated_by. is_empty ( ) {
1434
- log:: warn!( "Val Trigger (RtS) - Not ready to sign - validated_by is empty" ) ;
1461
+ log:: warn!(
1462
+ "Val Trigger (RtS) - Not ready to sign - validated_by is empty"
1463
+ ) ;
1435
1464
false
1436
1465
} else if actor != bot_user {
1437
- log:: warn!( "Val Trigger (RtS) - Not ready to sign - actor is not the bot user" ) ;
1466
+ log:: warn!(
1467
+ "Val Trigger (RtS) - Not ready to sign - actor is not the bot user"
1468
+ ) ;
1438
1469
false
1439
1470
} else if !valid_verifier_list. is_valid ( & validated_by) {
1440
1471
log:: warn!( "Val Trigger (RtS) - Not ready to sign - valid_verifier_list is not valid" ) ;
@@ -1543,7 +1574,10 @@ impl LDNApplication {
1543
1574
{
1544
1575
Some ( ( ) ) => {
1545
1576
let gh = github_async_new ( owner. to_string ( ) , repo. to_string ( ) ) . await ;
1546
- match gh. get_pull_request_by_head ( & ldn_application. branch_name ) . await {
1577
+ match gh
1578
+ . get_pull_request_by_head ( & ldn_application. branch_name )
1579
+ . await
1580
+ {
1547
1581
Ok ( prs) => {
1548
1582
if let Some ( pr) = prs. get ( 0 ) {
1549
1583
let number = pr. number ;
@@ -1612,10 +1646,30 @@ impl LDNApplication {
1612
1646
}
1613
1647
} ;
1614
1648
let signers: application:: file:: Verifiers = active_request. signers . clone ( ) ;
1615
- if signers. 0 . len ( ) != 2 {
1616
- log:: warn!( "Val Approval (G) - Not enough signers" ) ;
1649
+
1650
+ // Try getting the multisig threshold from the blockchain
1651
+ let blockchain_threshold =
1652
+ get_multisig_threshold_for_actor ( "actor_address" ) . await ;
1653
+
1654
+ // Fallback to database value if blockchain query fails
1655
+ let multisig_threshold = match blockchain_threshold {
1656
+ Ok ( threshold) => threshold as usize ,
1657
+ Err ( _) => {
1658
+ let db_allocator = get_allocator ( & owner, & repo) . await
1659
+ . map_err ( |e| LDNError :: Load ( format ! ( "Database error: {}" , e) ) ) ?;
1660
+ db_allocator
1661
+ . as_ref ( )
1662
+ . and_then ( |allocator| allocator. multisig_threshold )
1663
+ . unwrap_or ( 2 ) as usize
1664
+ }
1665
+ } ;
1666
+
1667
+ // Check if the number of signers meets or exceeds the multisig threshold
1668
+ if signers. 0 . len ( ) < multisig_threshold {
1669
+ log:: warn!( "Not enough signers for approval" ) ;
1617
1670
return Ok ( false ) ;
1618
1671
}
1672
+
1619
1673
let signer = signers. 0 . get ( 1 ) . unwrap ( ) ;
1620
1674
let signer_gh_handle = signer. github_username . clone ( ) ;
1621
1675
let valid_verifiers =
@@ -1732,7 +1786,11 @@ impl LDNApplication {
1732
1786
}
1733
1787
}
1734
1788
1735
- async fn issue_waiting_for_gov_review ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
1789
+ async fn issue_waiting_for_gov_review (
1790
+ issue_number : String ,
1791
+ owner : String ,
1792
+ repo : String ,
1793
+ ) -> Result < bool , LDNError > {
1736
1794
let gh = github_async_new ( owner, repo) . await ;
1737
1795
gh. add_comment_to_issue (
1738
1796
issue_number. parse ( ) . unwrap ( ) ,
@@ -1749,7 +1807,11 @@ impl LDNApplication {
1749
1807
Ok ( true )
1750
1808
}
1751
1809
1752
- async fn issue_datacap_request_trigger ( application_file : ApplicationFile , owner : String , repo : String ) -> Result < bool , LDNError > {
1810
+ async fn issue_datacap_request_trigger (
1811
+ application_file : ApplicationFile ,
1812
+ owner : String ,
1813
+ repo : String ,
1814
+ ) -> Result < bool , LDNError > {
1753
1815
let gh = github_async_new ( owner, repo) . await ;
1754
1816
1755
1817
let client_address = application_file. lifecycle . client_on_chain_address . clone ( ) ;
@@ -1929,7 +1991,11 @@ Your Datacap Allocation Request has been {} by the Notary
1929
1991
Ok ( true )
1930
1992
}
1931
1993
1932
- async fn issue_start_sign_dc ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
1994
+ async fn issue_start_sign_dc (
1995
+ issue_number : String ,
1996
+ owner : String ,
1997
+ repo : String ,
1998
+ ) -> Result < bool , LDNError > {
1933
1999
let gh = github_async_new ( owner, repo) . await ;
1934
2000
gh. add_comment_to_issue (
1935
2001
issue_number. parse ( ) . unwrap ( ) ,
@@ -1945,7 +2011,11 @@ Your Datacap Allocation Request has been {} by the Notary
1945
2011
. unwrap ( ) ;
1946
2012
Ok ( true )
1947
2013
}
1948
- async fn issue_granted ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
2014
+ async fn issue_granted (
2015
+ issue_number : String ,
2016
+ owner : String ,
2017
+ repo : String ,
2018
+ ) -> Result < bool , LDNError > {
1949
2019
let gh = github_async_new ( owner, repo) . await ;
1950
2020
gh. add_comment_to_issue ( issue_number. parse ( ) . unwrap ( ) , "Application is Granted" )
1951
2021
. await
@@ -1958,7 +2028,11 @@ Your Datacap Allocation Request has been {} by the Notary
1958
2028
. unwrap ( ) ;
1959
2029
Ok ( true )
1960
2030
}
1961
- async fn issue_refill ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
2031
+ async fn issue_refill (
2032
+ issue_number : String ,
2033
+ owner : String ,
2034
+ repo : String ,
2035
+ ) -> Result < bool , LDNError > {
1962
2036
let gh = github_async_new ( owner, repo) . await ;
1963
2037
gh. add_comment_to_issue ( issue_number. parse ( ) . unwrap ( ) , "Application is in Refill" )
1964
2038
. await
@@ -1980,7 +2054,11 @@ Your Datacap Allocation Request has been {} by the Notary
1980
2054
. unwrap ( ) ;
1981
2055
Ok ( true )
1982
2056
}
1983
- async fn issue_full_dc ( issue_number : String , owner : String , repo : String ) -> Result < bool , LDNError > {
2057
+ async fn issue_full_dc (
2058
+ issue_number : String ,
2059
+ owner : String ,
2060
+ repo : String ,
2061
+ ) -> Result < bool , LDNError > {
1984
2062
let gh = github_async_new ( owner, repo) . await ;
1985
2063
gh. add_comment_to_issue ( issue_number. parse ( ) . unwrap ( ) , "Application is Completed" )
1986
2064
. await
@@ -1994,7 +2072,12 @@ Your Datacap Allocation Request has been {} by the Notary
1994
2072
Ok ( true )
1995
2073
}
1996
2074
1997
- async fn add_error_label ( issue_number : String , comment : String , owner : String , repo : String ) -> Result < ( ) , LDNError > {
2075
+ async fn add_error_label (
2076
+ issue_number : String ,
2077
+ comment : String ,
2078
+ owner : String ,
2079
+ repo : String ,
2080
+ ) -> Result < ( ) , LDNError > {
1998
2081
let gh = github_async_new ( owner, repo) . await ;
1999
2082
let num: u64 = issue_number. parse ( ) . expect ( "Not a valid integer" ) ;
2000
2083
gh. add_error_label ( num, comment)
@@ -2010,8 +2093,13 @@ Your Datacap Allocation Request has been {} by the Notary
2010
2093
Ok ( ( ) )
2011
2094
}
2012
2095
2013
- async fn update_issue_labels ( issue_number : String , new_labels : & [ & str ] , owner : String , repo : String ) -> Result < ( ) , LDNError > {
2014
- let gh = github_async_new ( owner, repo) . await ;
2096
+ async fn update_issue_labels (
2097
+ issue_number : String ,
2098
+ new_labels : & [ & str ] ,
2099
+ owner : String ,
2100
+ repo : String ,
2101
+ ) -> Result < ( ) , LDNError > {
2102
+ let gh = github_async_new ( owner, repo) . await ;
2015
2103
let num: u64 = issue_number. parse ( ) . expect ( "Not a valid integer" ) ;
2016
2104
gh. update_issue_labels ( num, new_labels)
2017
2105
. await
@@ -2447,8 +2535,8 @@ pub fn get_file_sha(content: &ContentItems) -> Option<String> {
2447
2535
// }
2448
2536
2449
2537
// let ldn_application_after_trigger = match LDNApplication::load(
2450
- // application_id.clone(),
2451
- // OWNER.to_string(),
2538
+ // application_id.clone(),
2539
+ // OWNER.to_string(),
2452
2540
// REPO.to_string()
2453
2541
// ).await
2454
2542
// {
0 commit comments