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,28 @@ 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 tx_envelope = json ! (
164
+ { "type" : "Unwitnessed Tx ConwayEra" ,
165
+ "description" : "" ,
166
+ "cborHex" : hex:: encode( tx. to_bytes( ) )
167
+ }
168
+ ) ;
169
+ log:: info!( "Transaction envelope: {}" , tx_envelope) ;
170
+ Ok ( TxCBOR ( tx. to_bytes ( ) ) )
171
+ }
154
172
}
155
173
156
174
async fn update_d_param < C : QueryLedgerState + Transactions + QueryNetwork > (
@@ -161,7 +179,7 @@ async fn update_d_param<C: QueryLedgerState + Transactions + QueryNetwork>(
161
179
ctx : TransactionContext ,
162
180
genesis_utxo : UtxoId ,
163
181
client : & C ,
164
- ) -> anyhow:: Result < McTxHash > {
182
+ ) -> anyhow:: Result < McSmartContractResult > {
165
183
let governance_data = GovernanceData :: get ( genesis_utxo, client) . await ?;
166
184
167
185
let tx = Costs :: calculate_costs (
@@ -180,17 +198,28 @@ async fn update_d_param<C: QueryLedgerState + Transactions + QueryNetwork>(
180
198
)
181
199
. await ?;
182
200
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)
201
+ if governance_data. policy . is_single_key_policy_for ( & ctx. payment_key_hash ( ) ) {
202
+ let signed_tx = ctx. sign ( & tx) . to_bytes ( ) ;
203
+ let res = client. submit_transaction ( & signed_tx) . await . map_err ( |e| {
204
+ anyhow ! (
205
+ "Submit D-parameter update transaction request failed: {}, bytes: {}" ,
206
+ e,
207
+ hex:: encode( signed_tx)
208
+ )
209
+ } ) ?;
210
+ let tx_id = McTxHash ( res. transaction . id ) ;
211
+ log:: info!( "Update D-parameter transaction submitted: {}" , hex:: encode( tx_id. 0 ) ) ;
212
+ Ok ( TxHash ( tx_id) )
213
+ } else {
214
+ let tx_envelope = json ! (
215
+ { "type" : "Unwitnessed Tx ConwayEra" ,
216
+ "description" : "" ,
217
+ "cborHex" : hex:: encode( tx. to_bytes( ) )
218
+ }
219
+ ) ;
220
+ log:: info!( "Transaction envelope: {}" , tx_envelope) ;
221
+ Ok ( TxCBOR ( tx. to_bytes ( ) ) )
222
+ }
194
223
}
195
224
196
225
fn mint_d_param_token_tx (
0 commit comments