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

Improve shared wallets #2663

Merged
merged 7 commits into from
May 26, 2021
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
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-addresses
tag: 7e062438fae15cf1025ab780adbe6ed26ac3e6e6
tag: 9fe7084c9c53b9edf3eba34ee8459c896734ac7a
subdir: command-line
core

Expand Down
31 changes: 27 additions & 4 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module Test.Integration.Framework.DSL
, patchSharedWallet
, getSharedWalletKey
, postAccountKeyShared
, getAccountKeyShared

-- * Wallet helpers
, listFilteredWallets
Expand Down Expand Up @@ -160,6 +161,8 @@ module Test.Integration.Framework.DSL
, triggerMaintenanceAction
, verifyMaintenanceAction
, genXPubs
, hexText
, fromHexText
, accPubKeyFromMnemonics

-- * Delegation helpers
Expand Down Expand Up @@ -242,6 +245,7 @@ import Cardano.Wallet.Api.Types
, DecodeStakeAddress (..)
, EncodeAddress (..)
, Iso8601Time (..)
, KeyFormat
, SettingsPutData (..)
, WalletStyle (..)
, insertedAt
Expand Down Expand Up @@ -855,9 +859,11 @@ genXPubs num =
xpubFromText :: Text -> Maybe XPub
xpubFromText = fmap eitherToMaybe fromHexText >=> xpubFromBytes

fromHexText :: Text -> Either String ByteString
fromHexText = fromHex . T.encodeUtf8
fromHexText :: Text -> Either String ByteString
fromHexText = fromHex . T.encodeUtf8

hexText :: ByteString -> Text
hexText = T.decodeLatin1 . hex

getTxId :: (ApiTransaction n) -> String
getTxId tx = T.unpack $ toUrlPiece $ ApiTxId (tx ^. #id)
Expand Down Expand Up @@ -1457,7 +1463,7 @@ getSharedWalletKey ctx wal role ix hashed =
ApiSharedWallet (Right wal') -> r wal'
where
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException ApiVerificationKeyShared)
r w = request @ApiVerificationKeyShared ctx (Link.getSharedWalletKey w role ix hashed) Default Empty
r w = request @ApiVerificationKeyShared ctx (Link.getWalletKey @'Shared w role ix hashed) Default Empty

postAccountKeyShared
:: forall m.
Expand All @@ -1476,7 +1482,24 @@ postAccountKeyShared ctx wal ix headers payload =
ApiSharedWallet (Right wal') -> r wal'
where
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
r w = request @ApiAccountKeyShared ctx (Link.postAccountKeyShared w ix) headers payload
r w = request @ApiAccountKeyShared ctx (Link.postAccountKey @'Shared w ix) headers payload

getAccountKeyShared
:: forall m.
( MonadIO m
, MonadUnliftIO m
)
=> Context
-> ApiSharedWallet
-> Maybe KeyFormat
-> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
getAccountKeyShared ctx wal hashed =
case wal of
ApiSharedWallet (Left wal') -> r wal'
ApiSharedWallet (Right wal') -> r wal'
where
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
r w = request @ApiAccountKeyShared ctx (Link.getAccountKey @'Shared w hashed) Default Empty

patchEndpointEnding :: CredentialType -> Text
patchEndpointEnding = \case
Expand Down
38 changes: 35 additions & 3 deletions lib/core-integration/src/Test/Integration/Framework/TestData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ module Test.Integration.Framework.TestData
, errMsg400ScriptDuplicateKeys
, errMsg400ScriptTimelocksContradictory
, errMsg400ScriptNotUniformRoles
, errMsg403TemplateInvalidNoCosignerInScript
, errMsg403TemplateInvalidUnknownCosigner
, errMsg403TemplateInvalidDuplicateXPub
, errMsg403TemplateInvalidScript
) where

import Prelude
Expand Down Expand Up @@ -546,9 +550,37 @@ errMsg403CannotUpdateThisCosigner = mconcat

errMsg403CreateIllegal :: String
errMsg403CreateIllegal = mconcat
[ "It looks like you've tried to create a shared wallet "
, "with a missing account key in the script template(s). This cannot be done "
, "as the wallet's account key must be always present for each script template."
[ "It looks like you've tried to create a shared wallet with a template "
, "script for payment credential that does not pass validation. The problem "
, "is: The wallet's account key must be always present for the script template."
]

errMsg403TemplateInvalidNoCosignerInScript :: String
errMsg403TemplateInvalidNoCosignerInScript = mconcat
[ "It looks like you've tried to create a shared wallet with a template "
, "script for payment credential that does not pass validation. "
, "The problem is: The list inside a script is empty or only contains timelocks (which is not recommended)."
]

errMsg403TemplateInvalidUnknownCosigner :: String
errMsg403TemplateInvalidUnknownCosigner = mconcat
[ "It looks like you've tried to create a shared wallet with a template"
, " script for payment credential that does not pass validation. The problem is:"
, " The specified cosigner must be present in the script of the template."
]

errMsg403TemplateInvalidDuplicateXPub :: String
errMsg403TemplateInvalidDuplicateXPub = mconcat
[ "It looks like you've tried to create a shared wallet with a template"
, " script for payment credential that does not pass validation. The problem is:"
, " The cosigners in a script template must stand behind an unique extended public key."
]

errMsg403TemplateInvalidScript :: String -> String
errMsg403TemplateInvalidScript reason = mconcat
[ "It looks like you've tried to create a shared wallet with a template"
, " script for payment credential that does not pass validation. The problem is: "
, reason
]

errMsg400ScriptWrongCoeffcient :: String
Expand Down
Loading