fix: change in scope was applied in wrong place in pattern_ir for constr expect

This commit is contained in:
Kasey White
2023-03-12 00:12:45 -05:00
committed by Kasey
parent 4b9ccc8592
commit 4a7bbc23df
5 changed files with 104 additions and 4 deletions

View File

@@ -0,0 +1,41 @@
use aiken/list.{find, foldr}
use aiken/transaction.{Input, ScriptContext, Spend}
use aiken/transaction/value.{add, zero}
validator staking {
fn(_datum: Void, _redeemer: Void, context: ScriptContext) -> Bool {
expect Spend(ref) = context.purpose
expect Some(i) =
find(context.transaction.inputs, fn(x) { x.output_reference == ref })
let Input { output, .. } = i
let staking_addr = output.address
let v_in =
foldr(
context.transaction.inputs,
fn(x, y) {
if x.output.address == staking_addr {
add(x.output.value, y)
} else {
y
}
},
zero(),
)
let v_out =
foldr(
context.transaction.outputs,
fn(x, y) {
if x.address == staking_addr {
add(x.value, y)
} else {
y
}
},
zero(),
)
v_in == v_out
}
}