Skip to content

Commit c174728

Browse files
author
CodeSandwich
committed
Add special validation when JCLI TX builder finds owned stake delegation
1 parent 9c7184a commit c174728

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

jcli/src/jcli_app/transaction/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ custom_error! { pub Error
131131
ExpectingOnlyOneSigningKey { got: usize }
132132
= "expecting only one signing keys but got {got}",
133133
CertificateError { error: certificate::Error } = "certificate error {error}",
134+
135+
TxWithOwnerStakeDelegationMultiInputs { inputs: usize }
136+
= "transaction has owner stake delegation, but has {inputs} inputs, should have 1",
137+
TxWithOwnerStakeDelegationHasUtxoInput = "transaction has owner stake delegation, but has UTxO input",
138+
TxWithOwnerStakeDelegationHasOutputs = "transaction has owner stake delegation, but has outputs",
134139
}
135140

136141
/*

jcli/src/jcli_app/transaction/staging.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl Staging {
192192
payload: &P,
193193
fee_algorithm: &FA,
194194
output_policy: chain::transaction::OutputPolicy,
195-
) -> Result<chain::transaction::Balance, Error>
195+
) -> Result<Balance, Error>
196196
where
197197
FA: FeeAlgorithm,
198198
P: Payload,
@@ -215,7 +215,7 @@ impl Staging {
215215
&mut self,
216216
fee_algorithm: &FA,
217217
output_policy: chain::transaction::OutputPolicy,
218-
) -> Result<chain::transaction::Balance, Error>
218+
) -> Result<Balance, Error>
219219
where
220220
FA: FeeAlgorithm,
221221
{
@@ -241,7 +241,24 @@ impl Staging {
241241
self.finalize_payload(&c, fee_algorithm, output_policy)
242242
}
243243
Certificate::OwnerStakeDelegation(c) => {
244-
self.finalize_payload(&c, fee_algorithm, output_policy)
244+
let balance = self.finalize_payload(&c, fee_algorithm, output_policy)?;
245+
match self.inputs() {
246+
[input] => match input.input {
247+
interfaces::TransactionInputType::Account(_) => (),
248+
interfaces::TransactionInputType::Utxo(_, _) => {
249+
return Err(Error::TxWithOwnerStakeDelegationHasUtxoInput)
250+
}
251+
},
252+
inputs @ _ => {
253+
return Err(Error::TxWithOwnerStakeDelegationMultiInputs {
254+
inputs: inputs.len(),
255+
})
256+
}
257+
};
258+
if self.outputs().is_empty() == false {
259+
return Err(Error::TxWithOwnerStakeDelegationHasOutputs);
260+
}
261+
Ok(balance)
245262
}
246263
},
247264
}

0 commit comments

Comments
 (0)