From 9144e2a711621940f98c541ad6590e6a7f5aa45f Mon Sep 17 00:00:00 2001 From: SIDANWhatever Date: Mon, 4 Dec 2023 01:39:01 +0800 Subject: [PATCH] feat: building trade account withdrawal --- lib/aiken-virtual-dex/types.ak | 2 +- .../validators/trade_account.ak | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/aiken-virtual-dex/types.ak b/lib/aiken-virtual-dex/types.ak index 0aaae56..5a76feb 100644 --- a/lib/aiken-virtual-dex/types.ak +++ b/lib/aiken-virtual-dex/types.ak @@ -55,5 +55,5 @@ pub type TradeAddressDatum { pub type TradeAddressRedeemer { PlaceOrder - TradeWithdrawal + TradeWithdrawal { withdraw_output: OutputReference } } diff --git a/lib/aiken-virtual-dex/validators/trade_account.ak b/lib/aiken-virtual-dex/validators/trade_account.ak index 954fbb7..c14bd1b 100644 --- a/lib/aiken-virtual-dex/validators/trade_account.ak +++ b/lib/aiken-virtual-dex/validators/trade_account.ak @@ -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( @@ -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 }