Skip to content

Commit

Permalink
Rename queue.name to queue.id
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Garfield committed Sep 7, 2022
1 parent 40ec7cf commit 946eeab
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 37 deletions.
8 changes: 4 additions & 4 deletions client/src/crank/instruction/queue_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion programs/crank/src/instructions/queue_crank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions programs/crank/src/instructions/queue_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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::<Queue>(),
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()
)]
Expand All @@ -37,13 +37,13 @@ pub struct QueueCreate<'info> {
pub system_program: Program<'info, System>,
}

pub fn handler(ctx: Context<QueueCreate>, instruction: InstructionData, name: String, trigger: Trigger) -> Result<()> {
pub fn handler(ctx: Context<QueueCreate>, 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(())
}
2 changes: 1 addition & 1 deletion programs/crank/src/instructions/queue_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion programs/crank/src/instructions/queue_pause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion programs/crank/src/instructions/queue_resume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion programs/crank/src/instructions/queue_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion programs/crank/src/instructions/queue_withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions programs/crank/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ pub mod clockwork_crank {

pub fn queue_create(
ctx: Context<QueueCreate>,
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<QueueDelete>) -> Result<()> {
Expand Down
28 changes: 12 additions & 16 deletions programs/crank/src/state/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@ pub struct Queue {
pub authority: Pubkey,
pub created_at: ClockData,
pub exec_context: Option<ExecContext>,
pub id: String,
pub is_paused: bool,
pub kickoff_instruction: InstructionData,
pub name: String,
pub next_instruction: Option<InstructionData>,
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
}
}

Expand All @@ -54,13 +50,13 @@ impl TryFrom<Vec<u8>> for Queue {
impl Hash for Queue {
fn hash<H: Hasher>(&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)
}
}

Expand All @@ -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<()>;

Expand All @@ -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(())
Expand Down Expand Up @@ -138,7 +134,7 @@ impl QueueAccount for Account<'_, Queue> {
&[&[
SEED_QUEUE,
self.authority.as_ref(),
self.name.as_bytes(),
self.id.as_bytes(),
&[bump],
]],
)?;
Expand Down
2 changes: 1 addition & 1 deletion programs/network/src/instructions/entry_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}

Expand Down
2 changes: 1 addition & 1 deletion programs/network/src/instructions/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
)?;

Expand Down

0 comments on commit 946eeab

Please sign in to comment.