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

[ADP-3406] Scaffold signTxBody for deposit wallet #4722

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

Anviking
Copy link
Member

@Anviking Anviking commented Aug 8, 2024

  • Scaffold signTxBody function
  • Add rootXSignKey field to WalletState

Issue Number

ADP-3406

@Anviking Anviking self-assigned this Aug 8, 2024
@@ -95,7 +97,7 @@ data WalletState = WalletState
, utxoHistory :: !UTxOHistory.UTxOHistory
-- , txHistory :: [Read.Tx]
, submissions :: Sbm.TxSubmissions
-- , credentials :: Maybe (HashedCredentials (KeyOf s))
, rootXSignKey :: Maybe XPrv
Copy link
Member Author

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
Copy link
Member Author

@Anviking Anviking Aug 8, 2024

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

createPayment
:: [(Address, Read.Value)] -> WalletInstance -> IO (Maybe Write.TxBody)
createPayment a w =
Wallet.createPayment a <$> readWalletState w
? ... which contrasts with how we've in cardano-wallet moved towards IO result with a potential WalletException thrown.

Copy link
Contributor

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.

@Anviking Anviking changed the title Scaffold signTxBody for deposit wallet [ADP-3406] Scaffold signTxBody for deposit wallet Aug 8, 2024
Copy link
Contributor

@HeinrichApfelmus HeinrichApfelmus left a 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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

@Anviking Anviking force-pushed the anviking/ADP-3406/scaffold-signTx branch from 7d766ff to c15ff06 Compare August 8, 2024 17:18
@Anviking Anviking enabled auto-merge August 8, 2024 17:18
@Anviking Anviking added this pull request to the merge queue Aug 8, 2024
Merged via the queue into master with commit 5e82dff Aug 8, 2024
23 checks passed
@Anviking Anviking deleted the anviking/ADP-3406/scaffold-signTx branch August 8, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants