@@ -14,6 +14,7 @@ use crate::csl::{
14
14
use crate :: governance:: GovernanceData ;
15
15
use crate :: multisig:: { MultiSigSmartContractResult , submit_or_create_tx_to_sign} ;
16
16
use crate :: plutus_script:: PlutusScript ;
17
+ use crate :: scripts_data:: PlutusScriptData ;
17
18
use crate :: { cardano_keys:: CardanoPaymentSigningKey , scripts_data} ;
18
19
use anyhow:: anyhow;
19
20
use cardano_serialization_lib:: {
@@ -47,11 +48,11 @@ pub async fn upsert_permissioned_candidates<
47
48
let ctx = TransactionContext :: for_payment_key ( payment_signing_key, client) . await ?;
48
49
let scripts = scripts_data:: permissioned_candidates_scripts ( genesis_utxo, ctx. network ) ?;
49
50
let governance_data = GovernanceData :: get ( genesis_utxo, client) . await ?;
50
- let validator_utxos = client. query_utxos ( & [ scripts. validator_address ] ) . await ?;
51
+ let validator_utxos = client. query_utxos ( & [ scripts. validator_address . clone ( ) ] ) . await ?;
51
52
let mut candidates = candidates. to_owned ( ) ;
52
53
candidates. sort ( ) ;
53
54
54
- let result_opt = match get_current_permissioned_candidates ( validator_utxos) ? {
55
+ let result_opt = match get_current_permissioned_candidates ( validator_utxos, & scripts ) ? {
55
56
Some ( ( _, current_permissioned_candidates) )
56
57
if current_permissioned_candidates == * candidates =>
57
58
{
@@ -99,8 +100,18 @@ pub async fn upsert_permissioned_candidates<
99
100
100
101
fn get_current_permissioned_candidates (
101
102
validator_utxos : Vec < OgmiosUtxo > ,
103
+ scripts : & PlutusScriptData ,
102
104
) -> Result < Option < ( OgmiosUtxo , Vec < PermissionedCandidateData > ) > , anyhow:: Error > {
103
- if let Some ( utxo) = validator_utxos. first ( ) {
105
+ let utxos_with_permissioned_candidates_token: Vec < OgmiosUtxo > = validator_utxos
106
+ . into_iter ( )
107
+ . filter ( |utxo| utxo. value . native_tokens . get ( & scripts. policy_id ( ) . 0 ) . is_some ( ) )
108
+ . collect ( ) ;
109
+
110
+ if utxos_with_permissioned_candidates_token. len ( ) > 1 {
111
+ return Err ( anyhow ! ( "Multiple UTXOs with permissioned candidates token found" ) ) ;
112
+ }
113
+
114
+ if let Some ( utxo) = utxos_with_permissioned_candidates_token. first ( ) {
104
115
let datum = utxo. datum . clone ( ) . ok_or_else ( || {
105
116
anyhow ! ( "Invalid state: an UTXO at the validator script address does not have a datum" )
106
117
} ) ?;
@@ -281,8 +292,9 @@ where
281
292
C : QueryNetwork + QueryLedgerState ,
282
293
{
283
294
let scripts = scripts_data:: permissioned_candidates_scripts ( genesis_utxo, network) ?;
284
- let validator_utxos = client. query_utxos ( & [ scripts. validator_address ] ) . await ?;
285
- Ok ( get_current_permissioned_candidates ( validator_utxos) ?. map ( |( _, candidates) | candidates) )
295
+ let validator_utxos = client. query_utxos ( & [ scripts. validator_address . clone ( ) ] ) . await ?;
296
+ Ok ( get_current_permissioned_candidates ( validator_utxos, & scripts) ?
297
+ . map ( |( _, candidates) | candidates) )
286
298
}
287
299
288
300
#[ cfg( test) ]
0 commit comments