Skip to content

Commit

Permalink
add endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Oct 26, 2020
1 parent 8cccce8 commit b835240
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 45 deletions.
9 changes: 9 additions & 0 deletions lib/core/src/Cardano/Wallet/Api.hs
Expand Up @@ -36,6 +36,7 @@ module Cardano.Wallet.Api
, Addresses
, ListAddresses
, InspectAddress
, PostScriptAddress

, CoinSelections
, SelectCoins
Expand Down Expand Up @@ -111,6 +112,8 @@ module Cardano.Wallet.Api

import Prelude

import Cardano.Address.Script
( Script )
import Cardano.Wallet
( WalletLayer (..), WalletLog )
import Cardano.Wallet.Api.Types
Expand Down Expand Up @@ -317,6 +320,7 @@ type SignMetadata = "wallets"
type Addresses n =
ListAddresses n
:<|> InspectAddress
:<|> PostScriptAddress n

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/listAddresses
type ListAddresses n = "wallets"
Expand All @@ -330,6 +334,11 @@ type InspectAddress = "addresses"
:> Capture "addressId" ApiAddressInspectData
:> Get '[JSON] ApiAddressInspect

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/postScriptAddress
type PostScriptAddress n = "addresses"
:> ReqBody '[JSON] (ApiT Script)
:> PostCreated '[JSON] (ApiAddressT n)

