Skip to content

Commit 0dc27ea

Browse files
committed
fix(games/gacha): start account discriminators at 1
All-zero account data must never carry a valid discriminator, so Pool moves off 0.
1 parent 61439d3 commit 0dc27ea

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎games/gacha/pinocchio-simple/idl/gacha_simple.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,12 @@
398398
},
399399
"variants": [
400400
{
401-
"discriminator": 0,
401+
"discriminator": 1,
402402
"kind": "enumEmptyVariantTypeNode",
403403
"name": "pool"
404404
},
405405
{
406-
"discriminator": 1,
406+
"discriminator": 2,
407407
"kind": "enumEmptyVariantTypeNode",
408408
"name": "pull"
409409
}

‎games/gacha/pinocchio-simple/program/src/state/common.rs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@ pub const MINT_SEED: &[u8] = b"mint";
1616

1717
/// One-byte discriminator identifying the type of a program-owned account.
1818
///
19-
/// Stored at byte offset 0 of every data-carrying account created by this program.
19+
/// Stored at byte offset 0 of every data-carrying account created by this
20+
/// program. Values start at 1 so all-zero account data never carries a valid
21+
/// discriminator.
2022
#[repr(u8)]
2123
#[derive(Clone, Copy, PartialEq, Debug, CodamaType)]
2224
pub enum AccountDiscriminator {
2325
/// [`Pool`](super::pool::Pool) account.
24-
Pool = 0,
26+
Pool = 1,
2527
/// [`Pull`](super::pull::Pull) account.
26-
Pull = 1,
28+
Pull = 2,
2729
}
2830

2931
impl TryFrom<u8> for AccountDiscriminator {
3032
type Error = ProgramError;
3133
fn try_from(value: u8) -> Result<Self, Self::Error> {
3234
match value {
33-
0 => Ok(Self::Pool),
34-
1 => Ok(Self::Pull),
35+
1 => Ok(Self::Pool),
36+
2 => Ok(Self::Pull),
3537
_ => Err(GachaError::InvalidAccountDiscriminator.into()),
3638
}
3739
}

0 commit comments

Comments
 (0)