@@ -5,9 +5,6 @@ use star_frame::borsh;
55use star_frame:: borsh:: { BorshDeserialize , BorshSerialize } ;
66use star_frame:: prelude:: * ;
77
8- use star_frame:: star_frame_idl:: ty:: { IdlEnumVariant , IdlType , IdlTypeDef , IdlTypeId } ;
9- use star_frame:: star_frame_idl:: { item_source, IdlDefinition , ItemInfo } ;
10-
118#[ derive( StarFrameProgram ) ]
129#[ program(
1310 instruction_set = FactionEnlistmentInstructionSet
@@ -81,6 +78,11 @@ pub struct ProcessEnlistPlayer<'info> {
8178 Seeds ( PlayerFactionAccountSeeds {
8279 player_account: * self . player_account. key( )
8380 } ) ) ) ]
81+ #[ idl(
82+ arg = Seeds ( FindPlayerFactionAccountSeeds {
83+ player_account: seed_path( "player_account" )
84+ } )
85+ ) ]
8486 pub player_faction_account : Init < Seeded < DataAccount < ' info , PlayerFactionData > > > ,
8587 /// The player account
8688 #[ account_set( funder) ]
@@ -114,8 +116,9 @@ pub struct PlayerFactionData {
114116 Eq ,
115117 PartialEq ,
116118 Default ,
119+ TypeToIdl ,
117120) ]
118- #[ borsh( crate = "borsh" ) ]
121+ #[ borsh( crate = "borsh" , use_discriminant = true ) ]
119122#[ repr( u8 ) ]
120123pub enum FactionId {
121124 #[ default]
@@ -124,70 +127,10 @@ pub enum FactionId {
124127 Ustur ,
125128}
126129
127- impl TypeToIdl for FactionId {
128- type AssociatedProgram = crate :: StarFrameDeclaredProgram ;
129- fn type_to_idl ( idl_definition : & mut IdlDefinition ) -> Result < IdlTypeDef > {
130- let source = item_source :: < Self > ( ) ;
131- let type_def = IdlTypeDef :: Enum ( vec ! [
132- IdlEnumVariant {
133- name: "MUD" . to_string( ) ,
134- discriminant: vec![ 0 ] ,
135- type_def: None ,
136- } ,
137- IdlEnumVariant {
138- name: "ONI" . to_string( ) ,
139- discriminant: vec![ 1 ] ,
140- type_def: None ,
141- } ,
142- IdlEnumVariant {
143- name: "USTUR" . to_string( ) ,
144- discriminant: vec![ 2 ] ,
145- type_def: None ,
146- } ,
147- ] ) ;
148- let idl_type = IdlType {
149- info : ItemInfo {
150- name : "FactionId" . to_string ( ) ,
151- description : vec ! [ ] ,
152- source : source. clone ( ) ,
153- } ,
154- type_def,
155- generics : vec ! [ ] ,
156- } ;
157- let namespace = idl_definition. add_type ( idl_type, Self :: AssociatedProgram :: PROGRAM_ID ) ;
158- Ok ( IdlTypeDef :: Defined ( IdlTypeId {
159- namespace,
160- source,
161- provided_generics : vec ! [ ] ,
162- } ) )
163- }
164- }
165-
166130unsafe impl Zeroable for FactionId { }
167131
168- // impl AccountToIdl for PlayerFactionData {
169- // fn account_to_idl(idl_definition: &mut IdlDefinition) -> Result<IdlAccountId> {
170- // let source = item_source::<Self>();
171- // let idl_account = IdlAccount {
172- // discriminant: Self::discriminant_bytes(),
173- // seeds: Some(IdlSeeds(vec![
174- // IdlSeed::Const(b"FACTION_ENLISTMENT".into()),
175- // IdlSeed::Variable(IdlVariableSeed {
176- // name: "player_account".to_string(),
177- // description: vec![],
178- // ty: <Pubkey>::type_to_idl(idl_definition)?,
179- // }),
180- // ])),
181- // type_def: <PlayerFactionData>::type_to_idl(idl_definition)?,
182- // };
183- // let namespace =
184- // idl_definition.add_account(idl_account, Self::AssociatedProgram::PROGRAM_ID)?;
185- // Ok(IdlAccountId { namespace, source })
186- // }
187- // }
188-
189132#[ derive( Debug , GetSeeds , Clone ) ]
190- #[ seed_const ( b"FACTION_ENLISTMENT" ) ]
133+ #[ get_seeds ( seed_const = b"FACTION_ENLISTMENT" ) ]
191134pub struct PlayerFactionAccountSeeds {
192135 player_account : Pubkey ,
193136}
0 commit comments