diff --git a/packages/rs-sdk-ffi/cbindgen.toml b/packages/rs-sdk-ffi/cbindgen.toml index 957277506bc..8813a02e04b 100644 --- a/packages/rs-sdk-ffi/cbindgen.toml +++ b/packages/rs-sdk-ffi/cbindgen.toml @@ -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 = "" diff --git a/packages/rs-sdk-ffi/src/contested_resource/transitions/cast_vote.rs b/packages/rs-sdk-ffi/src/contested_resource/transitions/cast_vote.rs index 180e56ebcf4..2b61d482b93 100644 --- a/packages/rs-sdk-ffi/src/contested_resource/transitions/cast_vote.rs +++ b/packages/rs-sdk-ffi/src/contested_resource/transitions/cast_vote.rs @@ -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 diff --git a/packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ContestVoteState.swift b/packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ContestVoteState.swift index c5e493dbc08..c6dd4d0aae9 100644 --- a/packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ContestVoteState.swift +++ b/packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ContestVoteState.swift @@ -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 } } }