Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ documentation_style = "c99"
[defines]

[export]
include = ["dash_sdk_*", "dash_core_*", "dash_unified_sdk_*", "ContestedResourceVoteChoiceFFI"]
include = ["dash_sdk_*", "dash_core_*", "dash_unified_sdk_*"]
# Exclude types that come from key-wallet-ffi to avoid duplication
exclude = ["FFIAccountType", "FFIAccountTypePreference", "FFIAccountTypeUsed", "FFIAccountCreationOptionType"]
prefix = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ use zeroize::Zeroizing;
/// `0` = TowardsIdentity (requires `contender_identity_id`), `1` = Abstain,
/// `2` = Lock.
///
/// This `#[repr(u8)]` enum exists so cbindgen emits the discriminant values
/// into the generated C header (a bare `pub const u8` is not exported),
/// giving Swift a single source of truth instead of hand-mirroring `0/1/2`.
/// It is force-emitted via the `[export] include` list in `cbindgen.toml`.
/// This `#[repr(u8)]` enum is the Rust-internal single source of truth for the
/// `vote_choice` discriminants used by [`cast_vote_inner`] (its `as u8`
/// discriminants drive the value validation / comparison). It is intentionally
/// **not** exported to the generated C header: the FFI parameter is a plain
/// `u8`, and the Swift side mirrors the discriminants in
/// `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ContestVoteState.swift`.
///
/// The `vote_choice` FFI parameter is deliberately a plain `u8`, **not** this
/// enum: a C/Swift caller can pass any byte, and materializing an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,17 @@ public enum ContestedResourceVoteChoice: Sendable, Equatable {
/// Lock — vote that nobody should win the contested resource.
case lock

/// The `vote_choice` value passed across the FFI, typed as the
/// cbindgen-generated `ContestedResourceVoteChoiceFFI` rather than a bare
/// `UInt8`. `rs-sdk-ffi` emits that `#[repr(u8)]` enum into the C header
/// (a u8 typedef) as the single source of truth for the discriminants, so
/// binding the bridge to the generated symbol keeps Swift from drifting
/// from the Rust values. The FFI function takes a `u8`, which this maps
/// to cleanly. The raw values mirror the Rust variants:
/// The `vote_choice` discriminant byte passed across the FFI. The
/// `dash_sdk_contested_resource_cast_vote` parameter is a plain `u8`, so
/// this is a `UInt8`. The values must agree with the
/// `ContestedResourceVoteChoiceFFI` enum in
/// `packages/rs-sdk-ffi/src/contested_resource/transitions/cast_vote.rs`:
/// `TowardsIdentity = 0`, `Abstain = 1`, `Lock = 2`.
var ffiTag: ContestedResourceVoteChoiceFFI {
var ffiTag: UInt8 {
switch self {
case .towardsIdentity: return ContestedResourceVoteChoiceFFI(0)
case .abstain: return ContestedResourceVoteChoiceFFI(1)
case .lock: return ContestedResourceVoteChoiceFFI(2)
case .towardsIdentity: return 0
case .abstain: return 1
case .lock: return 2
}
}
}
Expand Down
Loading