cli cleanup

This commit is contained in:
Conner Gallagher 2022-05-19 11:21:56 -06:00
parent de42ea8ad2
commit 1fe1eebb77
6 changed files with 21 additions and 4905 deletions

View File

@ -98,7 +98,7 @@
"@oclif/plugin-warn-if-update-available": "^1.7.3", "@oclif/plugin-warn-if-update-available": "^1.7.3",
"@project-serum/anchor": "^0.24.2", "@project-serum/anchor": "^0.24.2",
"@solana/spl-token": "^0.1.8", "@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/sbv2-utils": "^0.0.10",
"@switchboard-xyz/switchboard-v2": "0.0.97", "@switchboard-xyz/switchboard-v2": "0.0.97",
"assert": "^2.0.0", "assert": "^2.0.0",

View File

@ -4,7 +4,6 @@ import { flags } from "@oclif/command";
import * as anchor from "@project-serum/anchor"; import * as anchor from "@project-serum/anchor";
import * as spl from "@solana/spl-token"; import * as spl from "@solana/spl-token";
import { import {
AccountInfo,
Keypair, Keypair,
SystemProgram, SystemProgram,
TransactionInstruction, TransactionInstruction,
@ -15,7 +14,6 @@ import {
prettyPrintCrank, prettyPrintCrank,
prettyPrintOracle, prettyPrintOracle,
prettyPrintQueue, prettyPrintQueue,
promiseWithTimeout,
} from "@switchboard-xyz/sbv2-utils"; } from "@switchboard-xyz/sbv2-utils";
import { import {
CrankAccount, CrankAccount,
@ -30,7 +28,7 @@ import Big from "big.js";
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import BaseCommand from "../../BaseCommand"; import BaseCommand from "../../BaseCommand";
import { sleep, verifyProgramHasPayer } from "../../utils"; import { verifyProgramHasPayer } from "../../utils";
export default class QueueCreate extends BaseCommand { export default class QueueCreate extends BaseCommand {
static description = "create a custom queue"; static description = "create a custom queue";
@ -361,40 +359,23 @@ export default class QueueCreate extends BaseCommand {
}) })
); );
let queueWs: number; const createAccountSignatures = await packAndSend(
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(
this.program, this.program,
[setupQueueTxns, finalTransactions], [setupQueueTxns, finalTransactions],
signers, signers,
payerKeypair.publicKey payerKeypair.publicKey
).catch((error) => { ).catch((error) => {
this.logger.error(error); this.logger.error(error);
this.exit(1); throw error;
}); });
const queueData = await promiseWithTimeout( let queueData: any;
25_000, try {
customQueuePromise queueData = await queueAccount.loadData();
).finally(() => { } catch (error) {
try { this.logger.error(error);
if (queueWs) { throw error;
this.logger.debug(`closing ws ${queueWs}`); }
this.program.provider.connection.removeAccountChangeListener(queueWs);
}
} catch {}
});
if (outputPath) { if (outputPath) {
fs.mkdirSync(path.dirname(outputPath), { recursive: true }); fs.mkdirSync(path.dirname(outputPath), { recursive: true });
@ -450,14 +431,7 @@ export default class QueueCreate extends BaseCommand {
this.logger.info( this.logger.info(
await prettyPrintOracle(oracle.oracleAccount, undefined, true, 30) await prettyPrintOracle(oracle.oracleAccount, undefined, true, 30)
); );
} catch { } catch {}
await sleep(1000);
try {
this.logger.info(
await prettyPrintOracle(oracle.oracleAccount, undefined, true, 30)
);
} catch {}
}
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@switchboard-xyz/sbv2-utils", "name": "@switchboard-xyz/sbv2-utils",
"version": "0.0.10", "version": "0.0.11",
"description": "some basic utility functions when working with switchboard-v2", "description": "some basic utility functions when working with switchboard-v2",
"author": "", "author": "",
"license": "ISC", "license": "ISC",
@ -34,7 +34,7 @@
"@project-serum/anchor": "^0.24.2", "@project-serum/anchor": "^0.24.2",
"@saberhq/token-utils": "^1.12.68", "@saberhq/token-utils": "^1.12.68",
"@solana/spl-token": "^0.1.8", "@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", "@switchboard-xyz/switchboard-v2": "^0.0.97",
"big.js": "^6.1.1", "big.js": "^6.1.1",
"chalk": "4", "chalk": "4",

View File

@ -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],
};
}
}

View File

@ -274,9 +274,15 @@ export async function prettyPrintQueue(
data.unpermissionedFeedsEnabled.toString(), data.unpermissionedFeedsEnabled.toString(),
SPACING SPACING
) + "\r\n"; ) + "\r\n";
outputString +=
chalkString(
"unpermissionedVrfEnabled",
data.unpermissionedVrfEnabled.toString(),
SPACING
) + "\r\n";
outputString += chalkString( outputString += chalkString(
"unpermissionedVrfEnabled", "unpermissionedVrfEnabled",
data.unpermissionedVrfEnabled.toString(), data.enableBufferRelayers?.toString() ?? "",
SPACING SPACING
); );

File diff suppressed because it is too large Load Diff