-
Notifications
You must be signed in to change notification settings - Fork 220
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
[ADP-3406] Scaffold signTxBody
for deposit wallet
#4722
Conversation
@@ -95,7 +97,7 @@ data WalletState = WalletState | |||
, utxoHistory :: !UTxOHistory.UTxOHistory | |||
-- , txHistory :: [Read.Tx] | |||
, submissions :: Sbm.TxSubmissions | |||
-- , credentials :: Maybe (HashedCredentials (KeyOf s)) | |||
, rootXSignKey :: Maybe XPrv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure where to put a type alias, so went with XPrv
for now
@@ -245,6 +248,9 @@ getBIP32Paths :: WalletState -> [Read.Address] -> [BIP32Path] | |||
getBIP32Paths w = | |||
mapMaybe $ Address.getBIP32Path (addresses w) . Read.toRawAddress | |||
|
|||
signTxBody :: Write.TxBody -> [BIP32Path] -> WalletState -> Write.Tx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or well — at least Maybe Write.Tx
as rootSignKey
might be nothing.
But is returning IO (Maybe result)
in the .IO
module our desired approach then like
cardano-wallet/lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/IO.hs
Lines 205 to 208 in 7d766ff
createPayment | |
:: [(Address, Read.Value)] -> WalletInstance -> IO (Maybe Write.TxBody) | |
createPayment a w = | |
Wallet.createPayment a <$> readWalletState w |
IO result
with a potential WalletException
thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 For the pure version, I would definitely add explicit failure.
I would also leave out the [BIP32Path]
argument, because that can be computed from the combination of TxBody
and WalletState
. (My feeling is that this argument would be on topic for a function whose abstraction is at the level of XPrv
, e.g. signTxBody :: XPrv → [BIP32Path] → …
, and does not know about the WalletState
.)
How about this:
-- | Add signatures for *all* inputs if possible, `Nothing` otherwise.
signTxBody :: Write.TxBody -> WalletState -> Maybe Write.Tx
For the version without Maybe
, I would probably give it a different name, which makes the semantics more clear:
-- | Add signatures for as many inputs as possible.
cosignTx :: Write.Tx -> WalletState -> Write.Tx
We can have either one or both, but for the beginning, I think that signTxBody
is a good start.
signTxBody
for deposit walletsignTxBody
for deposit wallet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 😊
🤔 I think I prefer the version with explicit Maybe
, definitely in the pure part.
@@ -245,6 +248,9 @@ getBIP32Paths :: WalletState -> [Read.Address] -> [BIP32Path] | |||
getBIP32Paths w = | |||
mapMaybe $ Address.getBIP32Path (addresses w) . Read.toRawAddress | |||
|
|||
signTxBody :: Write.TxBody -> [BIP32Path] -> WalletState -> Write.Tx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 For the pure version, I would definitely add explicit failure.
I would also leave out the [BIP32Path]
argument, because that can be computed from the combination of TxBody
and WalletState
. (My feeling is that this argument would be on topic for a function whose abstraction is at the level of XPrv
, e.g. signTxBody :: XPrv → [BIP32Path] → …
, and does not know about the WalletState
.)
How about this:
-- | Add signatures for *all* inputs if possible, `Nothing` otherwise.
signTxBody :: Write.TxBody -> WalletState -> Maybe Write.Tx
For the version without Maybe
, I would probably give it a different name, which makes the semantics more clear:
-- | Add signatures for as many inputs as possible.
cosignTx :: Write.Tx -> WalletState -> Write.Tx
We can have either one or both, but for the beginning, I think that signTxBody
is a good start.
@@ -245,6 +248,9 @@ getBIP32Paths :: WalletState -> [Read.Address] -> [BIP32Path] | |||
getBIP32Paths w = | |||
mapMaybe $ Address.getBIP32Path (addresses w) . Read.toRawAddress | |||
|
|||
signTxBody :: Write.TxBody -> [BIP32Path] -> WalletState -> Write.Tx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signTxBody :: Write.TxBody -> [BIP32Path] -> WalletState -> Write.Tx | |
signTxBody :: Write.TxBody -> WalletState -> Maybe Write.Tx |
@@ -211,6 +212,9 @@ getBIP32PathsForOwnedInputs | |||
getBIP32PathsForOwnedInputs a w = | |||
Wallet.getBIP32PathsForOwnedInputs a <$> readWalletState w | |||
|
|||
signTxBody :: Write.TxBody -> [BIP32Path] -> WalletInstance -> IO Write.Tx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
signTxBody :: Write.TxBody -> [BIP32Path] -> WalletInstance -> IO Write.Tx | |
signTxBody :: Write.TxBody -> WalletInstance -> IO (Maybe Write.Tx) |
But is returning IO (Maybe result) in the .IO module our desired approach then like
I think so 🤔 — The ubiquitous ErrNoSuchWallet
is gone, and by making the failure explicitly in the result, we can also present it an explicit HTTP status code 4xx response. I would only sweep the status code 500 "internal server error" into the IO
exceptions.
7d766ff
to
c15ff06
Compare
signTxBody
functionrootXSignKey
field toWalletState
Issue Number
ADP-3406