cli cleanup
This commit is contained in:
parent
de42ea8ad2
commit
1fe1eebb77
|
@ -98,7 +98,7 @@
|
|||
"@oclif/plugin-warn-if-update-available": "^1.7.3",
|
||||
"@project-serum/anchor": "^0.24.2",
|
||||
"@solana/spl-token": "^0.1.8",
|
||||
"@solana/web3.js": "^1.39.1",
|
||||
"@solana/web3.js": "^1.42.0",
|
||||
"@switchboard-xyz/sbv2-utils": "^0.0.10",
|
||||
"@switchboard-xyz/switchboard-v2": "0.0.97",
|
||||
"assert": "^2.0.0",
|
||||
|
|
|
@ -4,7 +4,6 @@ import { flags } from "@oclif/command";
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import * as spl from "@solana/spl-token";
|
||||
import {
|
||||
AccountInfo,
|
||||
Keypair,
|
||||
SystemProgram,
|
||||
TransactionInstruction,
|
||||
|
@ -15,7 +14,6 @@ import {
|
|||
prettyPrintCrank,
|
||||
prettyPrintOracle,
|
||||
prettyPrintQueue,
|
||||
promiseWithTimeout,
|
||||
} from "@switchboard-xyz/sbv2-utils";
|
||||
import {
|
||||
CrankAccount,
|
||||
|
@ -30,7 +28,7 @@ import Big from "big.js";
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
import BaseCommand from "../../BaseCommand";
|
||||
import { sleep, verifyProgramHasPayer } from "../../utils";
|
||||
import { verifyProgramHasPayer } from "../../utils";
|
||||
|
||||
export default class QueueCreate extends BaseCommand {
|
||||
static description = "create a custom queue";
|
||||
|
@ -361,40 +359,23 @@ export default class QueueCreate extends BaseCommand {
|
|||
})
|
||||
);
|
||||
|
||||
let queueWs: number;
|
||||
const customQueuePromise = new Promise((resolve: (result: any) => void) => {
|
||||
queueWs = this.program.provider.connection.onAccountChange(
|
||||
queueAccount.publicKey,
|
||||
(accountInfo: AccountInfo<Buffer>, slot) => {
|
||||
const accountCoder = new anchor.BorshAccountsCoder(this.program.idl);
|
||||
resolve(
|
||||
accountCoder.decode("OracleQueueAccountData", accountInfo.data)
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const createAccountSignatures = packAndSend(
|
||||
const createAccountSignatures = await packAndSend(
|
||||
this.program,
|
||||
[setupQueueTxns, finalTransactions],
|
||||
signers,
|
||||
payerKeypair.publicKey
|
||||
).catch((error) => {
|
||||
this.logger.error(error);
|
||||
this.exit(1);
|
||||
throw error;
|
||||
});
|
||||
|
||||
const queueData = await promiseWithTimeout(
|
||||
25_000,
|
||||
customQueuePromise
|
||||
).finally(() => {
|
||||
try {
|
||||
if (queueWs) {
|
||||
this.logger.debug(`closing ws ${queueWs}`);
|
||||
this.program.provider.connection.removeAccountChangeListener(queueWs);
|
||||
}
|
||||
} catch {}
|
||||
});
|
||||
let queueData: any;
|
||||
try {
|
||||
queueData = await queueAccount.loadData();
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (outputPath) {
|
||||
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
||||
|
@ -450,14 +431,7 @@ export default class QueueCreate extends BaseCommand {
|
|||
this.logger.info(
|
||||
await prettyPrintOracle(oracle.oracleAccount, undefined, true, 30)
|
||||
);
|
||||
} catch {
|
||||
await sleep(1000);
|
||||
try {
|
||||
this.logger.info(
|
||||
await prettyPrintOracle(oracle.oracleAccount, undefined, true, 30)
|
||||
);
|
||||
} catch {}
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@switchboard-xyz/sbv2-utils",
|
||||
"version": "0.0.10",
|
||||
"version": "0.0.11",
|
||||
"description": "some basic utility functions when working with switchboard-v2",
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
@ -34,7 +34,7 @@
|
|||
"@project-serum/anchor": "^0.24.2",
|
||||
"@saberhq/token-utils": "^1.12.68",
|
||||
"@solana/spl-token": "^0.1.8",
|
||||
"@solana/web3.js": "^1.39.1",
|
||||
"@solana/web3.js": "^1.42.0",
|
||||
"@switchboard-xyz/switchboard-v2": "^0.0.97",
|
||||
"big.js": "^6.1.1",
|
||||
"chalk": "4",
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
import * as anchor from "@project-serum/anchor";
|
||||
import {
|
||||
Keypair,
|
||||
PublicKey,
|
||||
SystemProgram,
|
||||
TransactionInstruction,
|
||||
} from "@solana/web3.js";
|
||||
import {
|
||||
OracleJob,
|
||||
ProgramStateAccount,
|
||||
programWallet,
|
||||
} from "@switchboard-xyz/switchboard-v2";
|
||||
|
||||
export interface SwitchboardInstructionResult {
|
||||
ixns: (TransactionInstruction | Promise<TransactionInstruction>)[];
|
||||
signers: Keypair[];
|
||||
}
|
||||
|
||||
export class SwitchboardTransaction {
|
||||
program: anchor.Program;
|
||||
|
||||
payerKeypair: Keypair;
|
||||
|
||||
programStateAccount: ProgramStateAccount;
|
||||
|
||||
// programState: Promise<any>;
|
||||
|
||||
// programMint: Promise<spl.Token>;
|
||||
|
||||
stateBump: number;
|
||||
|
||||
constructor(program: anchor.Program) {
|
||||
this.program = program;
|
||||
this.payerKeypair = programWallet(program);
|
||||
const [programStateAccount, stateBump] =
|
||||
ProgramStateAccount.fromSeed(program);
|
||||
this.programStateAccount = programStateAccount;
|
||||
this.stateBump = stateBump;
|
||||
// this.programState = programStateAccount.loadData();
|
||||
// this.programMint = programStateAccount.getTokenMint();
|
||||
}
|
||||
|
||||
createInitJobInstruction(
|
||||
job: OracleJob,
|
||||
rentExemption: number,
|
||||
authorWallet: PublicKey,
|
||||
params: {
|
||||
name?: string;
|
||||
metadata?: string;
|
||||
authority?: PublicKey;
|
||||
expiration?: anchor.BN;
|
||||
variables?: string[];
|
||||
}
|
||||
): SwitchboardInstructionResult {
|
||||
const jobKeypair = Keypair.generate();
|
||||
const jobData = Buffer.from(
|
||||
OracleJob.encodeDelimited(
|
||||
OracleJob.create({
|
||||
tasks: job.tasks,
|
||||
})
|
||||
).finish()
|
||||
);
|
||||
const size =
|
||||
280 + jobData.length + (params.variables?.join("")?.length ?? 0);
|
||||
|
||||
const ixns: (TransactionInstruction | Promise<TransactionInstruction>)[] = [
|
||||
SystemProgram.createAccount({
|
||||
fromPubkey: this.payerKeypair.publicKey,
|
||||
newAccountPubkey: jobKeypair.publicKey,
|
||||
space: size,
|
||||
lamports: rentExemption,
|
||||
programId: this.program.programId,
|
||||
}),
|
||||
this.program.methods
|
||||
.jobInit({
|
||||
name: Buffer.from(params.name ?? ""),
|
||||
data: jobData,
|
||||
variables:
|
||||
params.variables?.map((item) => Buffer.from("")) ??
|
||||
new Array<Buffer>(),
|
||||
stateBump: this.stateBump,
|
||||
})
|
||||
.accounts({
|
||||
job: jobKeypair.publicKey,
|
||||
authorWallet: authorWallet,
|
||||
authority: this.payerKeypair.publicKey,
|
||||
programState: this.programStateAccount.publicKey,
|
||||
})
|
||||
// .signers([jobKeypair])
|
||||
.instruction(),
|
||||
];
|
||||
|
||||
return {
|
||||
ixns,
|
||||
signers: [jobKeypair],
|
||||
};
|
||||
}
|
||||
}
|
|
@ -274,9 +274,15 @@ export async function prettyPrintQueue(
|
|||
data.unpermissionedFeedsEnabled.toString(),
|
||||
SPACING
|
||||
) + "\r\n";
|
||||
outputString +=
|
||||
chalkString(
|
||||
"unpermissionedVrfEnabled",
|
||||
data.unpermissionedVrfEnabled.toString(),
|
||||
SPACING
|
||||
) + "\r\n";
|
||||
outputString += chalkString(
|
||||
"unpermissionedVrfEnabled",
|
||||
data.unpermissionedVrfEnabled.toString(),
|
||||
data.enableBufferRelayers?.toString() ?? "",
|
||||
SPACING
|
||||
);
|
||||
|
||||
|
|
4766
switchboard_v2.json
4766
switchboard_v2.json
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue