Skip to content

Commit

Permalink
add withdrawals era-dependent extraction from Read.Tx
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino authored and erikd committed Jan 31, 2023
1 parent b8bd2d0 commit 5ecd872
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/wallet/cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ library
Cardano.Wallet.Read.Tx.Outputs
Cardano.Wallet.Read.Tx.Validity
Cardano.Wallet.Read.Tx.Witnesses
Cardano.Wallet.Read.Tx.Withdrawals
Cardano.Wallet.Registry
Cardano.Wallet.Shelley.BlockchainSource
Cardano.Wallet.Shelley.Compatibility
Expand Down
65 changes: 65 additions & 0 deletions lib/wallet/src/Cardano/Wallet/Read/Tx/Withdrawals.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

-- |
-- Copyright: © 2020-2022 IOHK
-- License: Apache-2.0
--
-- Raw witnesses data extraction from 'Tx'
--

module Cardano.Wallet.Read.Tx.Withdrawals
( WithdrawalsType
, Withdrawals (..)
, getEraWithdrawals
) where

import Prelude

import Cardano.Api
( AllegraEra, AlonzoEra, BabbageEra, ByronEra, MaryEra, ShelleyEra )
import Cardano.Ledger.Crypto
( StandardCrypto )
import Cardano.Wallet.Read.Eras
( EraFun (..) )
import Cardano.Wallet.Read.Tx
( Tx (..) )
import Cardano.Wallet.Read.Tx.Eras
( onTx )
import GHC.Records
( HasField (getField) )

import qualified Cardano.Ledger.Alonzo.Tx as AL
import qualified Cardano.Ledger.Shelley.API as SH

type family WithdrawalsType era where
WithdrawalsType ByronEra = ()
WithdrawalsType ShelleyEra = SH.Wdrl StandardCrypto
WithdrawalsType AllegraEra = SH.Wdrl StandardCrypto
WithdrawalsType MaryEra = SH.Wdrl StandardCrypto
WithdrawalsType AlonzoEra = SH.Wdrl StandardCrypto
WithdrawalsType BabbageEra = SH.Wdrl StandardCrypto

newtype Withdrawals era = Withdrawals (WithdrawalsType era)

deriving instance Show (WithdrawalsType era) => Show (Withdrawals era)
deriving instance Eq (WithdrawalsType era) => Eq (Withdrawals era)

getEraWithdrawals :: EraFun Tx Withdrawals
getEraWithdrawals = EraFun
{ byronFun = \_ -> Withdrawals ()
, shelleyFun = onTx $ \(SH.Tx b _ _ ) -> getWithdrawals b
, allegraFun = onTx $ \(SH.Tx b _ _ ) -> getWithdrawals b
, maryFun = onTx $ \(SH.Tx b _ _ ) -> getWithdrawals b
, alonzoFun = onTx $ \(AL.ValidatedTx b _ _ _) -> getWithdrawals b
, babbageFun = onTx $ \(AL.ValidatedTx b _ _ _) -> getWithdrawals b
}

getWithdrawals
:: ( HasField "wdrls" a (WithdrawalsType b))
=> a -> Withdrawals b
getWithdrawals = Withdrawals . getField @"wdrls"

0 comments on commit 5ecd872

Please sign in to comment.