1
- use axelar_wasm_std:: IntoContractError ;
1
+ use axelar_wasm_std:: { nonempty , FnExt , IntoContractError } ;
2
2
use cosmwasm_std:: { DepsMut , HexBinary , QuerierWrapper , Response , Storage } ;
3
3
use error_stack:: { bail, ensure, report, Result , ResultExt } ;
4
4
use router_api:: { Address , ChainName , ChainNameRaw , CrossChainId } ;
@@ -21,12 +21,12 @@ pub enum Error {
21
21
FailedItsContractRegistration ( ChainNameRaw ) ,
22
22
#[ error( "failed to deregister its contract for chain {0}" ) ]
23
23
FailedItsContractDeregistration ( ChainNameRaw ) ,
24
- #[ error( "failed to execute message " ) ]
25
- FailedExecuteMessage ,
26
- #[ error( "failed to query nexus " ) ]
27
- NexusQueryError ,
28
- #[ error( "storage error " ) ]
29
- StorageError ,
24
+ #[ error( "chain config for {0} already set " ) ]
25
+ ChainConfigAlreadySet ( ChainNameRaw ) ,
26
+ #[ error( "invalid chain max uint " ) ]
27
+ LoadChainConfig ( ChainNameRaw ) ,
28
+ #[ error( "failed to save chain config for chain {0} " ) ]
29
+ SaveChainConfig ( ChainNameRaw ) ,
30
30
}
31
31
32
32
/// Executes an incoming ITS message.
@@ -132,3 +132,19 @@ pub fn deregister_its_contract(deps: DepsMut, chain: ChainNameRaw) -> Result<Res
132
132
133
133
Ok ( Response :: new ( ) . add_event ( Event :: ItsContractDeregistered { chain } . into ( ) ) )
134
134
}
135
+
136
+ pub fn set_chain_config (
137
+ deps : DepsMut ,
138
+ chain : ChainNameRaw ,
139
+ max_uint : nonempty:: Uint256 ,
140
+ max_target_decimals : u8 ,
141
+ ) -> Result < Response , Error > {
142
+ match state:: may_load_chain_config ( deps. storage , & chain)
143
+ . change_context_lazy ( || Error :: LoadChainConfig ( chain. clone ( ) ) ) ?
144
+ {
145
+ Some ( _) => bail ! ( Error :: ChainConfigAlreadySet ( chain) ) ,
146
+ None => state:: save_chain_config ( deps. storage , & chain, max_uint, max_target_decimals)
147
+ . change_context_lazy ( || Error :: SaveChainConfig ( chain) ) ?
148
+ . then ( |_| Ok ( Response :: new ( ) ) ) ,
149
+ }
150
+ }
0 commit comments