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

Redeem rewards from another wallet #1967

Merged
merged 11 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generated 10 of them, used 2 or 3 I think in the scenarios I wrote, so there is still some room for some :p

<*> 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