-
Notifications
You must be signed in to change notification settings - Fork 211
/
CollateralOutputs.hs
42 lines (36 loc) · 1.3 KB
/
CollateralOutputs.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
35
36
37
38
39
40
41
42
{-# LANGUAGE TypeFamilies #-}
module Cardano.Wallet.Read.Primitive.Tx.Features.CollateralOutputs
( getCollateralOutputs
)
where
import Prelude
import Cardano.Wallet.Read.Eras
( EraFun (..), K (..) )
import Cardano.Wallet.Read.Primitive.Tx.Features.Outputs
( fromCardanoValue, fromShelleyAddress )
import Cardano.Wallet.Read.Tx.CollateralOutputs
( CollateralOutputs (..) )
import Data.Maybe.Strict
( strictMaybeToMaybe )
import Ouroboros.Consensus.Shelley.Eras
( StandardBabbage )
import qualified Cardano.Api.Shelley as Cardano
import qualified Cardano.Ledger.Babbage as Babbage
import qualified Cardano.Ledger.Babbage.TxBody as Babbage
import qualified Cardano.Wallet.Primitive.Types.Tx.TxOut as W
getCollateralOutputs :: EraFun CollateralOutputs (K (Maybe W.TxOut))
getCollateralOutputs = EraFun
{ byronFun = \_ -> K Nothing
, shelleyFun = \_ -> K Nothing
, allegraFun = \_ -> K Nothing
, maryFun = \_ -> K Nothing
, alonzoFun = \_ -> K Nothing
, babbageFun = \(CollateralOutputs mo)
-> K $ fromBabbageTxOut <$> strictMaybeToMaybe mo
}
fromBabbageTxOut
:: Babbage.TxOut StandardBabbage
-> W.TxOut
fromBabbageTxOut (Babbage.TxOut addr value _datum _refScript) =
W.TxOut (fromShelleyAddress addr) $
fromCardanoValue $ Cardano.fromMaryValue value