Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Http-Bridge specifics into a dedicated package #212

Merged
merged 6 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 0 additions & 106 deletions lib/core/cardano-wallet-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,24 @@ library
hs-source-dirs:
src
exposed-modules:
Cardano.Environment
Cardano.Wallet
Cardano.Wallet.Compatibility
Cardano.Wallet.Api
Cardano.Wallet.Api.Server
Cardano.Wallet.Api.Types
Cardano.Wallet.Binary
Cardano.Wallet.Binary.Packfile
Cardano.Wallet.CoinSelection
Cardano.Wallet.CoinSelection.Fee
Cardano.Wallet.CoinSelection.Policy.LargestFirst
Cardano.Wallet.CoinSelection.Policy.Random
Cardano.Wallet.DB
Cardano.Wallet.DB.MVar
Cardano.Wallet.Network
Cardano.Wallet.Network.HttpBridge
Cardano.Wallet.Network.HttpBridge.Api
Cardano.Wallet.Primitive.AddressDerivation
Cardano.Wallet.Primitive.AddressDiscovery
Cardano.Wallet.Primitive.Mnemonic
Cardano.Wallet.Primitive.Model
Cardano.Wallet.Primitive.Types
Cardano.Wallet.Transaction
Cardano.Wallet.Transaction.HttpBridge
Data.Quantity
Servant.Extra.ContentTypes
other-modules:
Paths_cardano_wallet_core

Expand Down Expand Up @@ -143,118 +135,20 @@ test-suite unit
main-is:
Main.hs
other-modules:
Cardano.EnvironmentSpec
Cardano.Wallet.Api.TypesSpec
Cardano.Wallet.ApiSpec
Cardano.Wallet.Binary.PackfileSpec
Cardano.Wallet.BinarySpec
Cardano.Wallet.CoinSelection.FeeSpec
Cardano.Wallet.CoinSelection.Policy.LargestFirstSpec
Cardano.Wallet.CoinSelection.Policy.RandomSpec
Cardano.Wallet.CoinSelectionSpec
Cardano.Wallet.DB.MVarSpec
Cardano.Wallet.DBSpec
Cardano.Wallet.Network.HttpBridge.ApiSpec
Cardano.Wallet.Network.HttpBridgeSpec
Cardano.Wallet.NetworkSpec
Cardano.Wallet.Primitive.AddressDerivationSpec
Cardano.Wallet.Primitive.AddressDiscoverySpec
Cardano.Wallet.Primitive.MnemonicSpec
Cardano.Wallet.Primitive.ModelSpec
Cardano.Wallet.Primitive.TypesSpec
Cardano.Wallet.Primitive.SigningSpec
Cardano.WalletSpec
Data.QuantitySpec
Servant.Extra.ContentTypesSpec
Spec

test-suite integration
default-language:
Haskell2010
default-extensions:
NoImplicitPrelude
OverloadedStrings
ghc-options:
-threaded -rtsopts
-Wall
-O2
if (!flag(development))
ghc-options:
-Werror
build-depends:
base
, aeson
, aeson-qq
, async
, bytestring
, cardano-wallet-core
, cardano-wallet-launcher
, cborg
, cryptonite
, exceptions
, generic-lens
, hspec
, hspec-core
, hspec-expectations-lifted
, http-client
, http-api-data
, http-types
, process
, template-haskell
, text
, text-class
, time
, transformers
type:
exitcode-stdio-1.0
hs-source-dirs:
test/integration
main-is:
Main.hs
other-modules:
Cardano.WalletSpec
Cardano.Wallet.Network.HttpBridgeSpec
Test.Integration.Framework.DSL
Test.Integration.Framework.Request
Test.Integration.Scenario.Wallets

benchmark restore
default-language:
Haskell2010
default-extensions:
NoImplicitPrelude
OverloadedStrings
ghc-options:
-threaded -rtsopts
-Wall
-O2
if (!flag(development))
ghc-options:
-Werror
build-depends:
base
, async
, bytestring
, cardano-wallet-core
, cardano-wallet-launcher
, containers
, criterion-measurement
, cryptonite
, deepseq
, digest
, fmt
, generic-lens
, process
, say
, text
, text-class
, time
, transformers
type:
exitcode-stdio-1.0
hs-source-dirs:
test/bench
main-is:
Main.hs
other-modules:
Cardano.Wallet.Primitive.AddressDiscovery.Any
6 changes: 1 addition & 5 deletions lib/core/src/Cardano/Wallet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ module Cardano.Wallet

