Skip to content

Commit

Permalink
Use Void type in function assignMigrationAddresses.
Browse files Browse the repository at this point in the history
Use `Void` type in function `assignMigrationAddresses` to indicate that
no change is returned.
  • Loading branch information
jonathanknowles committed Oct 20, 2020
1 parent 66c2489 commit 4dd0b28
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -378,6 +378,8 @@ import Data.Time
( UTCTime )
import Data.Time.Clock
( getCurrentTime )
import Data.Void
( Void )
import Data.Word
( Word32, Word64 )
import Fmt
Expand Down Expand Up @@ -1688,26 +1690,28 @@ migrateWallet ctx (ApiT wid) migrateData = do
-- the number of addresses in the specified address list, addresses will be
-- recycled in order of their appearance in the original list.
assignMigrationAddresses
:: forall input output change .
:: forall input output.
( input ~ (TxIn, TxOut)
, output ~ TxOut
)
=> [Address]
-- ^ Target addresses
-> [CoinSelection]
-- ^ Migration data for the source wallet.
-> [UnsignedTx input output change]
-> [UnsignedTx input output Void]
-- ^ An unsigned transaction without change, indicated with Void.
assignMigrationAddresses addrs selections =
fst $ foldr accumulate ([], cycle addrs) selections
where
accumulate sel (txs, addrsAvailable) = first
(\addrsSelected -> makeTx sel addrsSelected : txs)
(splitAt (length $ view #change sel) addrsAvailable)

makeTx :: CoinSelection -> [Address] -> UnsignedTx input output change
makeTx :: CoinSelection -> [Address] -> UnsignedTx input output Void
makeTx sel addrsSelected = UnsignedTx
(NE.fromList (sel ^. #inputs))
(zipWith TxOut addrsSelected (sel ^. #change))
-- We never return any change:
[]

{-------------------------------------------------------------------------------
Expand Down

0 comments on commit 4dd0b28

Please sign in to comment.