4
4
//! The datum encodes D-parameter using VersionedGenericDatum envelope with the D-parameter being
5
5
//! `datum` field being `[num_permissioned_candidates, num_registered_candidates]`.
6
6
7
+ use std:: any:: Any ;
8
+
7
9
use crate :: await_tx:: { AwaitTx , FixedDelayRetries } ;
8
10
use crate :: cardano_keys:: CardanoPaymentSigningKey ;
9
11
use crate :: csl:: {
@@ -20,7 +22,12 @@ use ogmios_client::{
20
22
types:: OgmiosUtxo ,
21
23
} ;
22
24
use partner_chains_plutus_data:: d_param:: { d_parameter_to_plutus_data, DParamDatum } ;
23
- use sidechain_domain:: { DParameter , McTxHash , UtxoId } ;
25
+ use serde_json:: json;
26
+ use sidechain_domain:: {
27
+ DParameter , MainchainKeyHash , McSmartContractResult ,
28
+ McSmartContractResult :: { TxCBOR , TxHash } ,
29
+ McTxHash , UtxoId ,
30
+ } ;
24
31
25
32
#[ cfg( test) ]
26
33
mod tests;
@@ -32,7 +39,7 @@ pub trait UpsertDParam {
32
39
genesis_utxo : UtxoId ,
33
40
d_parameter : & DParameter ,
34
41
payment_signing_key : & CardanoPaymentSigningKey ,
35
- ) -> anyhow:: Result < Option < McTxHash > > ;
42
+ ) -> anyhow:: Result < Option < McSmartContractResult > > ;
36
43
}
37
44
38
45
impl < C : QueryLedgerState + QueryNetwork + Transactions + QueryUtxoByUtxoId > UpsertDParam for C {
@@ -41,7 +48,7 @@ impl<C: QueryLedgerState + QueryNetwork + Transactions + QueryUtxoByUtxoId> Upse
41
48
genesis_utxo : UtxoId ,
42
49
d_parameter : & DParameter ,
43
50
payment_signing_key : & CardanoPaymentSigningKey ,
44
- ) -> anyhow:: Result < Option < McTxHash > > {
51
+ ) -> anyhow:: Result < Option < McSmartContractResult > > {
45
52
upsert_d_param (
46
53
genesis_utxo,
47
54
d_parameter,
@@ -62,7 +69,7 @@ pub async fn upsert_d_param<
62
69
payment_signing_key : & CardanoPaymentSigningKey ,
63
70
ogmios_client : & C ,
64
71
await_tx : & A ,
65
- ) -> anyhow:: Result < Option < McTxHash > > {
72
+ ) -> anyhow:: Result < Option < McSmartContractResult > > {
66
73
let ctx = TransactionContext :: for_payment_key ( payment_signing_key, ogmios_client) . await ?;
67
74
let ( validator, policy) = crate :: scripts_data:: d_parameter_scripts ( genesis_utxo, ctx. network ) ?;
68
75
let validator_address = validator. address_bech32 ( ctx. network ) ?;
@@ -96,7 +103,7 @@ pub async fn upsert_d_param<
96
103
)
97
104
} ,
98
105
} ;
99
- if let Some ( tx_hash) = tx_hash_opt {
106
+ if let Some ( TxHash ( tx_hash) ) = tx_hash_opt {
100
107
await_tx. await_tx_output ( ogmios_client, UtxoId :: new ( tx_hash. 0 , 0 ) ) . await ?;
101
108
}
102
109
Ok ( tx_hash_opt)
@@ -131,7 +138,7 @@ async fn insert_d_param<C: QueryLedgerState + Transactions + QueryNetwork>(
131
138
ctx : TransactionContext ,
132
139
genesis_utxo : UtxoId ,
133
140
client : & C ,
134
- ) -> anyhow:: Result < McTxHash > {
141
+ ) -> anyhow:: Result < McSmartContractResult > {
135
142
let gov_data = GovernanceData :: get ( genesis_utxo, client) . await ?;
136
143
137
144
let tx = Costs :: calculate_costs (
@@ -140,17 +147,41 @@ async fn insert_d_param<C: QueryLedgerState + Transactions + QueryNetwork>(
140
147
)
141
148
. await ?;
142
149
143
- let signed_tx = ctx. sign ( & tx) . to_bytes ( ) ;
144
- let res = client. submit_transaction ( & signed_tx) . await . map_err ( |e| {
145
- anyhow ! (
146
- "Submit insert D-parameter transaction request failed: {}, bytes: {}" ,
147
- e,
148
- hex:: encode( signed_tx)
149
- )
150
- } ) ?;
151
- let tx_id = McTxHash ( res. transaction . id ) ;
152
- log:: info!( "Transaction submitted: {}" , hex:: encode( tx_id. 0 ) ) ;
153
- Ok ( tx_id)
150
+ if gov_data. policy . is_single_key_policy_for ( & ctx. payment_key_hash ( ) ) {
151
+ let signed_tx = ctx. sign ( & tx) . to_bytes ( ) ;
152
+ let res = client. submit_transaction ( & signed_tx) . await . map_err ( |e| {
153
+ anyhow ! (
154
+ "Submit insert D-parameter transaction request failed: {}, bytes: {}" ,
155
+ e,
156
+ hex:: encode( signed_tx)
157
+ )
158
+ } ) ?;
159
+ let tx_id = McTxHash ( res. transaction . id ) ;
160
+ log:: info!( "Transaction submitted: {}" , hex:: encode( tx_id. 0 ) ) ;
161
+ Ok ( TxHash ( tx_id) )
162
+ } else {
163
+ let authorities = gov_data. policy . key_hashes ( ) ;
164
+ if authorities. contains ( & ctx. payment_key_hash ( ) . to_bytes ( ) . try_into ( ) . unwrap ( ) ) {
165
+ let signed_tx = ctx. sign ( & tx) . to_bytes ( ) ;
166
+ let tx_envelope = json ! (
167
+ { "type" : "Witnessed Tx ConwayEra" ,
168
+ "description" : "" ,
169
+ "cborHex" : hex:: encode( signed_tx. clone( ) )
170
+ }
171
+ ) ;
172
+ log:: info!( "Transaction envelope: {}" , tx_envelope) ;
173
+ Ok ( TxCBOR ( signed_tx) )
174
+ } else {
175
+ let tx_envelope = json ! (
176
+ { "type" : "Unwitnessed Tx ConwayEra" ,
177
+ "description" : "" ,
178
+ "cborHex" : hex:: encode( tx. to_bytes( ) )
179
+ }
180
+ ) ;
181
+ log:: info!( "Transaction envelope: {}" , tx_envelope) ;
182
+ Ok ( TxCBOR ( tx. to_bytes ( ) ) )
183
+ }
184
+ }
154
185
}
155
186
156
187
async fn update_d_param < C : QueryLedgerState + Transactions + QueryNetwork > (
@@ -161,7 +192,7 @@ async fn update_d_param<C: QueryLedgerState + Transactions + QueryNetwork>(
161
192
ctx : TransactionContext ,
162
193
genesis_utxo : UtxoId ,
163
194
client : & C ,
164
- ) -> anyhow:: Result < McTxHash > {
195
+ ) -> anyhow:: Result < McSmartContractResult > {
165
196
let governance_data = GovernanceData :: get ( genesis_utxo, client) . await ?;
166
197
167
198
let tx = Costs :: calculate_costs (
@@ -180,17 +211,41 @@ async fn update_d_param<C: QueryLedgerState + Transactions + QueryNetwork>(
180
211
)
181
212
. await ?;
182
213
183
- let signed_tx = ctx. sign ( & tx) . to_bytes ( ) ;
184
- let res = client. submit_transaction ( & signed_tx) . await . map_err ( |e| {
185
- anyhow ! (
186
- "Submit D-parameter update transaction request failed: {}, bytes: {}" ,
187
- e,
188
- hex:: encode( signed_tx)
189
- )
190
- } ) ?;
191
- let tx_id = McTxHash ( res. transaction . id ) ;
192
- log:: info!( "Update D-parameter transaction submitted: {}" , hex:: encode( tx_id. 0 ) ) ;
193
- Ok ( tx_id)
214
+ if governance_data. policy . is_single_key_policy_for ( & ctx. payment_key_hash ( ) ) {
215
+ let signed_tx = ctx. sign ( & tx) . to_bytes ( ) ;
216
+ let res = client. submit_transaction ( & signed_tx) . await . map_err ( |e| {
217
+ anyhow ! (
218
+ "Submit D-parameter update transaction request failed: {}, bytes: {}" ,
219
+ e,
220
+ hex:: encode( signed_tx)
221
+ )
222
+ } ) ?;
223
+ let tx_id = McTxHash ( res. transaction . id ) ;
224
+ log:: info!( "Update D-parameter transaction submitted: {}" , hex:: encode( tx_id. 0 ) ) ;
225
+ Ok ( TxHash ( tx_id) )
226
+ } else {
227
+ let authorities = governance_data. policy . key_hashes ( ) ;
228
+ if authorities. contains ( & ctx. payment_key_hash ( ) . to_bytes ( ) . try_into ( ) . unwrap ( ) ) {
229
+ let signed_tx = ctx. sign ( & tx) . to_bytes ( ) ;
230
+ let tx_envelope = json ! (
231
+ { "type" : "Witnessed Tx ConwayEra" ,
232
+ "description" : "" ,
233
+ "cborHex" : hex:: encode( signed_tx. clone( ) )
234
+ }
235
+ ) ;
236
+ log:: info!( "Transaction envelope: {}" , tx_envelope) ;
237
+ Ok ( TxCBOR ( signed_tx) )
238
+ } else {
239
+ let tx_envelope = json ! (
240
+ { "type" : "Unwitnessed Tx ConwayEra" ,
241
+ "description" : "" ,
242
+ "cborHex" : hex:: encode( tx. to_bytes( ) )
243
+ }
244
+ ) ;
245
+ log:: info!( "Transaction envelope: {}" , tx_envelope) ;
246
+ Ok ( TxCBOR ( tx. to_bytes ( ) ) )
247
+ }
248
+ }
194
249
}
195
250
196
251
fn mint_d_param_token_tx (
0 commit comments