Skip to content

Commit

Permalink
Fix documentation in cardano-balance-tx. (#4234)
Browse files Browse the repository at this point in the history
## Issue

ADP-3186

## Description

This PR fixes the documentation for selected functions in
`cardano-balance-tx`.

In particular, references to "the wallet" have been removed.
  • Loading branch information
jonathanknowles authored Nov 16, 2023
2 parents fd9eb91 + 467f4e0 commit e9f88b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ withConstraints era a = case era of
RecentEraBabbage -> a
RecentEraConway -> a

-- | Return a proof that the wallet can create txs in this era, or @Nothing@.
-- | Returns a proof that the given era is a recent era.
--
-- Otherwise, returns @Nothing@.
toRecentEra :: CardanoApi.CardanoEra era -> Maybe (RecentEra era)
toRecentEra = \case
CardanoApi.ConwayEra -> Just RecentEraConway
Expand Down
20 changes: 14 additions & 6 deletions lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx/Balance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,10 +1169,20 @@ selectAssets era (ProtocolParameters pp) utxoAssumptions outs redeemers
extraBytes = 8

data ChangeAddressGen s = ChangeAddressGen
{ getChangeAddressGen :: s -> (Address, s)
{
-- | Generates a new change address.
--
genChangeAddress :: s -> (Address, s)

-- | Returns the longest address that the wallet can generate for a given
-- key.
-- | Returns a /dummy/ change address of the maximum possible length for
-- this generator.
--
-- Implementations must satisfy the following property:
--
-- @
-- ∀ s. length (fst (genChangeAddress s)) <=
-- length maxLengthChangeAddress
-- @
--
-- This is useful in situations where we want to compute some function of
-- an output under construction (such as a minimum UTxO value), but don't
Expand All @@ -1186,9 +1196,7 @@ data ChangeAddressGen s = ChangeAddressGen
, maxLengthChangeAddress :: Address
}

-- | Augments the given outputs with new outputs. These new outputs correspond
-- to change outputs to which new addresses have been assigned. This updates
-- the wallet state as it needs to keep track of new pending change addresses.
-- | Assigns addresses to the change outputs of the given selection.
assignChangeAddresses
:: ChangeAddressGen s
-> SelectionOf W.TokenBundle
Expand Down
4 changes: 2 additions & 2 deletions lib/wallet/test/unit/Internal/Cardano/Write/Tx/BalanceSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ spec_balanceTransaction = describe "balanceTransaction" $ do
let expectedChange = fmap Convert.toWalletAddress <$>
flip evalState s0
$ replicateM nChange
$ state @Identity (getChangeAddressGen dummyChangeAddrGen)
$ state @Identity (genChangeAddress dummyChangeAddrGen)

let address :: Babbage.BabbageTxOut StandardBabbage -> W.Address
address (Babbage.BabbageTxOut addr _ _ _) = Convert.toWallet addr
Expand Down Expand Up @@ -2312,7 +2312,7 @@ costModelsForTesting = either (error . show) id $ do

dummyChangeAddrGen :: ChangeAddressGen DummyChangeState
dummyChangeAddrGen = ChangeAddressGen
{ getChangeAddressGen = \(DummyChangeState i) ->
{ genChangeAddress = \(DummyChangeState i) ->
(addressAtIx $ toEnum i, DummyChangeState $ succ i)
, maxLengthChangeAddress = addressAtIx minBound
}
Expand Down

0 comments on commit e9f88b3

Please sign in to comment.