Skip to content

Commit

Permalink
create a read primitive era independent for tx withdrawals
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino authored and erikd committed Jan 31, 2023
1 parent 5ecd872 commit b0f4ed1
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/wallet/cardano-wallet.cabal
Expand Up @@ -316,6 +316,7 @@ library
Cardano.Wallet.Read.Primitive.Tx.Features.Mint
Cardano.Wallet.Read.Primitive.Tx.Features.Outputs
Cardano.Wallet.Read.Primitive.Tx.Features.Validity
Cardano.Wallet.Read.Primitive.Tx.Features.Withdrawals
Cardano.Wallet.Read.Primitive.Tx.Mary
Cardano.Wallet.Read.Primitive.Tx.Shelley
Cardano.Wallet.Read.Tx
Expand Down
4 changes: 3 additions & 1 deletion lib/wallet/src/Cardano/Wallet/Read/Primitive/Tx/Allegra.hs
Expand Up @@ -39,8 +39,10 @@ import Cardano.Wallet.Read.Primitive.Tx.Features.Outputs
( fromAllegraTxOut )
import Cardano.Wallet.Read.Primitive.Tx.Features.Validity
( afterShelleyValidityInterval )
import Cardano.Wallet.Read.Primitive.Tx.Features.Withdrawals
( fromShelleyWdrl )
import Cardano.Wallet.Read.Primitive.Tx.Shelley
( fromShelleyMD, fromShelleyWdrl )
( fromShelleyMD )
import Cardano.Wallet.Read.Tx
( Tx (..) )
import Cardano.Wallet.Read.Tx.CBOR
Expand Down
3 changes: 3 additions & 0 deletions lib/wallet/src/Cardano/Wallet/Read/Primitive/Tx/Alonzo.hs
Expand Up @@ -36,7 +36,10 @@ import Cardano.Wallet.Read.Primitive.Tx.Features.Outputs
( fromAlonzoTxOut )
import Cardano.Wallet.Read.Primitive.Tx.Features.Validity
( afterShelleyValidityInterval )
import Cardano.Wallet.Read.Primitive.Tx.Features.Withdrawals
( fromShelleyWdrl )
import Cardano.Wallet.Read.Primitive.Tx.Shelley
( fromShelleyMD )
import Cardano.Wallet.Read.Tx
( Tx (..) )
import Cardano.Wallet.Read.Tx.CBOR
Expand Down
4 changes: 3 additions & 1 deletion lib/wallet/src/Cardano/Wallet/Read/Primitive/Tx/Babbage.hs
Expand Up @@ -39,8 +39,10 @@ import Cardano.Wallet.Read.Primitive.Tx.Features.Outputs
( fromBabbageTxOut )
import Cardano.Wallet.Read.Primitive.Tx.Features.Validity
( afterShelleyValidityInterval )
import Cardano.Wallet.Read.Primitive.Tx.Features.Withdrawals
( fromShelleyWdrl )
import Cardano.Wallet.Read.Primitive.Tx.Shelley
( fromShelleyMD, fromShelleyWdrl )
( fromShelleyMD )
import Cardano.Wallet.Read.Tx
( Tx (..) )
import Cardano.Wallet.Read.Tx.CBOR
Expand Down
Expand Up @@ -9,10 +9,8 @@ import Prelude

import Cardano.Wallet.Read.Eras
( EraFun (..), K (..) )
import Cardano.Wallet.Read.Primitive.Tx.Mary
( fromCardanoValue )
import Cardano.Wallet.Read.Primitive.Tx.Shelley
( fromShelleyAddress )
import Cardano.Wallet.Read.Primitive.Tx.Features.Outputs
( fromCardanoValue, fromShelleyAddress )
import Cardano.Wallet.Read.Tx.CollateralOutputs
( CollateralOutputs (..) )
import Data.Maybe.Strict
Expand Down
@@ -0,0 +1,59 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}

-- |
-- Copyright: © 2020-2022 IOHK
-- License: Apache-2.0
--

module Cardano.Wallet.Read.Primitive.Tx.Features.Withdrawals
( getWithdrawals
, fromShelleyWdrl
)
where

import Prelude

import Cardano.Ledger.Crypto
( StandardCrypto )
import Cardano.Wallet.Primitive.Types.Coin
( Coin )
import Cardano.Wallet.Primitive.Types.RewardAccount
( RewardAccount )
import Cardano.Wallet.Read.Eras
( EraFun (..), K (..) )
import Cardano.Wallet.Read.Primitive.Tx.Features.Certificates
( fromStakeCredential )
import Cardano.Wallet.Read.Primitive.Tx.Features.Fee
( fromShelleyCoin )
import Cardano.Wallet.Read.Tx.Withdrawals
( Withdrawals (..) )
import Data.Bifunctor
( Bifunctor (..) )
import Data.Map.Strict
( Map )

import qualified Cardano.Ledger.Shelley.TxBody as SL
import qualified Cardano.Wallet.Primitive.Types.Coin as W
import qualified Cardano.Wallet.Primitive.Types.RewardAccount as W
import qualified Data.Map.Strict as Map

getWithdrawals :: EraFun Withdrawals (K (Maybe (Map RewardAccount Coin)))
getWithdrawals = EraFun
{ byronFun = noWithdrawals
, shelleyFun = yesWithdrawals
, allegraFun = yesWithdrawals
, maryFun = yesWithdrawals
, alonzoFun = yesWithdrawals
, babbageFun = yesWithdrawals
}
where
noWithdrawals = const $ K Nothing
yesWithdrawals (Withdrawals ttl)
= K . Just . fromShelleyWdrl $ ttl

fromShelleyWdrl :: SL.Wdrl StandardCrypto -> Map W.RewardAccount W.Coin
fromShelleyWdrl (SL.Wdrl wdrl) = Map.fromList $
bimap (fromStakeCredential . SL.getRwdCred) fromShelleyCoin
<$> Map.toList wdrl
3 changes: 3 additions & 0 deletions lib/wallet/src/Cardano/Wallet/Read/Primitive/Tx/Mary.hs
Expand Up @@ -35,7 +35,10 @@ import Cardano.Wallet.Read.Primitive.Tx.Features.Outputs
( fromMaryTxOut )
import Cardano.Wallet.Read.Primitive.Tx.Features.Validity
( afterShelleyValidityInterval )
import Cardano.Wallet.Read.Primitive.Tx.Features.Withdrawals
( fromShelleyWdrl )
import Cardano.Wallet.Read.Primitive.Tx.Shelley
( fromShelleyMD )
import Cardano.Wallet.Read.Tx
( Tx (Tx) )
import Cardano.Wallet.Read.Tx.CBOR
Expand Down
3 changes: 1 addition & 2 deletions lib/wallet/src/Cardano/Wallet/Read/Primitive/Tx/Shelley.hs
Expand Up @@ -10,8 +10,7 @@
--

module Cardano.Wallet.Read.Primitive.Tx.Shelley
( fromShelleyWdrl
, fromShelleyMD
( fromShelleyMD
, fromShelleyTx
)
where
Expand Down

0 comments on commit b0f4ed1

Please sign in to comment.