Skip to content

Commit

Permalink
feat(applying): fixing check_fees when only genesis UTxOs are concerned
Browse files Browse the repository at this point in the history
  • Loading branch information
MaicoLeberle committed Nov 10, 2023
1 parent e0f9f14 commit f76fa64
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions pallas-applying/src/byron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ fn check_outs_have_lovelace(tx: &Tx) -> ValidationResult {

fn check_fees(tx: &Tx, size: &u64, utxos: &UTxOs, prot_pps: &ByronProtParams) -> ValidationResult {
let mut inputs_balance: u64 = 0;
let mut only_redeem_utxos: bool = true;
for input in tx.inputs.iter() {
if !is_redeem_utxo(input, utxos) {
only_redeem_utxos = false;
}
match utxos
.get(&MultiEraInput::from_byron(input))
.and_then(MultiEraOutput::as_byron)
Expand All @@ -83,16 +87,34 @@ fn check_fees(tx: &Tx, size: &u64, utxos: &UTxOs, prot_pps: &ByronProtParams) ->
None => return Err(ValidationError::UnableToComputeFees),
}
}
let mut outputs_balance: u64 = 0;
for output in tx.outputs.iter() {
outputs_balance += output.amount
if only_redeem_utxos {
Ok(())
} else {
let mut outputs_balance: u64 = 0;
for output in tx.outputs.iter() {
outputs_balance += output.amount
}
let total_balance: u64 = inputs_balance - outputs_balance;
let min_fees: u64 = prot_pps.min_fees_const + prot_pps.min_fees_factor * size;
if total_balance < min_fees {
Err(ValidationError::FeesBelowMin)
} else {
Ok(())
}
}
let total_balance: u64 = inputs_balance - outputs_balance;
let min_fees: u64 = prot_pps.min_fees_const + prot_pps.min_fees_factor * size;
if total_balance < min_fees {
return Err(ValidationError::FeesBelowMin);
}

fn is_redeem_utxo(input: &TxIn, utxos: &UTxOs) -> bool {
match find_tx_out(input, utxos) {
Ok(tx_out) => {
let address: ByronAddress = mk_byron_address(&tx_out.address);
match address.decode() {
Ok(addr_payload) => matches!(addr_payload.addrtype, AddrType::Redeem),
_ => false,
}
}
_ => false,
}
Ok(())
}

fn check_size(size: &u64, prot_pps: &ByronProtParams) -> ValidationResult {
Expand Down

0 comments on commit f76fa64

Please sign in to comment.