/
Tx.hs
34 lines (31 loc) · 1.4 KB
/
Tx.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
-- | Functions for working with the contract interface using typed transactions.
module Language.Plutus.Contract.Typed.Tx where
import qualified Language.Plutus.Contract.Tx as Contract
import qualified Language.PlutusTx as PlutusTx
import Ledger (TxOut, TxOutRef)
import qualified Ledger as L
import Ledger.AddressMap (AddressMap)
import qualified Ledger.Typed.Tx as Typed
import qualified Wallet.Typed.API as Typed
-- | Given the pay to script address of the 'ValidatorScript', collect from it
-- all the outputs that match a predicate, using the 'RedeemerScript'.
collectFromScriptFilter ::
forall a
. (PlutusTx.Typeable (Typed.DataType a))
=> (TxOutRef -> TxOut -> Bool)
-> AddressMap
-> Typed.ScriptInstance a
-> PlutusTx.CompiledCode (Typed.RedeemerType a)
-> Contract.UnbalancedTx
collectFromScriptFilter flt am si red =
let typed = Typed.collectFromScriptFilter flt am si red
untypedTx :: L.Tx
-- Need to match to get the existential type out
untypedTx = case typed of
(Typed.TypedTxSomeIns tx) -> Typed.toUntypedTx tx
in Contract.fromLedgerTx untypedTx