{-------------------------------------------------------------------------------
Coin Selections
Expand Down
2 changes: 2 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Client.hs
Expand Up @@ -317,6 +317,7 @@ addressClient =
let
_listAddresses
:<|> _inspectAddress
:<|> _postScriptAddress
= client (Proxy @("v2" :> Addresses Aeson.Value))
in
AddressClient
Expand All @@ -336,6 +337,7 @@ byronAddressClient
byronAddressClient =
let
_ :<|> _inspectAddress
:<|> _postScriptAddress
= client (Proxy @("v2" :> Addresses Aeson.Value))

_postRandomAddress
Expand Down
7 changes: 7 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -143,6 +143,8 @@ import Prelude

import Cardano.Address.Derivation
( XPrv, XPub, xpubFromBytes, xpubToBytes )
import Cardano.Address.Script
( Script )
import Cardano.Api.MetaData
( TxMetadataJsonSchema (..), metadataFromJson, metadataToJson )
import Cardano.Api.Typed
Expand Down Expand Up @@ -1311,6 +1313,11 @@ instance (PassphraseMaxLength purpose, PassphraseMinLength purpose)
instance ToJSON (ApiT (Passphrase purpose)) where
toJSON = toJSON . toText . getApiT

instance FromJSON (ApiT Script) where
parseJSON = fmap ApiT . parseJSON
instance ToJSON (ApiT Script) where
toJSON (ApiT script) = toJSON script

instance MkSomeMnemonic sizes => FromJSON (ApiMnemonicT sizes)
where
parseJSON bytes = do
Expand Down
Expand Up @@ -182,6 +182,7 @@ server byron icarus jormungandr spl ntp =
addresses :: Server (Addresses n)
addresses = listAddresses jormungandr (normalizeDelegationAddress @_ @JormungandrKey @n)
:<|> (\_ -> throwError err501)
:<|> (\_ -> throwError err501)

-- Hlint doesn't seem to care about inlining properties:
-- https://github.com/quchen/articles/blob/master/fbut.md#f-x---is-not-f--x---
Expand Down
1 change: 1 addition & 0 deletions lib/shelley/src/Cardano/Wallet/Shelley/Api/Server.hs
Expand Up @@ -201,6 +201,7 @@ server byron icarus shelley spl ntp =
addresses :: Server (Addresses n)
addresses = listAddresses shelley (normalizeDelegationAddress @_ @ShelleyKey @n)
:<|> (handler ApiAddressInspect . inspectAddress . unApiAddressInspectData)
:<|> (\_ -> throwError err501)
where
toServerError :: TextDecodingError -> ServerError
toServerError = apiError err400 BadRequest . T.pack . getTextDecodingError
Expand Down
90 changes: 45 additions & 45 deletions stack.yaml
Expand Up @@ -46,7 +46,7 @@ extra-deps:

# cardano-addresses-2.1.0
- git: https://github.com/input-output-hk/cardano-addresses
commit: e0ab4587266430a08734e1aec1c29d261a9a3b70
commit: 1399751501b03346265b2e429e5832bacd6df279
subdirs:
- command-line
- core
Expand Down Expand Up @@ -87,177 +87,177 @@ nix:
# package cardano-crypto
# tests: False
# benchmarks: False
#
#
# package contra-tracer
# tests: False
# benchmarks: False
#
#
# package iohk-monitoring
# tests: False
# benchmarks: False
#
#
# package zip
# tests: False
# benchmarks: False
#
#
# package cardano-crypto-praos
# tests: False
# benchmarks: False
#
#
# package byron-spec-ledger
# tests: False
# benchmarks: False
#
#
# package ouroboros-consensus-cardano
# tests: False
# benchmarks: False
#
#
# package small-steps
# tests: False
# benchmarks: False
#
#
# package small-steps-test
# tests: False
# benchmarks: False
#
#
# package ouroboros-consensus
# tests: False
# benchmarks: False
#
#
# package ouroboros-consensus-byron
# tests: False
# benchmarks: False
#
#
# package ouroboros-consensus-shelley
# tests: False
# benchmarks: False
#
#
# package ouroboros-consensus-mock
# tests: False
# benchmarks: False
#
#
# package cborg
# tests: False
# benchmarks: False
#
#
# package http-client
# tests: False
# benchmarks: False
#
#
# package goblins
# tests: False
# benchmarks: False
#
#
# package io-sim
# tests: False
# benchmarks: False
#
#
# package io-sim-classes
# tests: False
# benchmarks: False
#
#
# package shelley-spec-non-integral
# tests: False
# benchmarks: False
#
#
# package network-mux
# tests: False
# benchmarks: False
#
#
# package typed-protocols
# tests: False
# benchmarks: False
#
#
# package typed-protocols-examples
# tests: False
# benchmarks: False
#
#
# package cardano-prelude
# tests: False
# benchmarks: False
#
#
# package cardano-binary
# tests: False
# benchmarks: False
#
#
# package cardano-sl-x509
# tests: False
# benchmarks: False
#
#
# package cardano-crypto-class
# tests: False
# benchmarks: False
#
#
# package cardano-crypto-wrapper
# tests: False
# benchmarks: False
#
#
# package ouroboros-network-framework
# tests: False
# benchmarks: False
#
#
# package ouroboros-network
# tests: False
# benchmarks: False
#
#
# package byron-spec-chain
# tests: False
# benchmarks: False
#
#
# package cardano-addresses
# tests: False
# benchmarks: False
#
#
# package cardano-api
# tests: False
# benchmarks: False
#
#
# package cardano-cli
# tests: False
# benchmarks: False
#
#
# package cardano-crypto
# tests: False
# benchmarks: False
#
#
# package cardano-ledger
# tests: False
# benchmarks: False
#
#
# package cardano-node
# tests: False
# benchmarks: False
#
#
# package cardano-transactions
# tests: False
# benchmarks: False
#
#
# package lobemo-backend-monitoring
# tests: False
# benchmarks: False
#
#
# package ntp-client
# tests: False
# benchmarks: False
#
#
# package ouroboros-consensus-test-infra
# tests: False
# benchmarks: False
#
#
# package persistent
# tests: False
# benchmarks: False
#
#
# package persistent-sqlite
# tests: False
# benchmarks: False
#
#
# package persistent-template
# tests: False
# benchmarks: False
#
#
# package shelley-spec-ledger-test
# tests: False
# benchmarks: False
#
#
#+END_STACK2CABAL

0 comments on commit b835240

Please sign in to comment.