@@ -4,6 +4,7 @@ use crate::model::wallet::WalletSeedHash;
44use crate :: ui:: tokens:: tokens_screen:: { IdentityTokenBalance , IdentityTokenIdentifier } ;
55use bincode:: config;
66use dash_sdk:: dpp:: data_contract:: TokenConfiguration ;
7+ use dash_sdk:: dpp:: data_contract:: accessors:: v0:: DataContractV0Getters ;
78use dash_sdk:: platform:: { DataContract , Identifier } ;
89use dash_sdk:: query_types:: IndexMap ;
910use rusqlite:: Result ;
@@ -20,52 +21,44 @@ impl AppContext {
2021 // Get contracts from the database
2122 let mut contracts = self . db . get_contracts ( self , limit, offset) ?;
2223
23- // Add the DPNS contract to the list
24- let dpns_contract = QualifiedContract {
25- contract : Arc :: clone ( & self . dpns_contract ) . as_ref ( ) . clone ( ) ,
26- alias : Some ( "dpns" . to_string ( ) ) ,
27- } ;
28-
29- // Insert the DPNS contract at 0
30- contracts. insert ( 0 , dpns_contract) ;
31-
32- // Add the token history contract to the list
33- let token_history_contract = QualifiedContract {
34- contract : Arc :: clone ( & self . token_history_contract ) . as_ref ( ) . clone ( ) ,
35- alias : Some ( "token_history" . to_string ( ) ) ,
36- } ;
37-
38- // Insert the token history contract at 1
39- contracts. insert ( 1 , token_history_contract) ;
40-
41- // Add the withdrawal contract to the list
42- let withdraws_contract = QualifiedContract {
43- contract : Arc :: clone ( & self . withdraws_contract ) . as_ref ( ) . clone ( ) ,
44- alias : Some ( "withdrawals" . to_string ( ) ) ,
45- } ;
46-
47- // Insert the withdrawal contract at 2
48- contracts. insert ( 2 , withdraws_contract) ;
49-
50- // Add the keyword search contract to the list
51- let keyword_search_contract = QualifiedContract {
52- contract : Arc :: clone ( & self . keyword_search_contract ) . as_ref ( ) . clone ( ) ,
53- alias : Some ( "keyword_search" . to_string ( ) ) ,
54- } ;
55-
56- // Insert the keyword search contract at 3
57- contracts. insert ( 3 , keyword_search_contract) ;
58-
59- // Add the DashPay contract to the list
60- let dashpay_contract = QualifiedContract {
61- contract : Arc :: clone ( & self . dashpay_contract ) . as_ref ( ) . clone ( ) ,
62- alias : Some ( "dashpay" . to_string ( ) ) ,
63- } ;
64-
65- // Insert the DashPay contract at 4
66- contracts. insert ( 4 , dashpay_contract) ;
67-
68- Ok ( contracts)
24+ // Build the list of system contracts to prepend
25+ let system_contracts = vec ! [
26+ QualifiedContract {
27+ contract: Arc :: clone( & self . dpns_contract) . as_ref( ) . clone( ) ,
28+ alias: Some ( "dpns" . to_string( ) ) ,
29+ } ,
30+ QualifiedContract {
31+ contract: Arc :: clone( & self . token_history_contract) . as_ref( ) . clone( ) ,
32+ alias: Some ( "token_history" . to_string( ) ) ,
33+ } ,
34+ QualifiedContract {
35+ contract: Arc :: clone( & self . withdraws_contract) . as_ref( ) . clone( ) ,
36+ alias: Some ( "withdrawals" . to_string( ) ) ,
37+ } ,
38+ QualifiedContract {
39+ contract: Arc :: clone( & self . keyword_search_contract) . as_ref( ) . clone( ) ,
40+ alias: Some ( "keyword_search" . to_string( ) ) ,
41+ } ,
42+ QualifiedContract {
43+ contract: Arc :: clone( & self . dashpay_contract) . as_ref( ) . clone( ) ,
44+ alias: Some ( "dashpay" . to_string( ) ) ,
45+ } ,
46+ ] ;
47+
48+ // Collect system contract IDs to deduplicate DB contracts that match
49+ let system_ids: std:: collections:: HashSet < _ > = system_contracts
50+ . iter ( )
51+ . map ( |c| c. contract . id ( ) )
52+ . collect ( ) ;
53+
54+ // Remove any DB contracts that duplicate a system contract
55+ contracts. retain ( |c| !system_ids. contains ( & c. contract . id ( ) ) ) ;
56+
57+ // Prepend system contracts in order
58+ let mut result = system_contracts;
59+ result. append ( & mut contracts) ;
60+
61+ Ok ( result)
6962 }
7063
7164 pub fn get_contract_by_id (
0 commit comments