Skip to content

Commit a8f2c01

Browse files
authored
Add custom signing key to sdk (#60)
* Add custom signing key to sdk * Remove helium specific task queue ID * Add next_available_task_ids, expose program * Fix up queue id and random task id fetches * adjust name
1 parent aeedaf4 commit a8f2c01

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

tuktuk-cli/src/cmd/task_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use solana_sdk::{
66
instruction::Instruction, pubkey::Pubkey, signer::Signer, system_instruction::transfer,
77
};
88
use tuktuk::task_queue_name_mapping_key;
9-
use tuktuk_program::{TaskQueueV0, TuktukConfigV0};
9+
use tuktuk_program::TaskQueueV0;
1010
use tuktuk_sdk::prelude::*;
1111

1212
use crate::{

tuktuk-sdk/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub mod pubsub_client;
77
pub mod tuktuk;
88
pub mod watcher;
99

10+
pub use tuktuk_program;
11+
1012
pub mod prelude {
1113
pub use anchor_lang::prelude::*;
1214

tuktuk-sdk/src/tuktuk.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ pub fn task_queue_name_mapping_key(config_key: &Pubkey, name: &str) -> Pubkey {
3232
.0
3333
}
3434

35+
pub fn custom_signer_key(task_queue: &Pubkey, signer_seeds: &[&[u8]]) -> Pubkey {
36+
Pubkey::find_program_address(
37+
&[&[b"custom", task_queue.as_ref()], signer_seeds].concat(),
38+
&tuktuk::ID,
39+
)
40+
.0
41+
}
42+
3543
#[derive(Debug)]
3644
pub struct TaskQueueUpdate {
3745
pub task_queues: Vec<(Pubkey, Option<TaskQueueV0>)>,
@@ -380,7 +388,23 @@ pub mod task_queue {
380388

381389
use self::tuktuk::types::InitializeTaskQueueArgsV0;
382390
use super::*;
383-
use crate::client::GetAnchorAccount;
391+
use crate::{
392+
client::GetAnchorAccount,
393+
compiled_transaction::next_available_task_ids_excluding_in_progress,
394+
};
395+
396+
pub fn next_available_task_ids(
397+
task_queue: &tuktuk::accounts::TaskQueueV0,
398+
n: u8,
399+
) -> Result<Vec<u16>, Error> {
400+
next_available_task_ids_excluding_in_progress(
401+
task_queue.capacity,
402+
&task_queue.task_bitmap,
403+
n,
404+
&Default::default(),
405+
rand::random_range(0..task_queue.task_bitmap.len()),
406+
)
407+
}
384408

385409
pub fn key(config_key: &Pubkey, next_task_queue_id: u32) -> Pubkey {
386410
Pubkey::find_program_address(
@@ -406,6 +430,10 @@ pub mod task_queue {
406430
.0
407431
}
408432

433+
pub fn queue_authority_key(program_id: &Pubkey) -> Pubkey {
434+
Pubkey::find_program_address(&[b"queue_authority"], program_id).0
435+
}
436+
409437
pub fn keys(config_key: &Pubkey, config: &TuktukConfigV0) -> Result<Vec<Pubkey>, Error> {
410438
let queue_ids = 0..config.next_task_queue_id;
411439
let queue_keys = queue_ids.map(|id| self::key(config_key, id)).collect_vec();

0 commit comments

Comments
 (0)