Skip to content

Conversation

@palas
Copy link
Contributor

@palas palas commented Nov 12, 2025

Changelog

- description: |
    Add implementation for stake certificate creation in `cardano-wasm` internal lib
  type:
  - feature
  projects:
  - cardano-wasm

Context

Work towards achieving support described in issue: #1007.

It is still necessary to expose the functions in the JavaScript API, and also support for adding certificates to transactions.

How to trust this PR

It is mainly a wrapper. I wanted to make it a separate PR to allow for early feedback on the API design.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

Exp.obtainCommonConstraints era $
conwayEraOnwardsConstraints (convert era) $
Certificate . ConwayTxCertDeleg
<$> ( case (action, delegateStake) of
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading this case gives off a feeling that StakeCertificateObject should be a sum type. The advantage is that you'd have to do more validations at the deserialisation stage, to reject invalid JSON representations and you wouldn't have to check for invalid states here.

Copy link
Contributor Author

@palas palas Nov 12, 2025

Choose a reason for hiding this comment

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

I was having doubts about this. My thought is that it would affect the API and it would be easier to have the API functions be simplest.

So, this way we make the registration/unregistration, deposit, and delegation aspects of the certificate independent, so you can set them one by one.

The disadvantage is, like you say, that we have a type that allows for invalid certificates, and that is disallowed at serialization time.

The advantage is that we don't have the almost cartesian product of possibilities, all of them with pretty much the same arguments:

  • Register without deposit (stakeid)
  • Register with deposit (stakeid, deposit)
  • Unregister (stakeid)
  • Unregister with deposit (stakeid, deposit)
  • Register with deposit and delegate (stakeid, deposit, poolid)
  • Delegate (stakeid, poolid)

Which is also not super nice

<$> ( case (action, delegateStake) of
(DelegateOnly, Nothing) ->
throwError
"Certificate must at least either: register, unregister, or delegate"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this error. Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not possible to create a certificate that does nothing, it needs to either register stake, or unregister stake, or delegate, or both register and delegate

@palas palas force-pushed the stake-certificates branch 3 times, most recently from 3c83b92 to 0e9d62c Compare November 12, 2025 18:18
@palas palas requested a review from Jimbo4350 November 13, 2025 00:06
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

A lot of these functions are not used anywhere. What is the goal here? Where will they be used?

import Data.Text qualified as Text
import Data.Text.Encoding qualified as Text

data StakeCertificateAction
Copy link
Contributor

@Jimbo4350 Jimbo4350 Nov 14, 2025

Choose a reason for hiding this comment

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

Why is StakeCertificateAction not defined like the following:

data StakeCertificateAction
  = RegisterStake Delegatee
  | UnregisterStake Delegatee
  | DelegateOnly Delegatee

Copy link
Contributor Author

@palas palas Nov 14, 2025

Choose a reason for hiding this comment

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

The intention was to be able to have separate withDelegation and withoutDelegation methods, if it is a sum type, then it is less obvious how to implement that, and in some situations withDelegation and withoutDelegation methods would fail. But I am not 100% sure this is the best approach. So maybe we can do something more straightforward even if more verbose

@palas
Copy link
Contributor Author

palas commented Nov 14, 2025

A lot of these functions are not used anywhere. What is the goal here? Where will they be used?

They will all be exposed to the JS API. I was doing this in steps, in case we wanted to rethink the API before adding the boiler-plate. Which seems to be the case

@palas palas force-pushed the stake-certificates branch from 39b15b8 to 6b352f0 Compare November 14, 2025 20:23
@palas palas requested a review from Jimbo4350 November 14, 2025 20:34
@palas
Copy link
Contributor Author

palas commented Nov 14, 2025

I've redone this PR to reuse existing types as much as possible. I have backed up the old approach in this branch for now: https://github.com/IntersectMBO/cardano-api/tree/stake-certificates-old-approach

Comment on lines +72 to +79
makeStakeAddressRegistrationCertificateWrapper Exp.ConwayEra skHash deposit

--  | Make a stake address registration certificate in the current experimental era.
makeStakeAddressRegistrationCertificateExperimentalEraImpl
:: MonadThrow m => String -> Integer -> m String
makeStakeAddressRegistrationCertificateExperimentalEraImpl skHashStr deposit = do
skHash <- readHash skHashStr
makeStakeAddressRegistrationCertificateWrapper Exp.DijkstraEra skHash deposit
Copy link
Contributor

Choose a reason for hiding this comment

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

ConwayEra and DijkstraEra are hardcoded in multiple places. Could you define those in one place and reuse it? It will be a pain in the neck to trace and update those on hardfork.

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.

4 participants