Skip to content

Commit

Permalink
Merge pull request #1967 from input-output-hk/KtorZ/1965/itn-withdrawals
Browse files Browse the repository at this point in the history
Redeem rewards from another wallet
  • Loading branch information
KtorZ authored Jul 31, 2020
2 parents ac9e1d0 + d3ebc72 commit 5af6e35
Show file tree
Hide file tree
Showing 49 changed files with 3,690 additions and 865 deletions.
4 changes: 4 additions & 0 deletions lib/byron/src/Cardano/Wallet/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ import System.Exit
( ExitCode (..) )
import System.IOManager
( withIOManager )
import Type.Reflection
( Typeable )

import qualified Cardano.Wallet.Api.Server as Server
import qualified Cardano.Wallet.DB.Sqlite as Sqlite
Expand All @@ -160,6 +162,7 @@ data SomeNetworkDiscriminant where
, EncodeStakeAddress n
, MaxSizeOf Address n IcarusKey
, MaxSizeOf Address n ByronKey
, Typeable n
)
=> Proxy n
-> SomeNetworkDiscriminant
Expand Down Expand Up @@ -244,6 +247,7 @@ serveWallet
, DecodeAddress n
, EncodeAddress n
, EncodeStakeAddress n
, Typeable n
)
=> Proxy n
-> Socket
Expand Down
15 changes: 9 additions & 6 deletions lib/byron/src/Cardano/Wallet/Byron/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ import Network.Ntp
( NtpClient )
import Servant
( (:<|>) (..), Server, err501, throwError )
import Type.Reflection
( Typeable )

-- | A diminished servant server to serve Byron wallets only.
server
:: forall t n.
( Buildable (ErrValidateSelection t)
, PaymentAddress n IcarusKey
, PaymentAddress n ByronKey
, Typeable n
)
=> ApiLayer (RndState n) t ByronKey
-> ApiLayer (SeqState n IcarusKey) t IcarusKey
Expand Down Expand Up @@ -153,9 +156,9 @@ server byron icarus ntp =

transactions :: Server (Transactions n)
transactions =
(\_ _ _ -> throwError err501)
(\_ _ -> throwError err501)
:<|> (\_ _ _ _ _ -> throwError err501)
:<|> (\_ _ _ -> throwError err501)
:<|> (\_ _ -> throwError err501)
:<|> (\_ _ -> throwError err501)
:<|> (\_ _ -> throwError err501)

