cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2018-2020 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Wallet.Api.Server

Description

API handlers and server using the underlying wallet layer to provide endpoints reachable through HTTP.

Synopsis

Server Configuration

data Listen Source #

How the server should listen for incoming requests.

Constructors

ListenOnPort Port

Listen on given TCP port

ListenOnRandomPort

Listen on an unused TCP port, selected at random

data HostPreference Source #

Which host to bind.

Note: The IsString instance recognizes the following special values:

  • * means HostAny - "any IPv4 or IPv6 hostname"
  • *4 means HostIPv4 - "any IPv4 or IPv6 hostname, IPv4 preferred"
  • !4 means HostIPv4Only - "any IPv4 hostname"
  • *6 means HostIPv6 @ - "any IPv4 or IPv6 hostname, IPv6 preferred"
  • !6 means HostIPv6Only - "any IPv6 hostname"

Note that the permissive * values allow binding to an IPv4 or an IPv6 hostname, which means you might be able to successfully bind to a port more times than you expect (eg once on the IPv4 localhost 127.0.0.1 and again on the IPv6 localhost 0:0:0:0:0:0:0:1).

Any other value is treated as a hostname. As an example, to bind to the IPv4 local host only, use "127.0.0.1".

Server Setup

start :: Settings -> Tracer IO ApiLog -> Maybe TlsConfiguration -> Socket -> Application -> IO () Source #

Start the application server, using the given settings and a bound socket.

