@@ -2,8 +2,8 @@ use crate::error::ContractError;
2
2
use crate :: msg:: { ExecuteMsg , InfusionsResponse , InstantiateMsg , MigrateMsg , QueryMsg } ;
3
3
use crate :: state:: {
4
4
Bundle , Config , InfusedCollection , Infusion , InfusionParamState , InfusionState , NFTCollection ,
5
- TokenPositionMapping , CONFIG , INFUSION , INFUSION_ID , INFUSION_INFO , MINTABLE_NUM_TOKENS ,
6
- MINTABLE_TOKEN_POSITIONS , NFT ,
5
+ TokenPositionMapping , UpdatingConfig , CONFIG , INFUSION , INFUSION_ID , INFUSION_INFO ,
6
+ MINTABLE_NUM_TOKENS , MINTABLE_TOKEN_POSITIONS , NFT ,
7
7
} ;
8
8
use cosmwasm_schema:: serde:: Serialize ;
9
9
#[ cfg( not( feature = "library" ) ) ]
@@ -120,8 +120,12 @@ pub fn execute(
120
120
infusion_id,
121
121
bundle,
122
122
} => execute_infuse_bundle ( deps, env, info, infusion_id, bundle) ,
123
- ExecuteMsg :: UpdateConfig { } => update_config ( deps, info) ,
123
+ ExecuteMsg :: UpdateConfig { config } => update_config ( deps, info, config ) ,
124
124
ExecuteMsg :: EndInfusion { id } => execute_end_infusion ( deps, info, id) ,
125
+ ExecuteMsg :: UpdateInfusionBaseUri {
126
+ infusion_id,
127
+ base_uri,
128
+ } => update_infused_base_uri ( deps, info, infusion_id, base_uri) ,
125
129
}
126
130
}
127
131
@@ -147,15 +151,20 @@ pub fn reply(_deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, Contract
147
151
}
148
152
}
149
153
150
- /// Update the configuration of the app
151
- fn update_config ( deps : DepsMut , msg : MessageInfo ) -> Result < Response , ContractError > {
152
- let config = CONFIG . load ( deps. storage ) ?;
153
- // Only the admin should be able to call this
154
- if config. contract_owner != msg. sender {
154
+ /// Update the baseuri used for infused collection metadata
155
+ fn update_infused_base_uri (
156
+ deps : DepsMut ,
157
+ msg : MessageInfo ,
158
+ id : u64 ,
159
+ base_uri : String ,
160
+ ) -> Result < Response , ContractError > {
161
+ let key = INFUSION_ID . load ( deps. storage , id) ?;
162
+ let mut infusion = INFUSION . load ( deps. storage , key. clone ( ) ) ?;
163
+ if infusion. owner != msg. sender {
155
164
return Err ( ContractError :: Admin ( AdminError :: NotAdmin { } ) ) ;
156
165
}
157
-
158
- // todo: update configs
166
+ infusion . infused_collection . base_uri = base_uri ;
167
+ INFUSION . save ( deps . storage , key , & infusion ) ? ;
159
168
160
169
Ok ( Response :: new ( ) )
161
170
}
@@ -279,6 +288,7 @@ pub fn execute_create_infusion(
279
288
max : cfg. max_per_bundle ,
280
289
} ) ;
281
290
}
291
+
282
292
unique. push ( col. addr . clone ( ) ) ;
283
293
}
284
294
}
@@ -475,7 +485,7 @@ fn execute_infuse_bundle(
475
485
}
476
486
}
477
487
478
- // check lens
488
+ // // check lens
479
489
if bundle. is_empty ( ) {
480
490
return Err ( ContractError :: EmptyBundle ) ;
481
491
}
@@ -565,49 +575,51 @@ fn check_bundles(
565
575
elig_col : Vec < NFTCollection > ,
566
576
sent : & Vec < Coin > ,
567
577
) -> Result < ( ) , ContractError > {
568
- // verify correct # of nft's provided & are accepted nfts
569
- // verify that the bundle is included in infusions
570
578
for c in & elig_col {
571
579
let elig = bundle
572
580
. iter ( )
573
581
. filter ( |b| b. addr == c. addr )
574
582
. collect :: < Vec < _ > > ( ) ;
575
583
584
+ let elig_len: u64 = elig. len ( ) as u64 ;
576
585
if let Some ( ps) = c. payment_substitute . clone ( ) {
577
- if !sent
578
- . iter ( )
579
- . any ( |coin| coin. denom == ps. denom && coin. amount >= ps. amount )
580
- {
581
- let mut havea = 0u128 ;
582
- let mut haved = String :: new ( ) ;
583
- for coin in sent {
584
- if coin. denom == ps. denom {
585
- havea = coin. amount . into ( ) ;
586
- haved = coin. denom . clone ( ) ;
587
- break ;
586
+ if elig_len == 0u64 {
587
+ if !sent
588
+ . iter ( )
589
+ . any ( |coin| coin. denom == ps. denom && coin. amount >= ps. amount )
590
+ {
591
+ let mut havea = 0u128 ;
592
+ let mut haved = String :: new ( ) ;
593
+ for coin in sent {
594
+ if coin. denom == ps. denom {
595
+ havea = coin. amount . into ( ) ;
596
+ haved = coin. denom . clone ( ) ;
597
+ break ;
598
+ }
588
599
}
600
+ return Err ( ContractError :: PaymentSubstituteNotProvided {
601
+ col : c. addr . to_string ( ) ,
602
+ haved,
603
+ havea : havea. to_string ( ) ,
604
+ wantd : ps. denom ,
605
+ wanta : ps. amount . to_string ( ) ,
606
+ } ) ;
589
607
}
590
- return Err ( ContractError :: PaymentSubstituteNotProvided {
591
- col : c. addr . to_string ( ) ,
592
- haved,
593
- havea : havea. to_string ( ) ,
594
- wantd : ps. denom ,
595
- wanta : ps. amount . to_string ( ) ,
596
- } ) ;
597
608
}
598
609
} else if elig. is_empty ( ) {
599
610
return Err ( ContractError :: CollectionNotEligible {
600
611
col : c. addr . to_string ( ) ,
601
612
} ) ;
602
- // ensure minimum is met
603
- } else if elig. len ( ) as u64 != c. min_req {
604
- return Err ( ContractError :: BundleNotAccepted {
605
- have : elig. len ( ) as u64 ,
606
- want : c. min_req ,
607
- } ) ;
608
- } else if c. max_req . is_some_and ( |a| elig. len ( ) as u64 > a) {
613
+ } else if let Some ( max) = c. max_req {
614
+ if elig_len > max {
615
+ return Err ( ContractError :: BundleNotAccepted {
616
+ have : elig_len,
617
+ want : c. min_req ,
618
+ } ) ;
619
+ }
620
+ } else if elig_len != c. min_req {
609
621
return Err ( ContractError :: BundleNotAccepted {
610
- have : elig . len ( ) as u64 ,
622
+ have : elig_len ,
611
623
want : c. min_req ,
612
624
} ) ;
613
625
}
@@ -788,6 +800,54 @@ fn random_mintable_token_mapping(
788
800
Ok ( TokenPositionMapping { position, token_id } )
789
801
}
790
802
803
+ /// Update the configuration of the app
804
+ fn update_config (
805
+ deps : DepsMut ,
806
+ msg : MessageInfo ,
807
+ uc : UpdatingConfig ,
808
+ ) -> Result < Response , ContractError > {
809
+ let mut config = CONFIG . load ( deps. storage ) ?;
810
+ // Only the admin should be able to call this
811
+ if config. contract_owner != msg. sender {
812
+ return Err ( ContractError :: Admin ( AdminError :: NotAdmin { } ) ) ;
813
+ }
814
+
815
+ if let Some ( owner) = uc. contract_owner {
816
+ config. contract_owner = deps. api . addr_validate ( & owner) ?;
817
+ }
818
+
819
+ if let Some ( of) = uc. owner_fee {
820
+ config. owner_fee = of;
821
+ }
822
+
823
+ if let Some ( cf) = uc. min_creation_fee {
824
+ config. min_creation_fee = Some ( cf) ;
825
+ }
826
+
827
+ if let Some ( mif) = uc. min_infusion_fee {
828
+ config. min_infusion_fee = Some ( mif) ;
829
+ }
830
+
831
+ if let Some ( mi) = uc. max_infusions {
832
+ config. max_infusions = mi;
833
+ }
834
+
835
+ if let Some ( mpb) = uc. min_per_bundle {
836
+ config. min_per_bundle = mpb;
837
+ }
838
+
839
+ if let Some ( mb) = uc. max_bundles {
840
+ config. max_bundles = mb;
841
+ }
842
+
843
+ if let Some ( ci) = uc. code_id {
844
+ config. code_id = ci;
845
+ }
846
+
847
+ CONFIG . save ( deps. storage , & config) ?;
848
+ Ok ( Response :: new ( ) )
849
+ }
850
+
791
851
// source: https://github.com/public-awesome/launchpad/blob/main/contracts/minters/vending-minter/src/contract.rs#L1371
792
852
#[ cfg_attr( not( feature = "library" ) , entry_point) ]
793
853
pub fn migrate ( deps : DepsMut , _env : Env , _msg : MigrateMsg ) -> StdResult < Response > {
@@ -799,10 +859,10 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response
799
859
let version: Version = current_version
800
860
. version
801
861
. parse ( )
802
- . map_err ( |_| StdError :: generic_err ( "Invalid contract version" ) ) ?;
862
+ . map_err ( |_| StdError :: generic_err ( "Invalid current contract version" ) ) ?;
803
863
let new_version: Version = CONTRACT_VERSION
804
864
. parse ( )
805
- . map_err ( |_| StdError :: generic_err ( "Invalid contract version" ) ) ?;
865
+ . map_err ( |_| StdError :: generic_err ( "Invalid new contract version" ) ) ?;
806
866
807
867
if version > new_version {
808
868
return Err ( StdError :: generic_err ( "Cannot upgrade to a previous contract version" ) . into ( ) ) ;
0 commit comments