Skip to content

Commit

Permalink
feat: building trade account withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Dec 3, 2023
1 parent eea20bf commit 9144e2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/aiken-virtual-dex/types.ak
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ pub type TradeAddressDatum {

pub type TradeAddressRedeemer {
PlaceOrder
TradeWithdrawal
TradeWithdrawal { withdraw_output: OutputReference }
}
17 changes: 13 additions & 4 deletions lib/aiken-virtual-dex/validators/trade_account.ak
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use aiken/transaction.{ScriptContext, Spend}
use aiken/transaction.{InlineDatum, ScriptContext, Spend, find_input}
use aiken/transaction/value.{PolicyId}
use aiken_virtual_dex/common.{all_key_signed, only_input_datum_with}
use aiken_virtual_dex/common.{all_key_signed, key_signed, only_input_datum_with}
use aiken_virtual_dex/types.{
OracleDatum, PlaceOrder, TradeAddressDatum, TradeAddressRedeemer, TradeUtxo,
TradeWithdrawal,
TradeWithdrawal, WithdrawUtxo,
}

pub fn trade_account_logic(
Expand All @@ -21,7 +21,16 @@ pub fn trade_account_logic(
expect TradeUtxo { owner } = datum
all_key_signed(transaction.extra_signatories, [owner, operation_key])
}
TradeWithdrawal -> False
TradeWithdrawal { withdraw_output } -> {
expect Some(input) = find_input(transaction.inputs, withdraw_output)
expect InlineDatum(raw_datum) = input.output.datum
expect casted_datum: TradeAddressDatum = raw_datum
when casted_datum is {
WithdrawUtxo { owner } ->
key_signed(transaction.extra_signatories, owner)
_ -> False
}
}
}
// TODO
}

0 comments on commit 9144e2a

Please sign in to comment.