Skip to content

Commit

Permalink
Merge #3577
Browse files Browse the repository at this point in the history
3577: Get/list shared txs r=Anviking a=paweljakubas

<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
   ✓ Self-review your changes to make sure nothing unexpected slipped through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->


- [x] Updated get/list shared tx in swagger
- [x] Adding plumbing in api scaffolding layer, link, reusing between shelley and shared modes
- [x] adding integration tests

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number
adp-2224

<!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->


Co-authored-by: Pawel Jakubas <[email protected]>
  • Loading branch information
iohk-bors[bot] and paweljakubas authored Nov 22, 2022
2 parents 3ec6256 + 7c74755 commit 999e7e1
Show file tree
Hide file tree
Showing 8 changed files with 894 additions and 20 deletions.
23 changes: 23 additions & 0 deletions lib/wallet/api/http/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ module Cardano.Wallet.Api
, SignSharedTransaction
, DecodeSharedTransaction
, SubmitSharedTransaction
, GetSharedTransaction
, ListSharedTransactions

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

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/constructSharedTransaction
type ConstructSharedTransaction n = "shared-wallets"
Expand Down Expand Up @@ -1143,6 +1147,25 @@ 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)

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/listSharedTransactions
type ListSharedTransactions n = "shared-wallets"
:> Capture "walletId" (ApiT WalletId)
:> "transactions"
:> QueryParam "minWithdrawal" MinWithdrawal
:> QueryParam "start" Iso8601Time
:> QueryParam "end" Iso8601Time
:> QueryParam "order" (ApiT SortOrder)
:> QueryFlag "simple-metadata"
:> Get '[JSON] [ApiTransactionT n]

{-------------------------------------------------------------------------------
Proxy_
Expand Down
10 changes: 10 additions & 0 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,16 @@ server byron icarus shelley multisig spl ntp blockchainSource =
:<|> signTransaction @_ @_ @_ @'CredFromScriptK apilayer
:<|> decodeSharedTransaction apilayer
:<|> submitSharedTransaction @_ @_ @_ apilayer
:<|>
(\wid txId simpleMetadataFlag ->
getTransaction apilayer wid txId
(parseSimpleMetadataFlag simpleMetadataFlag)
)
:<|>
(\wid mMinWithdrawal mStart mEnd mOrder simpleMetadataFlag ->
listTransactions apilayer wid mMinWithdrawal mStart mEnd mOrder
(parseSimpleMetadataFlag simpleMetadataFlag)
)

blocks :: Handler ApiBlockHeader
blocks = getBlocksLatestHeader (shelley ^. networkLayer)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
19 changes: 11 additions & 8 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Shelley/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2093,13 +2093,13 @@ deleteTransaction ctx (ApiT wid) (ApiTxId (ApiT (tid))) = do
return NoContent

listTransactions
:: forall s k n.
:: forall s k ktype n.
( Typeable s
, Typeable n
, HasDelegation s
, Typeable k
)
=> ApiLayer s k 'CredFromKeyK
=> ApiLayer s k ktype
-> ApiT WalletId
-> Maybe MinWithdrawal
-> Maybe Iso8601Time
Expand Down Expand Up @@ -2130,13 +2130,13 @@ listTransactions
defaultSortOrder = Descending

getTransaction
:: forall s k n.
:: forall s k ktype n.
( Typeable s
, Typeable n
, Typeable k
, HasDelegation s
)
=> ApiLayer s k 'CredFromKeyK
=> ApiLayer s k ktype
-> ApiT WalletId
-> ApiTxId
-> TxMetadataSchema
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,13 @@ data MkApiTransactionParams = MkApiTransactionParams
deriving (Eq, Generic, Show)

mkApiTransaction
:: forall n s k
. (Typeable s, Typeable n, Typeable k, HasDelegation s)
:: forall n s k ktype.
( Typeable s
, Typeable n
, Typeable k
, HasDelegation s)
=> 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
19 changes: 13 additions & 6 deletions lib/wallet/api/http/Cardano/Wallet/Api/Link.hs
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,7 @@ listTransactions w =

listTransactions'
:: forall (style :: WalletStyle) w.
( HasCallStack
, Discriminate style
( Discriminate style
, HasType (ApiT WalletId) w
)
=> w
Expand All @@ -639,7 +638,16 @@ listTransactions' w minWithdrawal inf sup order = discriminate @style
)
(endpoint @(Api.ListByronTransactions Net)
(\mk -> mk wid inf sup (ApiT <$> order)))
(notSupported "Shared")
(endpoint @(Api.ListSharedTransactions Net)
(\mk -> mk
wid
(MinWithdrawal <$> minWithdrawal)
inf
sup
(ApiT <$> order)
(toSimpleMetadataFlag TxMetadataDetailedSchema)
)
)
where
wid = w ^. typed @(ApiT WalletId)

Expand Down Expand Up @@ -679,8 +687,7 @@ deleteTransaction w t = discriminate @style

getTransaction
:: forall (style :: WalletStyle) w t.
( HasCallStack
, Discriminate style
( Discriminate style
, HasType (ApiT WalletId) w
, HasType (ApiT (Hash "Tx")) t
)
Expand All @@ -690,7 +697,7 @@ getTransaction
getTransaction w t = discriminate @style
(endpoint @(Api.GetTransaction Net) mkShelleyURL)
(endpoint @(Api.GetByronTransaction Net) mkByronURL)
(notSupported "Shared")
(endpoint @(Api.GetSharedTransaction Net) mkShelleyURL)
where
wid = w ^. typed @(ApiT WalletId)
tid = ApiTxId (t ^. typed @(ApiT (Hash "Tx")))
Expand Down
Loading

0 comments on commit 999e7e1

Please sign in to comment.