From 946eeab836abf03911ea8fda8b00d37fc638fcb4 Mon Sep 17 00:00:00 2001 From: Nick Garfield Date: Wed, 7 Sep 2022 10:44:48 -0500 Subject: [PATCH] Rename queue.name to queue.id --- client/src/crank/instruction/queue_create.rs | 8 +++--- .../crank/src/instructions/queue_crank.rs | 2 +- .../crank/src/instructions/queue_create.rs | 12 ++++---- .../crank/src/instructions/queue_delete.rs | 2 +- .../crank/src/instructions/queue_pause.rs | 2 +- .../crank/src/instructions/queue_resume.rs | 2 +- .../crank/src/instructions/queue_update.rs | 2 +- .../crank/src/instructions/queue_withdraw.rs | 2 +- programs/crank/src/lib.rs | 6 ++-- programs/crank/src/state/queue.rs | 28 ++++++++----------- .../network/src/instructions/entry_close.rs | 2 +- .../network/src/instructions/initialize.rs | 2 +- 12 files changed, 33 insertions(+), 37 deletions(-) diff --git a/client/src/crank/instruction/queue_create.rs b/client/src/crank/instruction/queue_create.rs index bba777d05..9b0c157a4 100644 --- a/client/src/crank/instruction/queue_create.rs +++ b/client/src/crank/instruction/queue_create.rs @@ -12,8 +12,8 @@ use { pub fn queue_create( authority: Pubkey, - instruction: Instruction, - name: String, + id: String, + kickoff_instruction: Instruction, payer: Pubkey, queue: Pubkey, trigger: Trigger, @@ -27,8 +27,8 @@ pub fn queue_create( AccountMeta::new_readonly(system_program::ID, false), ], data: clockwork_crank::instruction::QueueCreate { - instruction: ClockworkInstructionData::from(instruction), - name, + id, + kickoff_instruction: ClockworkInstructionData::from(kickoff_instruction), trigger, } .data(), diff --git a/programs/crank/src/instructions/queue_crank.rs b/programs/crank/src/instructions/queue_crank.rs index 64cdf84ea..185557199 100644 --- a/programs/crank/src/instructions/queue_crank.rs +++ b/programs/crank/src/instructions/queue_crank.rs @@ -32,7 +32,7 @@ pub struct QueueCrank<'info> { seeds = [ SEED_QUEUE, queue.authority.as_ref(), - queue.name.as_bytes(), + queue.id.as_bytes(), ], bump, constraint = !queue.is_paused @ ClockworkError::PausedQueue diff --git a/programs/crank/src/instructions/queue_create.rs b/programs/crank/src/instructions/queue_create.rs index 8887f7a79..58c5e8e4f 100644 --- a/programs/crank/src/instructions/queue_create.rs +++ b/programs/crank/src/instructions/queue_create.rs @@ -6,7 +6,7 @@ use { #[derive(Accounts)] -#[instruction(instruction: InstructionData, name: String, trigger: Trigger)] +#[instruction(id: String, kickoff_instruction: InstructionData, trigger: Trigger)] pub struct QueueCreate<'info> { #[account()] pub authority: Signer<'info>, @@ -19,15 +19,15 @@ pub struct QueueCreate<'info> { seeds = [ SEED_QUEUE, authority.key().as_ref(), - name.as_bytes(), + id.as_bytes(), ], bump, payer = payer, space = vec![ 8, size_of::(), - instruction.try_to_vec()?.len(), - name.as_bytes().len(), + id.as_bytes().len(), + kickoff_instruction.try_to_vec()?.len(), trigger.try_to_vec()?.len() ].iter().sum() )] @@ -37,13 +37,13 @@ pub struct QueueCreate<'info> { pub system_program: Program<'info, System>, } -pub fn handler(ctx: Context, instruction: InstructionData, name: String, trigger: Trigger) -> Result<()> { +pub fn handler(ctx: Context, id: String, kickoff_instruction: InstructionData, trigger: Trigger) -> Result<()> { // Get accounts let authority = &ctx.accounts.authority; let queue = &mut ctx.accounts.queue; // Initialize the queue - queue.init(authority.key(), instruction, name, trigger)?; + queue.init(authority.key(), id, kickoff_instruction, trigger)?; Ok(()) } diff --git a/programs/crank/src/instructions/queue_delete.rs b/programs/crank/src/instructions/queue_delete.rs index 823fe8bd1..0f679eddb 100644 --- a/programs/crank/src/instructions/queue_delete.rs +++ b/programs/crank/src/instructions/queue_delete.rs @@ -17,7 +17,7 @@ pub struct QueueDelete<'info> { seeds = [ SEED_QUEUE, queue.authority.as_ref(), - queue.name.as_bytes(), + queue.id.as_bytes(), ], bump, has_one = authority, diff --git a/programs/crank/src/instructions/queue_pause.rs b/programs/crank/src/instructions/queue_pause.rs index 6db859104..96cd59aab 100644 --- a/programs/crank/src/instructions/queue_pause.rs +++ b/programs/crank/src/instructions/queue_pause.rs @@ -13,7 +13,7 @@ pub struct QueuePause<'info> { seeds = [ SEED_QUEUE, queue.authority.key().as_ref(), - queue.name.as_bytes(), + queue.id.as_bytes(), ], bump, has_one = authority diff --git a/programs/crank/src/instructions/queue_resume.rs b/programs/crank/src/instructions/queue_resume.rs index f407542dd..03a730095 100644 --- a/programs/crank/src/instructions/queue_resume.rs +++ b/programs/crank/src/instructions/queue_resume.rs @@ -13,7 +13,7 @@ pub struct QueueResume<'info> { seeds = [ SEED_QUEUE, queue.authority.key().as_ref(), - queue.name.as_bytes(), + queue.id.as_bytes(), ], bump, has_one = authority diff --git a/programs/crank/src/instructions/queue_update.rs b/programs/crank/src/instructions/queue_update.rs index f27ac2a8d..bc0783c66 100644 --- a/programs/crank/src/instructions/queue_update.rs +++ b/programs/crank/src/instructions/queue_update.rs @@ -15,7 +15,7 @@ pub struct QueueUpdate<'info> { seeds = [ SEED_QUEUE, queue.authority.key().as_ref(), - queue.name.as_bytes(), + queue.id.as_bytes(), ], bump, has_one = authority, diff --git a/programs/crank/src/instructions/queue_withdraw.rs b/programs/crank/src/instructions/queue_withdraw.rs index 64d996425..77925e620 100644 --- a/programs/crank/src/instructions/queue_withdraw.rs +++ b/programs/crank/src/instructions/queue_withdraw.rs @@ -17,7 +17,7 @@ pub struct QueueWithdraw<'info> { seeds = [ SEED_QUEUE, queue.authority.key().as_ref(), - queue.name.as_bytes(), + queue.id.as_bytes(), ], bump, has_one = authority, diff --git a/programs/crank/src/lib.rs b/programs/crank/src/lib.rs index 67587d8a5..eff65e5db 100644 --- a/programs/crank/src/lib.rs +++ b/programs/crank/src/lib.rs @@ -30,11 +30,11 @@ pub mod clockwork_crank { pub fn queue_create( ctx: Context, - instruction: InstructionData, - name: String, + id: String, + kickoff_instruction: InstructionData, trigger: Trigger, ) -> Result<()> { - queue_create::handler(ctx, instruction, name, trigger) + queue_create::handler(ctx, id, kickoff_instruction, trigger) } pub fn queue_delete(ctx: Context) -> Result<()> { diff --git a/programs/crank/src/state/queue.rs b/programs/crank/src/state/queue.rs index 80ead869d..6f3233152 100644 --- a/programs/crank/src/state/queue.rs +++ b/programs/crank/src/state/queue.rs @@ -27,20 +27,16 @@ pub struct Queue { pub authority: Pubkey, pub created_at: ClockData, pub exec_context: Option, + pub id: String, pub is_paused: bool, pub kickoff_instruction: InstructionData, - pub name: String, pub next_instruction: Option, pub trigger: Trigger, } impl Queue { - pub fn pubkey(authority: Pubkey, name: String) -> Pubkey { - Pubkey::find_program_address( - &[SEED_QUEUE, authority.as_ref(), name.as_bytes()], - &crate::ID, - ) - .0 + pub fn pubkey(authority: Pubkey, id: String) -> Pubkey { + Pubkey::find_program_address(&[SEED_QUEUE, authority.as_ref(), id.as_bytes()], &crate::ID).0 } } @@ -54,13 +50,13 @@ impl TryFrom> for Queue { impl Hash for Queue { fn hash(&self, state: &mut H) { self.authority.hash(state); - self.name.hash(state); + self.id.hash(state); } } impl PartialEq for Queue { fn eq(&self, other: &Self) -> bool { - self.authority.eq(&other.authority) && self.name.eq(&other.name) + self.authority.eq(&other.authority) && self.id.eq(&other.id) } } @@ -74,8 +70,8 @@ pub trait QueueAccount { fn init( &mut self, authority: Pubkey, - instruction: InstructionData, - name: String, + id: String, + kickoff_instruction: InstructionData, trigger: Trigger, ) -> Result<()>; @@ -88,16 +84,16 @@ impl QueueAccount for Account<'_, Queue> { fn init( &mut self, authority: Pubkey, - instruction: InstructionData, - name: String, + id: String, + kickoff_instruction: InstructionData, trigger: Trigger, ) -> Result<()> { self.authority = authority.key(); self.created_at = Clock::get().unwrap().into(); self.exec_context = None; - self.kickoff_instruction = instruction; + self.id = id; self.is_paused = false; - self.name = name; + self.kickoff_instruction = kickoff_instruction; self.next_instruction = None; self.trigger = trigger; Ok(()) @@ -138,7 +134,7 @@ impl QueueAccount for Account<'_, Queue> { &[&[ SEED_QUEUE, self.authority.as_ref(), - self.name.as_bytes(), + self.id.as_bytes(), &[bump], ]], )?; diff --git a/programs/network/src/instructions/entry_close.rs b/programs/network/src/instructions/entry_close.rs index 91f445d77..ccd5a5623 100644 --- a/programs/network/src/instructions/entry_close.rs +++ b/programs/network/src/instructions/entry_close.rs @@ -32,7 +32,7 @@ pub struct EntryClose<'info> { )] pub snapshot: Account<'info, Snapshot>, - #[account(mut, has_one = authority, constraint = snapshot_queue.name.eq("snapshot"))] + #[account(mut, has_one = authority, constraint = snapshot_queue.id.eq("snapshot"))] pub snapshot_queue: Account<'info, Queue>, } diff --git a/programs/network/src/instructions/initialize.rs b/programs/network/src/instructions/initialize.rs index 61e0d9905..a736642c2 100644 --- a/programs/network/src/instructions/initialize.rs +++ b/programs/network/src/instructions/initialize.rs @@ -127,8 +127,8 @@ pub fn handler<'info>(ctx: Context<'_, '_, '_, 'info, Initialize<'info>>) -> Res }, &[&[SEED_AUTHORITY, &[bump]]] ), - snapshot_kickoff_ix.into(), "snapshot".into(), + snapshot_kickoff_ix.into(), Trigger::Cron { schedule: "0 * * * * * *".into() } )?;