Skip to content

Commit 8691cf1

Browse files
committed
Readme, more lint
1 parent 63f40fc commit 8691cf1

File tree

3 files changed

+61
-15
lines changed

3 files changed

+61
-15
lines changed

README.md

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,16 @@ You can see an example of this in the [remote-server-example](./solana-programs/
125125
You can queue such a task by using `remoteV0` instead of `compileV0` in the `QueueTaskV0` instruction.
126126

127127
```typescript
128-
await program.methods
129-
.queueTaskV0({
130-
id: taskId,
131-
trigger: { now: {} },
132-
transaction: {
133-
remoteV0: {
134-
url: "http://localhost:3002/remote",
135-
signer: me,
136-
},
128+
await program.methods.queueTaskV0({
129+
id: taskId,
130+
trigger: { now: {} },
131+
transaction: {
132+
remoteV0: {
133+
url: "http://localhost:3002/remote",
134+
signer: me,
137135
},
138-
})
136+
},
137+
});
139138
```
140139

141140
### Monitoring the Task Queue
@@ -150,7 +149,6 @@ Note that this will only show you tasks that have not been run. Tasks that have
150149

151150
If a task is active but has not yet been run, the cli will display a simulation result for the task. This is to help you debug the task if for some reason it is not running.
152151

153-
154152
### Cron Tasks
155153

156154
Sometimes, it's helpful to run a task on a specific schedule. You can do this by creating a cron job. A cron job will queue tasks onto a task queue at a specific time. The following example will queue a task every minute. Note that you will need to keep the cron funded so that it can, in turn, fund the task queue for each task it creates.
@@ -161,6 +159,54 @@ tuktuk -u <your-solana-url> cron create --name <your-cron-job-name> --task-queue
161159

162160
A single cron job can queue multiple transactions. You can add transactions to a cron job by using the `cron-transaction` command. To add a normal transaction to a cron job, it is easier to write a script:
163161

162+
```typescript
163+
import {
164+
compileTransaction,
165+
taskKey,
166+
customSignerKey,
167+
tuktukConfigKey
168+
} from "@helium/tuktuk-sdk";
169+
import { init as initCron, cronJobKey } from "@helium/cron-sdk";
170+
171+
const cronProgram = await initCron(provider);
172+
const cronJob = cronJobKey(provider.wallet.publicKey, 0)[0]
173+
const taskQueue = taskQueueKey(tuktukConfigKey()[0], Buffer.from("my queue name"));
174+
const taskId = 0;
175+
const task = taskKey(taskQueue, taskId)[0];
176+
177+
// Create a PDA wallet associated with the task queue
178+
const [wallet, bump] = customSignerKey(taskQueue, [Buffer.from("test")]);
179+
const instructions: TransactionInstruction[] = [
180+
new TransactionInstruction({
181+
keys: [{ pubkey: wallet, isSigner: true, isWritable: true }],
182+
data: Buffer.from("I'm a remote transaction!", "utf-8"),
183+
programId: new PublicKey(
184+
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
185+
),
186+
}),
187+
];
188+
189+
// Compile the instructions and PDA into the args expected by the tuktuk program
190+
const ({ transaction, remainingAccounts } = await compileTransaction(
191+
instructions,
192+
[[Buffer.from("test"), bumpBuffer]]
193+
));
194+
195+
await cronProgram.methods
196+
.addCronTransactionV0({
197+
index: 0,
198+
transactionSource: {
199+
compiledV0: [transaction],
200+
},
201+
})
202+
.accounts({
203+
payer: me,
204+
cronJob,
205+
cronJobTransaction: cronJobTransactionKey(cronJob, 0)[0],
206+
})
207+
.remainingAccounts(remainingAccounts)
208+
.rpc({ skipPreflight: true });
209+
```
164210

165211
To add a remote transaction, you can use the `create-remote` command:
166212

@@ -198,4 +244,4 @@ Then you can close the cron job itself:
198244

199245
```
200246
tuktuk -u <your-solana-url> cron close --cron-name <your-cron-job-name>
201-
```
247+
```

tuktuk-cli/src/cmd/cron_transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl CronTransactionCmd {
7171
index: *index,
7272
transaction_source: TransactionSourceV0::RemoteV0 {
7373
url: url.to_string(),
74-
signer: signer.clone(),
74+
signer: *signer,
7575
},
7676
},
7777
)?;
@@ -89,7 +89,7 @@ impl CronTransactionCmd {
8989
cron_job: cron_job_key,
9090
transaction_source: Some(TransactionSource::RemoteV0 {
9191
url: url.to_string(),
92-
signer: signer.clone(),
92+
signer: *signer,
9393
}),
9494
})?;
9595
}

tuktuk-cli/src/cmd/task_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl TaskQueueCmd {
9696
task_queue_key: &Pubkey,
9797
amount: u64,
9898
) -> Result<Instruction> {
99-
let ix = transfer(&client.payer.pubkey(), &task_queue_key, amount);
99+
let ix = transfer(&client.payer.pubkey(), task_queue_key, amount);
100100

101101
Ok(ix)
102102
}

0 commit comments

Comments
 (0)