serve :: HasServer api ('[] :: [ Type ]) => Proxy api -> Server api -> Application Source #

serve allows you to implement an API and produce a wai Application .

Example:

type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
        :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book -- POST /books

server :: Server MyApi
server = listAllBooks :<|> postBook
  where listAllBooks = ...
        postBook book = ...

myApi :: Proxy MyApi
myApi = Proxy

app :: Application
app = serve myApi server

main :: IO ()
main = Network.Wai.Handler.Warp.run 8080 app

withListeningSocket Source #

Arguments

:: HostPreference

Which host to bind.

-> Listen

Whether to listen on a given port, or random port.

-> ( Either ListenError ( Port , Socket ) -> IO a)

Action to run with listening socket.

-> IO a

Run an action with a TCP socket bound to a port specified by the Listen parameter.

ApiLayer

Handlers

getWallet :: forall ctx s k apiWallet. (ctx ~ ApiLayer s k, HasWorkerRegistry s k ctx, HasDBFactory s k ctx) => ctx -> MkApiWallet ctx s apiWallet -> ApiT WalletId -> Handler (apiWallet, UTCTime ) Source #

listAssets :: forall ctx s k. (ctx ~ ApiLayer s k, IsOurs s Address , HasTokenMetadataClient ctx) => ctx -> ApiT WalletId -> Handler [ ApiAsset ] Source #

All assets associated with this wallet, and their metadata (if metadata is available). This list may include assets which have already been spent.

getAsset :: forall ctx s k. (ctx ~ ApiLayer s k, IsOurs s Address , HasTokenMetadataClient ctx) => ctx -> ApiT WalletId -> ApiT TokenPolicyId -> ApiT TokenName -> Handler ApiAsset Source #

Look up a single asset and its metadata.

NOTE: This is slightly inefficient because it greps through the transaction history to check if the asset is associated with this wallet.

listWallets :: forall ctx s k apiWallet. (ctx ~ ApiLayer s k, NFData apiWallet) => ctx -> MkApiWallet ctx s apiWallet -> Handler [(apiWallet, UTCTime )] Source #

postRandomWallet :: forall ctx s k n. (ctx ~ ApiLayer s k, s ~ RndState n, k ~ ByronKey ) => ctx -> ByronWalletPostData '[12, 15, 18, 21, 24] -> Handler ApiByronWallet Source #

putWallet :: forall ctx s k apiWallet. ctx ~ ApiLayer s k => ctx -> MkApiWallet ctx s apiWallet -> ApiT WalletId -> WalletPutData -> Handler apiWallet Source #

mkSharedWallet :: forall ctx s k n. (ctx ~ ApiLayer s k, s ~ SharedState n k, HasWorkerRegistry s k ctx, SupportsDiscovery n k) => MkApiWallet ctx s ApiSharedWallet Source #

Server error responses

class IsServerError e where Source #

Maps types to servant error responses.

Methods

toServerError :: e -> ServerError Source #

A structured human-readable error code to return to API clients.

Instances

Instances details
IsServerError PastHorizonException Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrUpdateSealedTx Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrCannotQuit Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrCannotJoin Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrSignTx Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrAssignRedeemers Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrMkTransaction Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrPostTx Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrNoSuchWallet Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrWalletAlreadyExists Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrNoSuchTransaction Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrRemoveTx Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrWritePolicyPublicKey Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrReadPolicyPublicKey Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrWithdrawalNotWorth Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrReadRewardAccount Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrNotASequentialWallet Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrImportRandomAddress Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrCreateRandomAddress Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrWalletNotResponding Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrFetchRewards Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrStakePoolDelegation Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrSelectAssets Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrCreateMigrationPlan Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrStartTimeLaterThanEndTime Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrGetTransaction Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrListTransactions Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrWithRootKey Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrUpdatePassphrase Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrSubmitTx Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrDecodeTx Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrWitnessTx Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrGetPolicyId Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrConstructTx Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrSubmitTransaction Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrBalanceTx Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrSignPayment Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrListUTxOStatistics Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrReadAccountPublicKey Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrConstructSharedWallet Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrAddCosignerKey Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrDerivePublicKey Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ErrSignMetadataWith Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ( SelectionBalanceError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ( SelectionOutputTokenQuantityExceedsLimitError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ( SelectionOutputSizeExceedsLimitError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ( SelectionOutputError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ( SelectionOutputCoinInsufficientError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ( SelectionCollateralError WalletSelectionContext ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ( Request , ServerError ) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ( ErrInvalidDerivationIndex ' Hardened level) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

IsServerError ( ErrInvalidDerivationIndex ' Soft level) Source #
Instance details

Defined in Cardano.Wallet.Api.Server

liftHandler :: IsServerError e => ExceptT e IO a -> Handler a Source #

Lift our wallet layer into servant Handler , by mapping each error to a corresponding servant error.

Internals

withLegacyLayer' :: forall byron icarus n a. (byron ~ ApiLayer ( RndState n) ByronKey , icarus ~ ApiLayer ( SeqState n IcarusKey ) IcarusKey ) => ApiT WalletId -> (byron, Handler a, ErrWalletNotResponding -> Handler a) -> (icarus, Handler a, ErrWalletNotResponding -> Handler a) -> Handler a Source #

Like withLegacyLayer but allow passing a custom handler for handling dead workers.

rndStateChange :: forall ctx s k n. (ctx ~ ApiLayer s k, s ~ RndState n, k ~ ByronKey ) => ctx -> ApiT WalletId -> Passphrase "user" -> Handler ( ArgGenChange s) Source #

Handler for fetching the ArgGenChange for the RndState (i.e. the root XPrv), necessary to derive new change addresses.

withWorkerCtx Source #

Arguments

:: forall ctx s k m a. ( HasWorkerRegistry s k ctx, HasDBFactory s k ctx, MonadIO m)
=> ctx

A context that has a registry

-> WalletId

Wallet to look for

-> ( ErrNoSuchWallet -> m a)

Wallet not present, handle error

-> ( ErrWalletNotResponding -> m a)

Wallet worker is dead, handle error

-> ( WorkerCtx ctx -> m a)

Do something with the wallet

-> m a

Run an action in a particular worker context. Fails if there's no worker for a given id.

Workers

idleWorker :: ctx -> wid -> IO a Source #

Something to pass as the coworker action to newApiLayer , which does nothing, and never exits.

Logging