From b7ce49e785990127a38003749b037ce3ab39648d Mon Sep 17 00:00:00 2001 From: Pawel Jakubas Date: Mon, 7 Nov 2022 13:52:56 +0100 Subject: [PATCH] reuse getTransaction in shared context --- lib/wallet/api/http/Cardano/Wallet/Api.hs | 10 ++++ .../http/Cardano/Wallet/Api/Http/Server.hs | 5 ++ .../Api/Http/Server/Handlers/Certificates.hs | 53 +++++++++++++++++++ .../Cardano/Wallet/Api/Http/Shelley/Server.hs | 12 +++-- .../Cardano/Wallet/Address/HasDelegation.hs | 7 +++ 5 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 lib/wallet/api/http/Cardano/Wallet/Api/Http/Server/Handlers/Certificates.hs diff --git a/lib/wallet/api/http/Cardano/Wallet/Api.hs b/lib/wallet/api/http/Cardano/Wallet/Api.hs index dc12ea6a372..1a6b490962a 100644 --- a/lib/wallet/api/http/Cardano/Wallet/Api.hs +++ b/lib/wallet/api/http/Cardano/Wallet/Api.hs @@ -151,6 +151,7 @@ module Cardano.Wallet.Api , SignSharedTransaction , DecodeSharedTransaction , SubmitSharedTransaction + , GetSharedTransaction , GetBlocksLatestHeader , Proxy_ @@ -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" @@ -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_ diff --git a/lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs b/lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs index 2390a3ac3f1..9e47ab7b571 100644 --- a/lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs +++ b/lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs @@ -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) diff --git a/lib/wallet/api/http/Cardano/Wallet/Api/Http/Server/Handlers/Certificates.hs b/lib/wallet/api/http/Cardano/Wallet/Api/Http/Server/Handlers/Certificates.hs new file mode 100644 index 00000000000..0d01e74bccd --- /dev/null +++ b/lib/wallet/api/http/Cardano/Wallet/Api/Http/Server/Handlers/Certificates.hs @@ -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 diff --git a/lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs b/lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs index 90418ac8d88..aeca5cb4fda 100644 --- a/lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs +++ b/lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs @@ -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 @@ -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 @@ -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 diff --git a/lib/wallet/src/Cardano/Wallet/Address/HasDelegation.hs b/lib/wallet/src/Cardano/Wallet/Address/HasDelegation.hs index a8ac920cf60..5056bdd5f16 100644 --- a/lib/wallet/src/Cardano/Wallet/Address/HasDelegation.hs +++ b/lib/wallet/src/Cardano/Wallet/Address/HasDelegation.hs @@ -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 @@ -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