Skip to content

Commit

Permalink
reuse getTransaction in shared context
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Nov 22, 2022
1 parent 349e6b1 commit b7ce49e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/wallet/api/http/Cardano/Wallet/Api.hs
Expand Up @@ -151,6 +151,7 @@ module Cardano.Wallet.Api
, SignSharedTransaction
, DecodeSharedTransaction
, SubmitSharedTransaction
, GetSharedTransaction

, GetBlocksLatestHeader
, Proxy_
Expand Down Expand Up @@ -1114,6 +1115,7 @@ type SharedTransactions n =
:<|> SignSharedTransaction n
:<|> DecodeSharedTransaction n
:<|> SubmitSharedTransaction
:<|> GetSharedTransaction n

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/constructSharedTransaction
type ConstructSharedTransaction n = "shared-wallets"
Expand Down Expand Up @@ -1143,6 +1145,14 @@ type SubmitSharedTransaction = "shared-wallets"
:> ReqBody '[JSON] ApiSerialisedTransaction
:> PostAccepted '[JSON] ApiTxId

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/getSharedTransaction
type GetSharedTransaction n = "shared-wallets"
:> Capture "walletId" (ApiT WalletId)
:> "transactions"
:> Capture "transactionId" ApiTxId
:> QueryFlag "simple-metadata"
:> Get '[JSON] (ApiTransactionT n)

{-------------------------------------------------------------------------------
Proxy_
Expand Down
5 changes: 5 additions & 0 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs
Expand Up @@ -614,6 +614,11 @@ server byron icarus shelley multisig spl ntp blockchainSource =
:<|> signTransaction @_ @_ @_ @'CredFromScriptK apilayer
:<|> decodeSharedTransaction apilayer
:<|> submitSharedTransaction @_ @_ @_ apilayer
:<|>
(\wid txId simpleMetadataFlag ->
getTransaction apilayer wid txId
(parseSimpleMetadataFlag simpleMetadataFlag)
)

blocks :: Handler ApiBlockHeader
blocks = getBlocksLatestHeader (shelley ^. networkLayer)
Expand Down
@@ -0,0 +1,53 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

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

module Cardano.Wallet.Api.Http.Server.Handlers.Certificates
( getApiAnyCertificates
)
where

import Cardano.Wallet.Api
( ApiLayer )
import Cardano.Wallet.Api.Http.Server.Error
( liftHandler )
import Cardano.Wallet.Api.Http.Server.Handlers.TxCBOR
( ParsedTxCBOR (..) )
import Cardano.Wallet.Api.Types.Certificate
( ApiAnyCertificate, mkApiAnyCertificate )
import Cardano.Wallet.Primitive.Types
( WalletId )
import Cardano.Wallet.Registry
( WorkerCtx )
import Data.Typeable
( Typeable )
import Prelude hiding
( (.) )
import Servant.Server
( Handler )

import qualified Cardano.Wallet as W

-- | Promote certificates of a transaction to API type,
-- using additional context from the 'WorkerCtx'.
getApiAnyCertificates
:: forall ctx s k ktype n.
( ctx ~ ApiLayer s k ktype
, Typeable s
, Typeable n
)
=> WorkerCtx ctx
-> WalletId
-> ParsedTxCBOR
-> Handler [ApiAnyCertificate n]
getApiAnyCertificates wrk wid ParsedTxCBOR{certificates} = do
(acct, _, acctPath) <-
liftHandler $ W.readRewardAccount @_ @s @k @n wrk wid
pure $ mkApiAnyCertificate acct acctPath <$> certificates
12 changes: 8 additions & 4 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs
Expand Up @@ -2130,10 +2130,10 @@ listTransactions
defaultSortOrder = Descending

getTransaction
:: forall s k n.
:: forall ctx s k ktype n.
( Typeable s
, Typeable n
, Typeable k
, ctx ~ ApiLayer s k ktype
, HasDelegation s
)
=> ApiLayer s k 'CredFromKeyK
Expand All @@ -2155,7 +2155,7 @@ getTransaction ctx (ApiT wid) (ApiTxId (ApiT (tid))) metadataSchema =
mkApiTransactionFromInfo
:: (Typeable s, Typeable n, HasDelegation s, Typeable k)
=> TimeInterpreter (ExceptT PastHorizonException IO)
-> W.WalletLayer IO s k 'CredFromKeyK
-> W.WalletLayer IO s k ktype
-> WalletId
-> Coin
-> TransactionInfo
Expand Down Expand Up @@ -4162,10 +4162,14 @@ data MkApiTransactionParams = MkApiTransactionParams
deriving (Eq, Generic, Show)

mkApiTransaction
<<<<<<< HEAD
:: forall n s k
. (Typeable s, Typeable n, Typeable k, HasDelegation s)
=======
:: forall n s k ktype . (Typeable s, Typeable n, HasDelegation s)
>>>>>>> 3410d992b (reuse getTransaction in shared context)
=> TimeInterpreter (ExceptT PastHorizonException IO)
-> W.WalletLayer IO s k 'CredFromKeyK
-> W.WalletLayer IO s k ktype
-> WalletId
-> Lens' (ApiTransaction n) (Maybe ApiBlockReference)
-> MkApiTransactionParams
Expand Down
7 changes: 7 additions & 0 deletions lib/wallet/src/Cardano/Wallet/Address/HasDelegation.hs
Expand Up @@ -14,12 +14,16 @@ import Prelude

import Cardano.Wallet.Primitive.AddressDerivation.Icarus
( IcarusKey )
import Cardano.Wallet.Primitive.AddressDerivation.SharedKey
( SharedKey )
import Cardano.Wallet.Primitive.AddressDerivation.Shelley
( ShelleyKey )
import Cardano.Wallet.Primitive.AddressDiscovery.Random
( RndState (..) )
import Cardano.Wallet.Primitive.AddressDiscovery.Sequential
( SeqState )
import Cardano.Wallet.Primitive.AddressDiscovery.Shared
( SharedState )

-- | Discriminate whether an address state supports delegation.
class HasDelegation s where
Expand All @@ -33,3 +37,6 @@ instance HasDelegation (RndState n) where

instance HasDelegation (SeqState n IcarusKey) where
hasDelegation _ = False

instance HasDelegation (SharedState n SharedKey) where
hasDelegation _ = False

0 comments on commit b7ce49e

Please sign in to comment.