Skip to content

Commit

Permalink
make it compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed May 5, 2021
1 parent 5a9701c commit 1ac9f2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import Cardano.Wallet.Primitive.AddressDerivation
, SoftDerivation (..)
, ToRewardAccount (..)
)
import Cardano.Wallet.Primitive.Types.Address
( Address )
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..) )
import Cardano.Wallet.Primitive.Types.RewardAccount
Expand All @@ -62,11 +64,15 @@ import Control.DeepSeq
( NFData )
import Data.List.NonEmpty
( NonEmpty )
import Data.Maybe
( maybeToList )
import GHC.Generics
( Generic )
import Quiet
( Quiet (..) )

import qualified Cardano.Wallet.Primitive.Types.TokenBundle as TB

--------------------------------------------------------------------------------
-- Delegation State
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -196,14 +202,21 @@ data Cert
setPortfolioOf
:: (SoftDerivation k, ToRewardAccount k)
=> DelegationState k
-> (k 'AddressK XPub -> Address)
-> (RewardAccount -> Bool) -- TODO: Need a Set or Map for the real implementation with LSQ
-> Int
-> Maybe Tx
setPortfolioOf s isReg n =
setPortfolioOf s mkAddress isReg n =
let s' = s { nextKeyIx = toEnum n }
mkTxIn (PointerUTxO i c _) = (i, c)
pointerIn = maybe [] (\x -> [x]) (mkTxIn <$> pointer s)
pointerOut = [] -- TODO

-- TODO: What if the minUTxOValue changes? We should use it in the
-- output here.
mkTxOut (PointerUTxO _i c ix) =
TxOut (mkAddress $ keyAtIx s ix) (TB.fromCoin c)

pointerIn = maybeToList (mkTxIn <$> pointer s)
pointerOut = maybeToList (mkTxOut <$> pointer s)
-- TODO: Does this actually make sense?
in
case compare (toEnum n) (nextKeyIx s) of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import Cardano.Wallet.Primitive.AddressDerivation
, ToRewardAccount (..)
)
import Cardano.Wallet.Primitive.AddressDiscovery.Delegation
import Cardano.Wallet.Primitive.Types.Address
( Address (..) )
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..) )
import Cardano.Wallet.Primitive.Types.Hash
Expand Down Expand Up @@ -314,7 +316,7 @@ applyCmds = second reverse . foldl step ((s0, initialLedger), [])
where
-- TODO: Would be nice to have some abstraction to remove the boilerplate
-- here. Maybe StateT or some Foldable thing.
step ((s, l), accTxs) (CmdSetPortfolioOf n) = case setPortfolioOf s (acctIsReg l) n of
step ((s, l), accTxs) (CmdSetPortfolioOf n) = case setPortfolioOf s mkAddr (acctIsReg l) n of
Just tx -> ((applyTx tx s, applyLedger' tx l), tx:accTxs)
Nothing -> ((s, l), accTxs)
step ((s,l), accTxs) (CmdAdversarialReg k) =
Expand All @@ -329,6 +331,7 @@ applyCmds = second reverse . foldl step ((s0, initialLedger), [])

s0 = initialDelegationState accK
applyLedger' tx l = either (error . show) id $ applyLedger [tx] l
mkAddr k = Address $ "addr" <> unRewardAccount (toRewardAccount k)

--
-- Mock ledger
Expand Down

0 comments on commit 1ac9f2b

Please sign in to comment.