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

Withdrawals as part of core and API transactions #1892

Merged
merged 11 commits into from
Jul 10, 2020
Merged
4 changes: 3 additions & 1 deletion lib/byron/src/Cardano/Wallet/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import Cardano.Wallet.Api
import Cardano.Wallet.Api.Server
( HostPreference, Listen (..), ListenError (..), TlsConfiguration )
import Cardano.Wallet.Api.Types
( ApiStakePool, DecodeAddress, EncodeAddress )
( ApiStakePool, DecodeAddress, EncodeAddress, EncodeStakeAddress )
import Cardano.Wallet.Byron.Api.Server
( server )
import Cardano.Wallet.Byron.Compatibility
Expand Down Expand Up @@ -157,6 +157,7 @@ data SomeNetworkDiscriminant where
, PaymentAddress n ByronKey
, DecodeAddress n
, EncodeAddress n
, EncodeStakeAddress n
, MaxSizeOf Address n IcarusKey
, MaxSizeOf Address n ByronKey
)
Expand Down Expand Up @@ -242,6 +243,7 @@ serveWallet
, PaymentAddress n ByronKey
, DecodeAddress n
, EncodeAddress n
, EncodeStakeAddress n
)
=> Proxy n
-> Socket
Expand Down
6 changes: 3 additions & 3 deletions lib/byron/src/Cardano/Wallet/Byron/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ server byron icarus ntp =
transactions :: Server (Transactions n)
transactions =
(\_ _ _ -> throwError err501)
:<|> (\_ _ _ _ -> throwError err501)
:<|> (\_ _ _ _ _ -> throwError err501)
:<|> (\_ _ _ -> throwError err501)
:<|> (\_ _ -> throwError err501)
:<|> (\_ _ -> throwError err501)
Expand Down Expand Up @@ -246,8 +246,8 @@ server byron icarus ntp =
)
:<|>
(\wid r0 r1 s -> withLegacyLayer wid
(byron , listTransactions byron wid r0 r1 s)
(icarus, listTransactions icarus wid r0 r1 s)
(byron , listTransactions byron wid Nothing r0 r1 s)
(icarus, listTransactions icarus wid Nothing r0 r1 s)
)
:<|>
(\wid tx -> withLegacyLayer wid
Expand Down
18 changes: 17 additions & 1 deletion lib/byron/src/Cardano/Wallet/Byron/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
Expand Down Expand Up @@ -86,7 +87,11 @@ import Cardano.Crypto
import Cardano.Crypto.ProtocolMagic
( ProtocolMagicId, unProtocolMagicId )
import Cardano.Wallet.Api.Types
( DecodeAddress (..), EncodeAddress (..) )
( DecodeAddress (..)
, DecodeStakeAddress (..)
, EncodeAddress (..)
, EncodeStakeAddress (..)
)
import Cardano.Wallet.Primitive.AddressDerivation
( NetworkDiscriminant (..) )
import Cardano.Wallet.Primitive.AddressDerivation.Byron
Expand Down Expand Up @@ -355,6 +360,9 @@ fromTxAux txAux = case taTx txAux of

, outputs =
fromTxOut <$> NE.toList outputs

, withdrawals =
mempty
}

fromTxIn :: TxIn -> W.TxIn
Expand Down Expand Up @@ -496,6 +504,14 @@ fromProtocolMagicId = W.ProtocolMagic . fromIntegral . unProtocolMagicId
Address Encoding / Decoding
-------------------------------------------------------------------------------}

instance {-# OVERLAPS #-} EncodeStakeAddress n where
encodeStakeAddress = error
"encodeStakeAddress: there's no such thing as stake address in Byron"

instance {-# OVERLAPS #-} DecodeStakeAddress n where
decodeStakeAddress = error
"decodeStakeAddress: there's no such thing as stake address in Byron"

instance EncodeAddress 'Mainnet where
encodeAddress =
gEncodeAddress
Expand Down
1 change: 1 addition & 0 deletions lib/byron/src/Cardano/Wallet/Byron/Launch.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
Expand Down
5 changes: 3 additions & 2 deletions lib/byron/src/Cardano/Wallet/Byron/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ newTransactionLayer _proxy protocolMagic = TransactionLayer
witnesses <- forM (CS.inputs cs) $ \(_, TxOut addr _) ->
mkWitness protocolMagic sigData <$> lookupPrivateKey addr
pure
( Tx (Hash sigData) (second coin <$> CS.inputs cs) (CS.outputs cs)
( Tx (Hash sigData) (second coin <$> CS.inputs cs) (CS.outputs cs) mempty
, SealedTx $ CBOR.toStrictByteString $ CBOR.encodeSignedTx tx witnesses
)
where
Expand Down Expand Up @@ -190,6 +190,7 @@ newTransactionLayer _proxy protocolMagic = TransactionLayer
-- FIXME Do not require Tx to have resolvedInputs
, resolvedInputs = (,Coin 0) <$> inps
, outputs = outs
, withdrawals = mempty
}
, SealedTx bytes
)
Expand Down Expand Up @@ -243,7 +244,7 @@ genesisBlockFromTxOuts gp outs = Block
}
where
mkTx out@(TxOut (Address bytes) _) =
Tx (Hash $ blake2b256 bytes) [] [out]
Tx (Hash $ blake2b256 bytes) [] [out] mempty

