Skip to content

Commit

Permalink
slimming constraints in constructSharedTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Feb 8, 2023
1 parent 3ed4358 commit 92ed6a7
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs
Expand Up @@ -2776,23 +2776,17 @@ parseDelegationRequest (action :| otherActions) = except $
-- TO-DO withdrawals
-- TO-DO minting/burning
constructSharedTransaction
:: forall ctx s k n.
( k ~ SharedKey
, s ~ SharedState n k
, ctx ~ ApiLayer s k 'CredFromScriptK
, HasNetworkLayer IO ctx
, IsOurs s Address
, Typeable n
)
=> ctx
-> ArgGenChange s
:: forall (n :: NetworkDiscriminant)
. Typeable n
=> ApiLayer (SharedState n SharedKey) SharedKey 'CredFromScriptK
-> ArgGenChange (SharedState n SharedKey)
-> IO (Set PoolId)
-> (PoolId -> IO PoolLifeCycleStatus)
-> ApiT WalletId
-> ApiConstructTransactionData n
-> Handler (ApiConstructTransaction n)
constructSharedTransaction
ctx genChange knownPools poolStatus (ApiT wid) body = do
api genChange knownPools poolStatus (ApiT wid) body = do
let isNoPayload =
isNothing (body ^. #payments) &&
isNothing (body ^. #withdrawal) &&
Expand All @@ -2810,12 +2804,12 @@ constructSharedTransaction
delegationRequest <-
liftHandler $ traverse parseDelegationRequest $ body ^. #delegations

withWorkerCtx ctx wid liftE liftE $ \wrk -> do
withWorkerCtx api wid liftE liftE $ \wrk -> do
let db = wrk ^. dbLayer
netLayer = wrk ^. networkLayer
txLayer = wrk ^. transactionLayer @SharedKey @'CredFromScriptK
trWorker = MsgWallet >$< wrk ^. logger
epoch <- getCurrentEpoch ctx
epoch <- getCurrentEpoch api
era <- liftIO $ NW.currentNodeEra (wrk ^. networkLayer)
AnyRecentEra (_recentEra :: WriteTx.RecentEra era)
<- guardIsRecentEra era
Expand All @@ -2827,7 +2821,7 @@ constructSharedTransaction
poolStatus wid NoWithdrawal

(cp, _, _) <- liftHandler $ withExceptT ErrConstructTxNoSuchWallet $
W.readWallet @_ @s @k wrk wid
W.readWallet wrk wid
let txCtx = defaultTransactionCtx
{ txWithdrawal = NoWithdrawal
, txMetadata = md
Expand All @@ -2850,7 +2844,7 @@ constructSharedTransaction
txLayer netLayer db wid txCtx PreSelection {outputs = outs}

balancedTx <-
balanceTransaction ctx genChange scriptLookup
balanceTransaction api genChange scriptLookup
(Just (Shared.paymentTemplate $ getState cp)) (ApiT wid)
ApiBalanceTransactionPostData
{ transaction =
Expand All @@ -2860,8 +2854,7 @@ constructSharedTransaction
, encoding = body ^. #encoding
}

apiDecoded <-
decodeSharedTransaction @_ @s @k ctx (ApiT wid) balancedTx
apiDecoded <- decodeSharedTransaction api (ApiT wid) balancedTx

pure $ ApiConstructTransaction
{ transaction = balancedTx
Expand All @@ -2872,7 +2865,7 @@ constructSharedTransaction
}
where
ti :: TimeInterpreter (ExceptT PastHorizonException IO)
ti = timeInterpreter (ctx ^. networkLayer)
ti = timeInterpreter (api ^. networkLayer)

unsignedTx initialOuts decodedTx = UnsignedTx
{ unsignedCollateral =
Expand All @@ -2889,7 +2882,6 @@ constructSharedTransaction
[]
}


decodeSharedTransaction
:: forall ctx s k (n :: NetworkDiscriminant).
( ctx ~ ApiLayer s k 'CredFromScriptK
Expand Down

0 comments on commit 92ed6a7

Please sign in to comment.