Expand Down Expand Up @@ -243,11 +246,11 @@ server byron icarus ntp =
(byron , do
let pwd = coerce (getApiT $ tx ^. #passphrase)
genChange <- rndStateChange byron wid pwd
postTransaction byron genChange wid False tx
postTransaction byron genChange wid tx
)
(icarus, do
let genChange k _ = paymentAddress @n k
postTransaction icarus genChange wid False tx
postTransaction icarus genChange wid tx
)
)
:<|>
Expand All @@ -257,8 +260,8 @@ server byron icarus ntp =
)
:<|>
(\wid tx -> withLegacyLayer wid
(byron , postTransactionFee byron wid False tx)
(icarus, postTransactionFee icarus wid False tx)
(byron , postTransactionFee byron wid tx)
(icarus, postTransactionFee icarus wid tx)
)
:<|> (\wid txid -> withLegacyLayer wid
(byron , deleteTransaction byron wid txid)
Expand Down
2 changes: 1 addition & 1 deletion lib/byron/src/Cardano/Wallet/Byron/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ newTransactionLayer _proxy protocolMagic = TransactionLayer
}
where
_mkStdTx
:: (k 'AddressK XPrv, Passphrase "encryption")
:: (XPrv, Passphrase "encryption")
-- Reward account
-> (Address -> Maybe (k 'AddressK XPrv, Passphrase "encryption"))
-- Key store
Expand Down
3 changes: 2 additions & 1 deletion lib/byron/test/integration/Cardano/Wallet/Byron/Faucet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import Prelude
import Control.Concurrent.MVar
( newMVar )
import Test.Integration.Faucet
( Faucet (..), icaMnemonics, rndMnemonics, seqMnemonics )
( Faucet (..), icaMnemonics, mirMnemonics, rndMnemonics, seqMnemonics )

initFaucet :: IO Faucet
initFaucet = Faucet
<$> newMVar seqMnemonics
<*> newMVar icaMnemonics
<*> newMVar rndMnemonics
<*> newMVar mirMnemonics
<*> newMVar [] -- FIXME: txBuilder for external transaction.
17 changes: 2 additions & 15 deletions lib/cli/src/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ import Cardano.Wallet.Api.Types
, ApiT (..)
, ApiTxId (ApiTxId)
, ApiWallet
, ApiWithdrawRewards (..)
, ByronWalletPostData (..)
, ByronWalletStyle (..)
, Iso8601Time (..)
Expand Down Expand Up @@ -688,7 +687,6 @@ data TransactionCreateArgs t = TransactionCreateArgs
{ _port :: Port "Wallet"
, _id :: WalletId
, _payments :: NonEmpty Text
, _withdrawRewards :: Bool
}

cmdTransactionCreate
Expand All @@ -704,8 +702,7 @@ cmdTransactionCreate mkTxClient mkWalletClient =
<$> portOption
<*> walletIdArgument
<*> fmap NE.fromList (some paymentOption)
<*> withdrawRewardsFlag
exec (TransactionCreateArgs wPort wId wAddressAmounts wWithdraw) = do
exec (TransactionCreateArgs wPort wId wAddressAmounts) = do
wPayments <- either (fail . getTextDecodingError) pure $
traverse (fromText @(AddressAmount Text)) wAddressAmounts
res <- sendRequest wPort $ getWallet mkWalletClient $ ApiT wId
Expand All @@ -715,7 +712,6 @@ cmdTransactionCreate mkTxClient mkWalletClient =
runClient wPort Aeson.encodePretty $ postTransaction
mkTxClient
(ApiT wId)
(ApiWithdrawRewards wWithdraw)
(Aeson.object
[ "payments" .= wPayments
, "passphrase" .= ApiT wPwd
Expand All @@ -737,8 +733,7 @@ cmdTransactionFees mkTxClient mkWalletClient =
<$> portOption
<*> walletIdArgument
<*> fmap NE.fromList (some paymentOption)
<*> withdrawRewardsFlag
exec (TransactionCreateArgs wPort wId wAddressAmounts wWithdraw) = do
exec (TransactionCreateArgs wPort wId wAddressAmounts) = do
wPayments <- either (fail . getTextDecodingError) pure $
traverse (fromText @(AddressAmount Text)) wAddressAmounts
res <- sendRequest wPort $ getWallet mkWalletClient $ ApiT wId
Expand All @@ -747,7 +742,6 @@ cmdTransactionFees mkTxClient mkWalletClient =
runClient wPort Aeson.encodePretty $ postTransactionFee
mkTxClient
(ApiT wId)
(ApiWithdrawRewards wWithdraw)
(Aeson.object [ "payments" .= wPayments ])
Left _ ->
handleResponse Aeson.encodePretty res
Expand Down Expand Up @@ -1359,13 +1353,6 @@ addressIdArgument :: Parser Text
addressIdArgument = argumentT $ mempty
<> metavar "ADDRESS"

-- | [--withdraw-rewards]
withdrawRewardsFlag :: Parser Bool
withdrawRewardsFlag = switch $ mempty
<> long "withdraw-rewards"
<> help "Withdraw rewards as change in this transaction, provided they \
\contribute positively to the balance."

-- | Helper for writing an option 'Parser' using a 'FromText' instance.
optionT :: FromText a => Mod OptionFields a -> Parser a
optionT = option (eitherReader fromTextS)
Expand Down
9 changes: 1 addition & 8 deletions lib/cli/test/unit/Cardano/CLISpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ spec = do

["transaction", "create", "--help"] `shouldShowUsage`
[ "Usage: transaction create [--port INT] WALLET_ID"
, " --payment PAYMENT [--withdraw-rewards]"
, " --payment PAYMENT"
, " Create and submit a new transaction."
, ""
, "Available options:"
Expand All @@ -272,14 +272,10 @@ spec = do
, " --payment PAYMENT address to send to and amount to send"
, " separated by @, e.g."
, " '<amount>@<address>'"
," --withdraw-rewards Withdraw rewards as change in this"
," transaction, provided they contribute"
," positively to the balance."
]

["transaction", "fees", "--help"] `shouldShowUsage`
[ "Usage: transaction fees [--port INT] WALLET_ID --payment PAYMENT"
, " [--withdraw-rewards]"
, " Estimate fees for a transaction."
, ""
, "Available options:"
Expand All @@ -289,9 +285,6 @@ spec = do
, " --payment PAYMENT address to send to and amount to send"
, " separated by @, e.g."
, " '<amount>@<address>'"
," --withdraw-rewards Withdraw rewards as change in this"
," transaction, provided they contribute"
," positively to the balance."
]

["transaction", "list", "--help"] `shouldShowUsage`
Expand Down
Loading

0 comments on commit 5af6e35

Please sign in to comment.