@@ -9,7 +9,7 @@ use stellar_axelar_gateway::executable::AxelarExecutableInterface;
9
9
use stellar_axelar_gateway:: AxelarGatewayMessagingClient ;
10
10
use stellar_axelar_std:: address:: AddressExt ;
11
11
use stellar_axelar_std:: events:: Event ;
12
- use stellar_axelar_std:: ttl:: { extend_instance_ttl, extend_persistent_ttl } ;
12
+ use stellar_axelar_std:: ttl:: extend_instance_ttl;
13
13
use stellar_axelar_std:: types:: Token ;
14
14
use stellar_axelar_std:: {
15
15
ensure, interfaces, when_not_paused, Operatable , Ownable , Pausable , Upgradable ,
@@ -23,7 +23,7 @@ use crate::event::{
23
23
} ;
24
24
use crate :: flow_limit:: FlowDirection ;
25
25
use crate :: interface:: InterchainTokenServiceInterface ;
26
- use crate :: storage_types :: { DataKey , TokenIdConfigValue } ;
26
+ use crate :: storage :: { self , TokenIdConfigValue } ;
27
27
use crate :: token_metadata:: TokenMetadataExt ;
28
28
use crate :: types:: {
29
29
DeployInterchainToken , HubMessage , InterchainTransfer , Message , TokenManagerType ,
@@ -53,94 +53,59 @@ impl InterchainTokenService {
53
53
) {
54
54
interfaces:: set_owner ( & env, & owner) ;
55
55
interfaces:: set_operator ( & env, & operator) ;
56
- env. storage ( ) . instance ( ) . set ( & DataKey :: Gateway , & gateway) ;
57
- env. storage ( )
58
- . instance ( )
59
- . set ( & DataKey :: GasService , & gas_service) ;
60
- env. storage ( )
61
- . instance ( )
62
- . set ( & DataKey :: ItsHubAddress , & its_hub_address) ;
63
- env. storage ( )
64
- . instance ( )
65
- . set ( & DataKey :: ChainName , & chain_name) ;
66
- env. storage ( )
67
- . instance ( )
68
- . set ( & DataKey :: NativeTokenAddress , & native_token_address) ;
69
- env. storage ( ) . instance ( ) . set (
70
- & DataKey :: InterchainTokenWasmHash ,
71
- & interchain_token_wasm_hash,
72
- ) ;
73
- env. storage ( )
74
- . instance ( )
75
- . set ( & DataKey :: TokenManagerWasmHash , & token_manager_wasm_hash) ;
56
+ storage:: set_gateway ( & env, & gateway) ;
57
+ storage:: set_gas_service ( & env, & gas_service) ;
58
+ storage:: set_its_hub_address ( & env, & its_hub_address) ;
59
+ storage:: set_chain_name ( & env, & chain_name) ;
60
+ storage:: set_native_token_address ( & env, & native_token_address) ;
61
+ storage:: set_interchain_token_wasm_hash ( & env, & interchain_token_wasm_hash) ;
62
+ storage:: set_token_manager_wasm_hash ( & env, & token_manager_wasm_hash) ;
76
63
}
77
64
}
78
65
79
66
#[ contractimpl]
80
67
impl InterchainTokenServiceInterface for InterchainTokenService {
81
68
fn gas_service ( env : & Env ) -> Address {
82
- env. storage ( )
83
- . instance ( )
84
- . get ( & DataKey :: GasService )
85
- . expect ( "gas service not found" )
69
+ storage:: gas_service ( env)
86
70
}
87
71
88
72
fn chain_name ( env : & Env ) -> String {
89
- env. storage ( )
90
- . instance ( )
91
- . get ( & DataKey :: ChainName )
92
- . expect ( "chain name not found" )
73
+ storage:: chain_name ( env)
93
74
}
94
75
95
76
fn its_hub_chain_name ( env : & Env ) -> String {
96
77
String :: from_str ( env, ITS_HUB_CHAIN_NAME )
97
78
}
98
79
99
80
fn its_hub_address ( env : & Env ) -> String {
100
- env. storage ( )
101
- . instance ( )
102
- . get ( & DataKey :: ItsHubAddress )
103
- . expect ( "its hub address not found" )
81
+ storage:: its_hub_address ( env)
104
82
}
105
83
106
84
fn native_token_address ( env : & Env ) -> Address {
107
- env. storage ( )
108
- . instance ( )
109
- . get ( & DataKey :: NativeTokenAddress )
110
- . expect ( "native token address not found" )
85
+ storage:: native_token_address ( env)
111
86
}
112
87
113
88
fn interchain_token_wasm_hash ( env : & Env ) -> BytesN < 32 > {
114
- env. storage ( )
115
- . instance ( )
116
- . get ( & DataKey :: InterchainTokenWasmHash )
117
- . expect ( "interchain token wasm hash not found" )
89
+ storage:: interchain_token_wasm_hash ( env)
118
90
}
119
91
120
92
fn token_manager_wasm_hash ( env : & Env ) -> BytesN < 32 > {
121
- env. storage ( )
122
- . instance ( )
123
- . get ( & DataKey :: TokenManagerWasmHash )
124
- . expect ( "token manager wasm hash not found" )
93
+ storage:: token_manager_wasm_hash ( env)
125
94
}
126
95
127
96
fn is_trusted_chain ( env : & Env , chain : String ) -> bool {
128
- env. storage ( )
129
- . persistent ( )
130
- . has ( & DataKey :: TrustedChain ( chain) )
97
+ storage:: is_trusted_chain ( env, chain)
131
98
}
132
99
133
100
fn set_trusted_chain ( env : & Env , chain : String ) -> Result < ( ) , ContractError > {
134
101
Self :: owner ( env) . require_auth ( ) ;
135
102
136
- let key = DataKey :: TrustedChain ( chain. clone ( ) ) ;
137
-
138
103
ensure ! (
139
- !env . storage( ) . persistent ( ) . has ( & key ) ,
104
+ !storage:: is_trusted_chain ( env , chain . clone ( ) ) ,
140
105
ContractError :: TrustedChainAlreadySet
141
106
) ;
142
107
143
- env . storage ( ) . persistent ( ) . set ( & key , & ( ) ) ;
108
+ storage:: set_trusted_chain_status ( env , chain . clone ( ) ) ;
144
109
145
110
TrustedChainSetEvent { chain } . emit ( env) ;
146
111
@@ -150,14 +115,12 @@ impl InterchainTokenServiceInterface for InterchainTokenService {
150
115
fn remove_trusted_chain ( env : & Env , chain : String ) -> Result < ( ) , ContractError > {
151
116
Self :: owner ( env) . require_auth ( ) ;
152
117
153
- let key = DataKey :: TrustedChain ( chain. clone ( ) ) ;
154
-
155
118
ensure ! (
156
- env . storage( ) . persistent ( ) . has ( & key ) ,
119
+ storage:: is_trusted_chain ( env , chain . clone ( ) ) ,
157
120
ContractError :: TrustedChainNotSet
158
121
) ;
159
122
160
- env . storage ( ) . persistent ( ) . remove ( & key ) ;
123
+ storage:: remove_trusted_chain_status ( env , chain . clone ( ) ) ;
161
124
162
125
TrustedChainRemovedEvent { chain } . emit ( env) ;
163
126
@@ -361,10 +324,7 @@ impl AxelarExecutableInterface for InterchainTokenService {
361
324
type Error = ContractError ;
362
325
363
326
fn gateway ( env : & Env ) -> Address {
364
- env. storage ( )
365
- . instance ( )
366
- . get ( & DataKey :: Gateway )
367
- . expect ( "gateway not found" )
327
+ storage:: gateway ( env)
368
328
}
369
329
370
330
fn execute (
@@ -395,7 +355,6 @@ impl InterchainTokenService {
395
355
Self :: is_trusted_chain( env, destination_chain. clone( ) ) ,
396
356
ContractError :: UntrustedChain
397
357
) ;
398
- extend_persistent_ttl ( env, & DataKey :: TrustedChain ( destination_chain. clone ( ) ) ) ;
399
358
400
359
let gateway = AxelarGatewayMessagingClient :: new ( env, & Self :: gateway ( env) ) ;
401
360
let gas_service = AxelarGasServiceClient :: new ( env, & Self :: gas_service ( env) ) ;
@@ -449,7 +408,6 @@ impl InterchainTokenService {
449
408
Message :: DeployInterchainToken ( message) => Self :: execute_deploy_message ( env, message) ,
450
409
} ?;
451
410
452
- extend_persistent_ttl ( env, & DataKey :: TrustedChain ( source_chain) ) ;
453
411
extend_instance_ttl ( env) ;
454
412
455
413
Ok ( ( ) )
@@ -479,18 +437,15 @@ impl InterchainTokenService {
479
437
return Err ( ContractError :: InvalidMessageType ) ;
480
438
} ;
481
439
ensure ! (
482
- Self :: is_trusted_chain( env, original_source_chain. clone( ) ) ,
440
+ storage :: is_trusted_chain( env, original_source_chain. clone( ) ) ,
483
441
ContractError :: UntrustedChain
484
442
) ;
485
- extend_persistent_ttl ( env, & DataKey :: TrustedChain ( original_source_chain. clone ( ) ) ) ;
486
443
487
444
Ok ( ( original_source_chain, message) )
488
445
}
489
446
490
447
fn set_token_id_config ( env : & Env , token_id : BytesN < 32 > , token_data : TokenIdConfigValue ) {
491
- env. storage ( )
492
- . persistent ( )
493
- . set ( & DataKey :: TokenIdConfig ( token_id) , & token_data) ;
448
+ storage:: set_token_id_config ( env, token_id, & token_data) ;
494
449
}
495
450
496
451
/// Retrieves the configuration value for the specified token ID.
@@ -507,10 +462,7 @@ impl InterchainTokenService {
507
462
env : & Env ,
508
463
token_id : BytesN < 32 > ,
509
464
) -> Result < TokenIdConfigValue , ContractError > {
510
- env. storage ( )
511
- . persistent ( )
512
- . get :: < _ , TokenIdConfigValue > ( & DataKey :: TokenIdConfig ( token_id) )
513
- . ok_or ( ContractError :: InvalidTokenId )
465
+ storage:: try_token_id_config ( env, token_id) . ok_or ( ContractError :: InvalidTokenId )
514
466
}
515
467
516
468
/// Retrieves the configuration value for the specified token ID and extends its TTL.
@@ -528,7 +480,7 @@ impl InterchainTokenService {
528
480
token_id : BytesN < 32 > ,
529
481
) -> Result < TokenIdConfigValue , ContractError > {
530
482
let config = Self :: token_id_config ( env, token_id. clone ( ) ) ?;
531
- extend_persistent_ttl ( env , & DataKey :: TokenIdConfig ( token_id ) ) ;
483
+
532
484
Ok ( config)
533
485
}
534
486
@@ -764,9 +716,7 @@ impl InterchainTokenService {
764
716
765
717
fn ensure_token_not_registered ( env : & Env , token_id : BytesN < 32 > ) -> Result < ( ) , ContractError > {
766
718
ensure ! (
767
- !env. storage( )
768
- . persistent( )
769
- . has( & DataKey :: TokenIdConfig ( token_id) ) ,
719
+ storage:: try_token_id_config( env, token_id) . is_none( ) ,
770
720
ContractError :: TokenAlreadyRegistered
771
721
) ;
772
722
0 commit comments