import Prelude

import Cardano.Wallet.Binary
( encodeSignedTx, toByteString )
import Cardano.Wallet.CoinSelection
( CoinSelection (..)
, CoinSelectionError (..)
Expand Down Expand Up @@ -81,7 +79,6 @@ import Cardano.Wallet.Primitive.Types
( Block (..)
, Coin (..)
, Direction (..)
, SignedTx (..)
, SlotId (..)
, Tx
, TxId (..)
Expand Down Expand Up @@ -319,8 +316,7 @@ mkWalletLayer db nw tl = WalletLayer
throwE $ ErrSignTx e

, submitTx = \wid (tx, meta, wit) -> do
let signed = SignedTx $ toByteString $ encodeSignedTx (tx, wit)
withExceptT ErrSubmitTxNetwork $ postTx nw signed
withExceptT ErrSubmitTxNetwork $ postTx nw (tx, wit)
DB.withLock db $ withExceptT ErrSubmitTxNoSuchWallet $ do
(w, _) <- _readWallet wid
let history = Map.fromList [(txId @t tx, (tx, meta))]
Expand Down
21 changes: 19 additions & 2 deletions lib/core/src/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ import Cardano.Wallet.Api.Types
)
import Cardano.Wallet.Primitive.Types
( AddressState, WalletId )
import Data.List.NonEmpty
( NonEmpty ((:|)) )
import Network.HTTP.Media
( (//), (/:) )
import Servant.API
( (:<|>)
, (:>)
, Accept (..)
, Capture
, DeleteNoContent
, Get
Expand All @@ -28,8 +33,6 @@ import Servant.API
, QueryParam
, ReqBody
)
import Servant.Extra.ContentTypes
( Any )

type Api = Addresses :<|> Wallets :<|> Transactions

Expand Down Expand Up @@ -109,3 +112,17 @@ type CreateTransaction = "wallets"
:> "transactions"
:> ReqBody '[JSON] PostTransactionData
:> PostAccepted '[JSON] ApiTransaction

{-------------------------------------------------------------------------------
Internals
-------------------------------------------------------------------------------}

-- | Any media type
data Any

instance Accept Any where
contentTypes _ = ("*" // "*") :|
-- We also 'conveniently' accept JSON format
[ "application" // "json"
, "application" // "json" /: ("charset", "utf-8")
]
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Cardano.Wallet.Network
import Prelude

import Cardano.Wallet.Primitive.Types
( Block (..), BlockHeader (..), Hash (..), SignedTx, SlotId (..) )
( Block (..), BlockHeader (..), Hash (..), SlotId (..), Tx, TxWitness )
import Control.Exception
( Exception )
import Control.Monad.Trans.Except
Expand All @@ -40,7 +40,7 @@ data NetworkLayer m = NetworkLayer
-- ^ Get the current network tip from the chain producer

, postTx
:: SignedTx -> ExceptT ErrPostTx m ()
:: (Tx, [TxWitness]) -> ExceptT ErrPostTx m ()
-- ^ Broadcast a transaction to the chain producer
}

Expand Down
5 changes: 0 additions & 5 deletions lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ module Cardano.Wallet.Primitive.Types
, TxMeta(..)
, Direction(..)
, TxStatus(..)
, SignedTx (..)
, TxWitness (..)
, txIns

Expand Down Expand Up @@ -412,10 +411,6 @@ instance Buildable Direction where
Outgoing -> "outgoing"
Incoming -> "incoming"

-- | Wrapper around the final CBOR representation of a signed tx
newtype SignedTx = SignedTx { signedTx :: ByteString }
deriving (Show, Eq, Generic)

data TxWitness
= PublicKeyWitness ByteString (Hash "signature")
| ScriptWitness ByteString
Expand Down
1 change: 1 addition & 0 deletions lib/http-bridge/LICENSE
1 change: 1 addition & 0 deletions lib/http-bridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Http-Bridge
Loading