-
Notifications
You must be signed in to change notification settings - Fork 217
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
Construct tx for multisig wallet #3378
Construct tx for multisig wallet #3378
Conversation
6b61367
to
f026f64
Compare
f026f64
to
e476ff6
Compare
specifications/api/swagger.yaml
Outdated
/shared-wallets/{walletId}/transactions-construct: | ||
post: | ||
operationId: constructSharedTransaction | ||
tags: ["Transactions New"] |
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.
This should go rather into 'Shared Transactions' under 'Shelley (Shared Wallets)'.
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.
done
description: | | ||
<p align="right">status: <strong>under development</strong></p> | ||
|
||
Create a transaction to be signed from the shared 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.
I'd be for adding an additional note here explicitely which elements of construct we are expecting to work with a ApiConstructTransactionData
which might suggest all of them work)
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.
done
let amt = 10 * minUTxOValue (_mainEra ctx) | ||
fundSharedWallet ctx amt walShared | ||
where | ||
fundSharedWallet ctx amt walShared = do |
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.
I think it would be quite useful to introduce fixtureSharedWallet
mechanism (just like we have for fixtureWallet
). That would be quite handy for testing transactions, as we're going to have more tests like that.
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.
yes, it is good idea. I plan to do it in next PR just not to bloat this one
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.
I have done it in the current PR
errMsg403SharedWalletPending :: String | ||
errMsg403SharedWalletPending = unwords | ||
[ "Transaction for a shared wallet should not be tried for" | ||
, "a pending shared wallet. Make the wallet active before sending" |
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.
The visible status of such wallet is actually:
"state": {
"status": "incomplete"
}
So maybe something like:
"I cannot construct transaction for a shared wallet that is in 'incomplete' state. Please update your wallet accordingly with 'PATCH /shared-wallets/{walletId}/payment-script-template' or 'PATCH /shared-wallets/{walletId}/delegation-script-template' to make it applicable for constructing transaction."
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.
done
(Link.createUnsignedTransaction @'Shared wal) Default metadata | ||
verify rTx | ||
[ expectResponseCode HTTP.status403 | ||
, expectErrorMessage errMsg403EmptyUTxO |
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.
Ok for the empty wallet, but we're missing test for constructing tx from wallet with funds.
Actually, it seems the case of non-empty wallet there is an unexpected 403
:
$ curl -X POST http://localhost:8090/v2/shared-wallets/e173d884b4300c7450b6a7774fd4055bf3547eac/transactions-construct \
-d '{"payments":[{"address":"addr_test1xz0fh48l3rv4tgs32e767ax60rdncf3ydfgtgxt3u83staue0pjynxnypmrzetew4nmwq4yapd3cc85qc9fg6gva66psrh402e",
"amount":{"quantity":10000000,"unit":"lovelace"}}]}' \
-H "Content-Type: application/json" | jq
{
"code": "invalid_wallet_type",
"message": "It is regrettable but you've just attempted an operation that is invalid for this type of wallet. Only new 'Shelley' wallets can do something with rewards and this one isn't."
}
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.
I know, I needed to add special mutable account treatment for shared wallet to deal with that.
dfde761
to
6892586
Compare
fundSharedWallet ctx amt walShared | ||
|
||
rTx2 <- request @(ApiConstructTransaction n) ctx | ||
(Link.createUnsignedTransaction @'Shared wal) Default metadata |
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.
It would be nice actually to demonstrate in the integration tests all that we expect to work is working, i.e. constructing:
- single output tx
- multi ouput tx
- multi assets tx
- metadata
- use of validity intervals
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.
sounds reasonable. I have added testing for all cases except multi assets tx as this topic will require separate treatment and ticket. I also added fixtureSharedWallet
as you requested in early comment
16aa0d6
to
9532b60
Compare
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.
First round of review. Looks mostly good! 😊 However, a couple of points:
One point that needs to be fixed:
PendingIxs
need to be part of the Prologue — similar to howSeqState
does it. (Yes, this means that there could be a subtle problem with the pending txs when a rollback happens, they are not part of the checkpoints. However, this problem has always been present in theSeqState
; this is not the right moment to fix it.)
Two points that I think should be fixed:
- I believe that we can statically set
k ~ SharedKey
and get rid of the dynamic error forconstructSharedTransaction
. - Avoid code duplication for
PendingIxs
, specially for the implementation ofnextChangeIndex
, by extracting the common functions into a separate module (suggestions in comments).
One point that would be nice to address, but is not blocking:
- Accumulate less logic in
Cardano.Wallet.Api.Server
— move coin selection logic toCardano.Wallet
instead.
Looking forward to second round of review. Happy to discuss in person as well.
(I have looked at almost all files, but not the integration tests.)
9532b60
to
1ce7652
Compare
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.
Looks good to me now! 😊 Only minor issues with indentation remaining.
Shared.pendingIxsFromList . fromRes <$> selectList | ||
[SharedStatePendingWalletId ==. wid] | ||
[Desc SharedStatePendingIxIndex] |
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.
Shared.pendingIxsFromList . fromRes <$> selectList | |
[SharedStatePendingWalletId ==. wid] | |
[Desc SharedStatePendingIxIndex] | |
Shared.pendingIxsFromList . fromRes <$> selectList | |
[SharedStatePendingWalletId ==. wid] | |
[Desc SharedStatePendingIxIndex] |
(Indentation for clarity.)
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.
done
extAddrMap <- loadAddresses @'UtxoExternal | ||
intAddrMap <- loadAddresses @'UtxoInternal | ||
pure $ SharedDiscoveries extAddrMap intAddrMap |
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.
extAddrMap <- loadAddresses @'UtxoExternal | |
intAddrMap <- loadAddresses @'UtxoInternal | |
pure $ SharedDiscoveries extAddrMap intAddrMap | |
extAddrMap <- loadAddresses @'UtxoExternal | |
intAddrMap <- loadAddresses @'UtxoInternal | |
pure $ SharedDiscoveries extAddrMap intAddrMap |
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.
done
-------------------------------------------------------------------------------} | ||
|
||
-- | An ordered set of pending indexes. This keep track of indexes used | ||
newtype PendingIxs = PendingIxs |
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.
let's say I will do it in the next PR
That works for me! Feel free to make a separate PR just for this refactoring move — that will make it much easier to review.
bors r+ |
3378: Construct tx for multisig wallet r=paweljakubas a=paweljakubas <!-- Detail in a few bullet points the work accomplished in this PR. Before you submit, don't forget to: * Make sure the GitHub PR fields are correct: ✓ Set a good Title for your PR. ✓ Assign yourself to the PR. ✓ Assign one or more reviewer(s). ✓ Link to a Jira issue, and/or other GitHub issues or PRs. ✓ In the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages. * Don't waste reviewers' time: ✓ If it's a draft, select the Create Draft PR option. ✓ Self-review your changes to make sure nothing unexpected slipped through. * Try to make your intent clear: ✓ Write a good Description that explains what this PR is meant to do. ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding Jira ticket. ✓ Highlight what Testing you have done. ✓ Acknowledge any changes required to the Documentation. --> The work was realized in three areas: 1. On api level, the constructSharedTx was added in core's api level. Also swagger was updated accordingly. On api's server level the simplest (without delegation or minting support) impl was chosen. The error outlawing calling this endpoint was introduced when shared wallet is in pending state. Also transaction integration test suite was added 2. The shared wallet state was extended. When the wallet is in active state now both external and internal pools are available. Also `PendingIxs` was added there. Those three things are now encapsulated in `SharedAddressPools` abstraction. So the accounting logic is like with shelley's wallet. In order to achieve that `SharedAddressPool` abstraction was generalized to account for chain type parameter. As previously active state has only external shared address pool, the change to have two more things had significant ripple effects down to DB layer. It also affected core unit testing. As `deriveAddressPublicKey` from cardano-addresses was assuming external chain only, the prerequisite for this PR is IntersectMBO/cardano-addresses#191 that enabled also derivation for internal chain. Moreover, `GenChange` interface impl was added, also impl of `constructAddressFromIx` was changed, the same for `isShared` impl. 3. `constructSharedTransaction` was added in `Cardano.Wallet`. `constructTransaction` wallet therein could not be used as it sets reward account in a way that is not enough for shared wallets, also it outlawsnon-shelly style wallets. For shared wallets delegation credential could be both keyhash (like for shelley) or script hash - at this moment key hash solution based on accXPub of wallet and ix=0 was added. In next PRs we will return to this subject. ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-1623 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Pawel Jakubas <[email protected]> Co-authored-by: Piotr Stachyra <[email protected]>
Build failed:
|
bors r+ |
Build succeeded: |
3412: PendingIxs refactoring and decode tx shared wallets r=paweljakubas a=paweljakubas <!-- Detail in a few bullet points the work accomplished in this PR. Before you submit, don't forget to: * Make sure the GitHub PR fields are correct: ✓ Set a good Title for your PR. ✓ Assign yourself to the PR. ✓ Assign one or more reviewer(s). ✓ Link to a Jira issue, and/or other GitHub issues or PRs. ✓ In the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages. * Don't waste reviewers' time: ✓ If it's a draft, select the Create Draft PR option. ✓ Self-review your changes to make sure nothing unexpected slipped through. * Try to make your intent clear: ✓ Write a good Description that explains what this PR is meant to do. ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding Jira ticket. ✓ Highlight what Testing you have done. ✓ Acknowledge any changes required to the Documentation. --> - [x] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode - [x] I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx as in #3378 - [x] I have added integration tests ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-2008 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Pawel Jakubas <[email protected]>
3412: PendingIxs refactoring and decode tx shared wallets r=paweljakubas a=paweljakubas <!-- Detail in a few bullet points the work accomplished in this PR. Before you submit, don't forget to: * Make sure the GitHub PR fields are correct: ✓ Set a good Title for your PR. ✓ Assign yourself to the PR. ✓ Assign one or more reviewer(s). ✓ Link to a Jira issue, and/or other GitHub issues or PRs. ✓ In the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages. * Don't waste reviewers' time: ✓ If it's a draft, select the Create Draft PR option. ✓ Self-review your changes to make sure nothing unexpected slipped through. * Try to make your intent clear: ✓ Write a good Description that explains what this PR is meant to do. ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding Jira ticket. ✓ Highlight what Testing you have done. ✓ Acknowledge any changes required to the Documentation. --> - [x] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode - [x] I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx as in #3378 - [x] I have added integration tests ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-2008 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Pawel Jakubas <[email protected]>
3412: PendingIxs refactoring and decode tx shared wallets r=paweljakubas a=paweljakubas <!-- Detail in a few bullet points the work accomplished in this PR. Before you submit, don't forget to: * Make sure the GitHub PR fields are correct: ✓ Set a good Title for your PR. ✓ Assign yourself to the PR. ✓ Assign one or more reviewer(s). ✓ Link to a Jira issue, and/or other GitHub issues or PRs. ✓ In the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages. * Don't waste reviewers' time: ✓ If it's a draft, select the Create Draft PR option. ✓ Self-review your changes to make sure nothing unexpected slipped through. * Try to make your intent clear: ✓ Write a good Description that explains what this PR is meant to do. ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding Jira ticket. ✓ Highlight what Testing you have done. ✓ Acknowledge any changes required to the Documentation. --> - [x] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode - [x] I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx as in #3378 - [x] I have added integration tests ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-2008 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Pawel Jakubas <[email protected]>
3412: PendingIxs refactoring and decode tx shared wallets r=paweljakubas a=paweljakubas <!-- Detail in a few bullet points the work accomplished in this PR. Before you submit, don't forget to: * Make sure the GitHub PR fields are correct: ✓ Set a good Title for your PR. ✓ Assign yourself to the PR. ✓ Assign one or more reviewer(s). ✓ Link to a Jira issue, and/or other GitHub issues or PRs. ✓ In the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages. * Don't waste reviewers' time: ✓ If it's a draft, select the Create Draft PR option. ✓ Self-review your changes to make sure nothing unexpected slipped through. * Try to make your intent clear: ✓ Write a good Description that explains what this PR is meant to do. ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding Jira ticket. ✓ Highlight what Testing you have done. ✓ Acknowledge any changes required to the Documentation. --> - [x] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode - [x] I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx as in #3378 - [x] I have added integration tests ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-2008 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Pawel Jakubas <[email protected]>
3412: PendingIxs refactoring and decode tx shared wallets r=paweljakubas a=paweljakubas <!-- Detail in a few bullet points the work accomplished in this PR. Before you submit, don't forget to: * Make sure the GitHub PR fields are correct: ✓ Set a good Title for your PR. ✓ Assign yourself to the PR. ✓ Assign one or more reviewer(s). ✓ Link to a Jira issue, and/or other GitHub issues or PRs. ✓ In the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages. * Don't waste reviewers' time: ✓ If it's a draft, select the Create Draft PR option. ✓ Self-review your changes to make sure nothing unexpected slipped through. * Try to make your intent clear: ✓ Write a good Description that explains what this PR is meant to do. ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding Jira ticket. ✓ Highlight what Testing you have done. ✓ Acknowledge any changes required to the Documentation. --> - [x] I have introduced `PendingIxs` in `AddressDerivation` and reused it in both sequential and shared mode - [x] I have implemented endpoint for decode tx for multisig working for all cases supported for construct tx as in #3378 - [x] I have added integration tests ### Comments <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number adp-2008 <!-- Reference the Jira/GitHub issue that this PR relates to, and which requirements it tackles. Note: Jira issues of the form ADP- will be auto-linked. --> Co-authored-by: Pawel Jakubas <[email protected]>
The work was realized in three areas:
On api level, the constructSharedTx was added in core's api level. Also swagger was updated accordingly.
On api's server level the simplest (without delegation or minting support) impl was chosen. The error outlawing calling this endpoint was introduced when shared wallet is in pending state. Also transaction integration test suite was added
The shared wallet state was extended. When the wallet is in active state now both external and internal pools are available. Also
PendingIxs
was added there. Those three things are now encapsulated inSharedAddressPools
abstraction. So the accounting logic is like with shelley's wallet. In order to achieve thatSharedAddressPool
abstraction was generalized to account for chain type parameter. As previously active state has only external shared address pool, the change to have two more things had significant ripple effects down to DB layer. It also affected core unit testing. AsderiveAddressPublicKey
from cardano-addresses was assuming external chain only, the prerequisite for this PR is Extend payment share key derivation IntersectMBO/cardano-addresses#191 that enabled also derivation for internal chain.Moreover,
GenChange
interface impl was added, also impl ofconstructAddressFromIx
was changed, the same forisShared
impl.constructSharedTransaction
was added inCardano.Wallet
.constructTransaction
wallet therein could not be used as it sets reward account in a way that is not enough for shared wallets, also it outlawsnon-shelly style wallets. For shared wallets delegation credential could be both keyhash (like for shelley) or script hash - at this moment key hash solution based on accXPub of wallet and ix=0 was added. In next PRs we will return to this subject.Comments
Issue Number
adp-1623