Skip to content

Cardano: Add vote delegation to node api - #89

Merged
benma merged 1 commit into
BitBoxSwiss:masterfrom
RostarMarek:rostarmarek/cardano/npm-vote-delegation
Nov 18, 2024
Merged

benma merged 1 commit into
BitBoxSwiss:masterfrom
RostarMarek:rostarmarek/cardano/npm-vote-delegation

Conversation

@RostarMarek

Copy link
Copy Markdown
Contributor

Added vote delegation to node api and wasm generation.

I still have the issue where I can't build that I mentioned here so I wasn't able to load firmware to my dev device to properly test it out.

@RostarMarek
RostarMarek force-pushed the rostarmarek/cardano/npm-vote-delegation branch from 22aaf65 to abcd7f4 Compare September 27, 2024 11:08
@RostarMarek
RostarMarek marked this pull request as ready for review September 27, 2024 12:12
Comment thread src/wasm/types.rs Outdated
| {
voteDelegation: {
keypath: Keypath
type: number

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

number is a bit too generic, wouldn't it be possible to narrow the values down with some enum? That would potentially allow for making this a union of different object shapes, making it clear when is drep hash required and when it isn't

Moreover, if possible, instead of null, I'd consider making the drepCredHash optional, at least from a typescript perspective it would feel more "natural"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree, this type should be something like

CardanoDRepType = 'keyHash'  | 'scriptHash' | 'alwaysAbstain'  | 'alwaysNoConfidence'

if it doesn't work out of the box like this, check other enums (e.g. in btc.proto/btc.rs) and scripts/build-protos.rs for reference,

Comment thread src/wasm/types.rs Outdated
| {
voteDelegation: {
keypath: Keypath
type: number

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree, this type should be something like

CardanoDRepType = 'keyHash'  | 'scriptHash' | 'alwaysAbstain'  | 'alwaysNoConfidence'

if it doesn't work out of the box like this, check other enums (e.g. in btc.proto/btc.rs) and scripts/build-protos.rs for reference,

Comment thread src/wasm/types.rs Outdated
voteDelegation: {
keypath: Keypath
type: number
drepCredhash: Uint8Array | undefined | null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why undefined or null? Seems like drepCredhash?: Uint8Array should be enough.

in scripts/build-protos.rs, you could rename this to drepCredHash (proper camelCase)

Comment thread sandbox/src/Cardano.tsx
);
}

export function Cardano({ bb02 } : Props) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please keep the same style (spaces, indent level, ...)

@benma benma left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please also add a CHANGELOG in CHANGELOG-npm.md under 0.7.0

If you rebase, the failing nightly CI item should disappear.

@RostarMarek
RostarMarek force-pushed the rostarmarek/cardano/npm-vote-delegation branch 3 times, most recently from 00d5d6a to eb4173a Compare October 11, 2024 11:20
Comment thread scripts/build-protos.rs Outdated
Comment on lines +95 to +110
(
"shiftcrypto.bitbox02.CardanoSignTransactionRequest.Certificate.VoteDelegation.CardanoDRepType.KEY_HASH",
"serde(rename = \"keyHash\")",
),
(
"shiftcrypto.bitbox02.CardanoSignTransactionRequest.Certificate.VoteDelegation.CardanoDRepType.SCRIPT_HASH",
"serde(rename = \"scriptHash\")",
),
(
"shiftcrypto.bitbox02.CardanoSignTransactionRequest.Certificate.VoteDelegation.CardanoDRepType.ALWAYS_ABSTAIN",
"serde(rename = \"alwaysAbstain\")",
),
(
"shiftcrypto.bitbox02.CardanoSignTransactionRequest.Certificate.VoteDelegation.CardanoDRepType.ALWAYS_NO_CONFIDENCE",
"serde(rename = \"alwaysNoConfidence\")",
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These are not needed because camelCase is the default - the dRepType enum has this attribute already:

#[cfg_attr(feature = "wasm", serde(rename_all = "camelCase"))]

Could you remove these?

@benma benma Nov 14, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you missed make build-protos afterwards, as these tags are still in the generated protobuf file. Please run make build-protos again.

Comment thread src/wasm/types.rs Outdated
voteDelegation: {
keypath: Keypath
type: CardanoDrepType
drepCredHash?: Uint8Array

@benma benma Oct 28, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you changed the name here but the deserialization still uses drepCredhash, so if you tried to use drepCredHash, it would not actually show the hash and error after confirmation.

Comment thread sandbox/src/Cardano.tsx
['zero-ttl', 'Transaction with TTL=0'],
['tokens', 'Transaction sending tokens'],
['delegate', 'Delegate staking to a pool'],
['vote-delegation', 'Delegate vote to a dRep'],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add another one that delegates to a keyHash or scriptHash, or add a dropdown to the existing one to switch the mode so all of them can be tested in the sandbox. The hash ones don't work right now (see other comment).

@benma benma left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also please add an entry to CHANGELOG-npm.md

@benma

benma commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

In the meantime we released v0.7.0 to npmjs. Please rebase and change NPM_VERSION to 0.8.0. Thanks.

@RostarMarek
RostarMarek force-pushed the rostarmarek/cardano/npm-vote-delegation branch 2 times, most recently from f211ed6 to 18b8237 Compare November 12, 2024 00:33
@RostarMarek
RostarMarek requested a review from benma November 12, 2024 10:42
Comment thread CHANGELOG-npm.md

## Unreleased

## 0.8.0

@benma benma Nov 14, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread scripts/build-protos.rs Outdated
Comment on lines +95 to +110
(
"shiftcrypto.bitbox02.CardanoSignTransactionRequest.Certificate.VoteDelegation.CardanoDRepType.KEY_HASH",
"serde(rename = \"keyHash\")",
),
(
"shiftcrypto.bitbox02.CardanoSignTransactionRequest.Certificate.VoteDelegation.CardanoDRepType.SCRIPT_HASH",
"serde(rename = \"scriptHash\")",
),
(
"shiftcrypto.bitbox02.CardanoSignTransactionRequest.Certificate.VoteDelegation.CardanoDRepType.ALWAYS_ABSTAIN",
"serde(rename = \"alwaysAbstain\")",
),
(
"shiftcrypto.bitbox02.CardanoSignTransactionRequest.Certificate.VoteDelegation.CardanoDRepType.ALWAYS_NO_CONFIDENCE",
"serde(rename = \"alwaysNoConfidence\")",
),

@benma benma Nov 14, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you missed make build-protos afterwards, as these tags are still in the generated protobuf file. Please run make build-protos again.

Added vote delegation to node api and wasm generation.

Signed-off-by: RostarMarek <rostarmarek@gmail.com>
@RostarMarek
RostarMarek force-pushed the rostarmarek/cardano/npm-vote-delegation branch from 18b8237 to afe26fd Compare November 18, 2024 12:05

@benma benma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks 🎉

@benma
benma merged commit 49e5ab8 into BitBoxSwiss:master Nov 18, 2024
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.

3 participants