dummyAddress
:: forall (n :: NetworkDiscriminant). (MaxSizeOf Address n ByronKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Cardano.Wallet.Api.Types
, ApiTransaction
, ApiWalletMigrationInfo
, DecodeAddress (..)
, DecodeStakeAddress (..)
, EncodeAddress (..)
, WalletStyle (..)
)
Expand Down Expand Up @@ -68,6 +69,7 @@ spec
, PaymentAddress n ByronKey
, EncodeAddress n
, DecodeAddress n
, DecodeStakeAddress n
)
=> SpecWith (Context t)
spec = do
Expand All @@ -87,6 +89,7 @@ spec = do
scenario_MIGRATE_01
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand All @@ -107,6 +110,7 @@ scenario_MIGRATE_01 fixtureSource = it title $ \ctx -> do
scenario_MIGRATE_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Cardano.Wallet.Api.Types
, ApiTxId (ApiTxId)
, ApiUtxoStatistics
, DecodeAddress (..)
, DecodeStakeAddress (..)
, EncodeAddress (..)
, Iso8601Time (..)
, WalletStyle (..)
Expand Down Expand Up @@ -110,6 +111,7 @@ spec
, PaymentAddress n ByronKey
, EncodeAddress n
, DecodeAddress n
, DecodeStakeAddress n
)
=> SpecWith (Context t)
spec = do
Expand Down Expand Up @@ -175,6 +177,7 @@ spec = do
scenario_TRANS_CREATE_01_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO ApiByronWallet)
Expand Down Expand Up @@ -260,6 +263,7 @@ scenario_TRANS_CREATE_01_02 fixtureSource fixtures = it title $ \ctx -> do
scenario_TRANS_ESTIMATE_01_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO ApiByronWallet)
Expand Down Expand Up @@ -292,6 +296,7 @@ scenario_TRANS_ESTIMATE_01_02 fixtureSource fixtures = it title $ \ctx -> do
scenario_TRANS_CREATE_04b
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -314,6 +319,7 @@ scenario_TRANS_CREATE_04b = it title $ \ctx -> do
scenario_TRANS_CREATE_04c
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -336,6 +342,7 @@ scenario_TRANS_CREATE_04c = it title $ \ctx -> do
scenario_TRANS_CREATE_04d
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -358,6 +365,7 @@ scenario_TRANS_CREATE_04d = it title $ \ctx -> do
scenario_TRANS_ESTIMATE_04b
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand Down Expand Up @@ -385,6 +393,7 @@ scenario_TRANS_ESTIMATE_04b = it title $ \ctx -> do
scenario_TRANS_ESTIMATE_04c
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -407,6 +416,7 @@ scenario_TRANS_ESTIMATE_04c = it title $ \ctx -> do
scenario_TRANS_CREATE_07
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand All @@ -429,6 +439,7 @@ scenario_TRANS_CREATE_07 = it title $ \ctx -> do
scenario_RESTORE_01
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand Down Expand Up @@ -506,6 +517,7 @@ scenario_RESTORE_01 fixtureSource = it title $ \ctx -> do
scenario_RESTORE_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO (ApiByronWallet, [Address]))
Expand Down Expand Up @@ -563,6 +575,7 @@ scenario_RESTORE_02 fixtureTarget = it title $ \ctx -> do
scenario_RESTORE_03
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO (ApiByronWallet, [Address]))
Expand Down Expand Up @@ -603,6 +616,7 @@ scenario_RESTORE_03 fixtureTarget = it title $ \ctx -> do
scenario_TRANS_UTXO_01
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO ApiByronWallet)
Expand Down Expand Up @@ -648,6 +662,7 @@ scenario_TRANS_UTXO_01 fixtureSource fixtureTarget = it title $ \ctx -> do
scenario_TRANS_REG_1670
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand Down Expand Up @@ -698,12 +713,12 @@ scenario_TRANS_REG_1670 fixture = it title $ \ctx -> do

-- ACTION
rTxsFromDate <- request @[ApiTransaction n] ctx
(Link.listTransactions' @'Byron wSrc (Just start) Nothing Nothing)
(Link.listTransactions' @'Byron wSrc Nothing (Just start) Nothing Nothing)
Default
Empty

rTxsAll <- request @[ApiTransaction n] ctx
(Link.listTransactions' @'Byron wSrc Nothing Nothing Nothing)
(Link.listTransactions' @'Byron wSrc Nothing Nothing Nothing Nothing)
Default
Empty

Expand All @@ -725,6 +740,7 @@ scenario_TRANS_REG_1670 fixture = it title $ \ctx -> do
verifyTxInputsAndOutputs
:: forall (d :: NetworkDiscriminant).
( DecodeAddress d
, DecodeStakeAddress d
, EncodeAddress d
, PaymentAddress d IcarusKey
)
Expand All @@ -749,6 +765,7 @@ scenario_TRANS_REG_1670 fixture = it title $ \ctx -> do
fixtureCantCoverFee
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -766,6 +783,7 @@ fixtureCantCoverFee ctx = do
fixtureNotEnoughMoney
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -782,6 +800,7 @@ fixtureNotEnoughMoney ctx = do
fixtureWrongPassphrase
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -797,6 +816,7 @@ fixtureWrongPassphrase ctx = do
fixtureDeletedWallet
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand Down Expand Up @@ -833,6 +853,7 @@ mkPayment addr_ amnt = [json|
postByronTransaction
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
)
=> Context t
-- A surrounding API context
Expand Down
Loading