Skip to content

Commit

Permalink
♻️ Code Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielePicco committed Oct 4, 2024
1 parent e4f92c5 commit 7947a95
Show file tree
Hide file tree
Showing 32 changed files with 535 additions and 568 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

24 changes: 0 additions & 24 deletions .eslintrc.yml

This file was deleted.

14 changes: 7 additions & 7 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Ignore all files in the generated types directory
clients/bolt-sdk/src/generated/types/world.ts

# You can add more patterns here
.anchor
.bolt
.DS_Store
target
node_modules
dist

clients/bolt-sdk/idl/world.ts
.anchor
build
test-ledger
target
clients/bolt-sdk/lib
7 changes: 0 additions & 7 deletions .prettierrc

This file was deleted.

42 changes: 21 additions & 21 deletions cli/npm-package/bolt.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env node
import fs from 'fs';
import { spawn, spawnSync } from 'child_process';
import path from 'path';
import { arch, platform } from 'os';
import { version } from './package.json';
import fs from "fs";
import { spawn, spawnSync } from "child_process";
import path from "path";
import { arch, platform } from "os";
import { version } from "./package.json";

const PACKAGE_VERSION = `bolt-cli ${version}`;

function getBinaryVersion(location: string): [string | null, string | null] {
const result = spawnSync(location, ['--version']);
const result = spawnSync(location, ["--version"]);
const error: string | null =
(result.error && result.error.toString()) ||
(result.stderr.length > 0 && result.stderr.toString().trim()) ||
Expand All @@ -18,26 +18,26 @@ function getBinaryVersion(location: string): [string | null, string | null] {

function getExePath(): string {
let os: string = platform();
let extension = '';
if (['win32', 'cygwin'].includes(os)) {
os = 'windows';
extension = '.exe';
let extension = "";
if (["win32", "cygwin"].includes(os)) {
os = "windows";
extension = ".exe";
}
const binaryName = `@magicblock-labs/bolt-cli-${os}-${arch()}/bin/bolt${extension}`;
try {
return require.resolve(binaryName);
} catch (e) {
throw new Error(
`Couldn't find application binary inside node_modules for ${os}-${arch()}`,
`Couldn't find application binary inside node_modules for ${os}-${arch()}`
);
}
}

function runBolt(location: string): void {
const args = process.argv.slice(2);
const bolt = spawn(location, args, { stdio: 'inherit' });
bolt.on('exit', (code: number | null, signal: NodeJS.Signals | null) => {
process.on('exit', () => {
const bolt = spawn(location, args, { stdio: "inherit" });
bolt.on("exit", (code: number | null, signal: NodeJS.Signals | null) => {
process.on("exit", () => {
if (signal) {
process.kill(process.pid, signal);
} else if (code !== null) {
Expand All @@ -46,9 +46,9 @@ function runBolt(location: string): void {
});
});

process.on('SIGINT', () => {
bolt.kill('SIGINT');
bolt.kill('SIGTERM');
process.on("SIGINT", () => {
bolt.kill("SIGINT");
bolt.kill("SIGTERM");
});
}

Expand All @@ -59,8 +59,8 @@ function tryPackageBolt(): boolean {
return true;
} catch (e) {
console.error(
'Failed to run bolt from package:',
e instanceof Error ? e.message : e,
"Failed to run bolt from package:",
e instanceof Error ? e.message : e
);
return false;
}
Expand All @@ -80,7 +80,7 @@ function trySystemBolt(): void {

if (!absolutePath) {
console.error(
`Could not find globally installed bolt, please install with cargo.`,
`Could not find globally installed bolt, please install with cargo.`
);
process.exit(1);
}
Expand All @@ -94,7 +94,7 @@ function trySystemBolt(): void {
}
if (binaryVersion !== PACKAGE_VERSION) {
console.error(
`Globally installed bolt version is not correct. Expected "${PACKAGE_VERSION}", found "${binaryVersion}".`,
`Globally installed bolt version is not correct. Expected "${PACKAGE_VERSION}", found "${binaryVersion}".`
);
return;
}
Expand Down
16 changes: 8 additions & 8 deletions clients/bolt-sdk/.solitarc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const path = require('path');
const programDir = path.join(__dirname, '../../', 'programs', 'world');
const idlDir = path.join(__dirname, 'idl');
const sdkDir = path.join(__dirname, 'src', 'generated');
const binaryInstallDir = path.join(__dirname, '.crates');
const path = require("path");
const programDir = path.join(__dirname, "../../", "programs", "world");
const idlDir = path.join(__dirname, "idl");
const sdkDir = path.join(__dirname, "src", "generated");
const binaryInstallDir = path.join(__dirname, ".crates");

module.exports = {
idlGenerator: 'anchor',
programName: 'world',
programId: 'WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n',
idlGenerator: "anchor",
programName: "world",
programId: "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n",
removeExistingIdl: false,
idlDir,
sdkDir,
Expand Down
14 changes: 7 additions & 7 deletions clients/bolt-sdk/src/delegation/allow_undelegation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as beet from '@metaplex-foundation/beet';
import * as web3 from '@solana/web3.js';
import * as beet from "@metaplex-foundation/beet";
import * as web3 from "@solana/web3.js";
import {
DelegateAccounts,
DELEGATION_PROGRAM_ID,
} from '@magicblock-labs/ephemeral-rollups-sdk';
} from "@magicblock-labs/ephemeral-rollups-sdk";

export const allowUndelegationStruct = new beet.BeetArgsStruct<{
instructionDiscriminator: number[] /* size: 8 */;
}>(
[['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)]],
'allowUndelegationInstructionArgs',
[["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)]],
"allowUndelegationInstructionArgs"
);

export interface AllowUndelegationInstructionAccounts {
Expand All @@ -27,15 +27,15 @@ export const allowUndelegateInstructionDiscriminator = [
*/

export function createAllowUndelegationInstruction(
accounts: AllowUndelegationInstructionAccounts,
accounts: AllowUndelegationInstructionAccounts
) {
const [data] = allowUndelegationStruct.serialize({
instructionDiscriminator: allowUndelegateInstructionDiscriminator,
});

const { delegationPda, delegationMetadata, bufferPda } = DelegateAccounts(
accounts.delegatedAccount,
accounts.ownerProgram,
accounts.ownerProgram
);

const keys: web3.AccountMeta[] = [
Expand Down
24 changes: 12 additions & 12 deletions clients/bolt-sdk/src/delegation/delegate.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as beet from '@metaplex-foundation/beet';
import * as web3 from '@solana/web3.js';
import * as beet from "@metaplex-foundation/beet";
import * as web3 from "@solana/web3.js";
import {
DelegateAccounts,
DELEGATION_PROGRAM_ID,
} from '@magicblock-labs/ephemeral-rollups-sdk';
import { FindComponentPda } from '../index';
} from "@magicblock-labs/ephemeral-rollups-sdk";
import { FindComponentPda } from "../index";
import {
type PublicKey,
Transaction,
type TransactionInstruction,
} from '@solana/web3.js';
} from "@solana/web3.js";

export interface DelegateInstructionArgs {
validUntil: beet.bignum;
Expand All @@ -22,11 +22,11 @@ export const delegateStruct = new beet.FixableBeetArgsStruct<
}
>(
[
['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)],
['validUntil', beet.i64],
['commitFrequencyMs', beet.u32],
["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
["validUntil", beet.i64],
["commitFrequencyMs", beet.u32],
],
'DelegateInstructionArgs',
"DelegateInstructionArgs"
);

/**
Expand Down Expand Up @@ -58,7 +58,7 @@ export function createDelegateInstruction(
accounts: DelegateInstructionAccounts,
validUntil: beet.bignum = 0,
commitFrequencyMs: number = 30000,
programId = accounts.ownerProgram,
programId = accounts.ownerProgram
) {
const [data] = delegateStruct.serialize({
instructionDiscriminator: delegateInstructionDiscriminator,
Expand All @@ -68,7 +68,7 @@ export function createDelegateInstruction(

const { delegationPda, delegationMetadata, bufferPda } = DelegateAccounts(
accounts.account,
accounts.ownerProgram,
accounts.ownerProgram
);

const keys: web3.AccountMeta[] = [
Expand Down Expand Up @@ -144,7 +144,7 @@ export async function DelegateComponent({
payer,
entity,
componentId,
seed = '',
seed = "",
buffer,
delegationRecord,
delegationMetadata,
Expand Down
12 changes: 6 additions & 6 deletions clients/bolt-sdk/src/delegation/undelegate.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as beet from '@metaplex-foundation/beet';
import * as web3 from '@solana/web3.js';
import * as beet from "@metaplex-foundation/beet";
import * as web3 from "@solana/web3.js";
import {
MAGIC_CONTEXT_ID,
MAGIC_PROGRAM_ID,
} from '@magicblock-labs/ephemeral-rollups-sdk';
} from "@magicblock-labs/ephemeral-rollups-sdk";

export const undelegateStruct = new beet.BeetArgsStruct<{
instructionDiscriminator: number[] /* size: 8 */;
}>(
[['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)]],
'undelegateInstructionArgs',
[["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)]],
"undelegateInstructionArgs"
);

export interface UndelegateInstructionAccounts {
Expand All @@ -26,7 +26,7 @@ export const undelegateInstructionDiscriminator = [
* Creates an Undelegate instruction.
*/
export function createUndelegateInstruction(
accounts: UndelegateInstructionAccounts,
accounts: UndelegateInstructionAccounts
) {
const [data] = undelegateStruct.serialize({
instructionDiscriminator: undelegateInstructionDiscriminator,
Expand Down
28 changes: 14 additions & 14 deletions clients/bolt-sdk/src/generated/accounts/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* See: https://github.com/metaplex-foundation/solita
*/

import * as beet from '@metaplex-foundation/beet';
import * as web3 from '@solana/web3.js';
import * as beetSolana from '@metaplex-foundation/beet-solana';
import * as beet from "@metaplex-foundation/beet";
import * as web3 from "@solana/web3.js";
import * as beetSolana from "@metaplex-foundation/beet-solana";

/**
* Arguments used to create {@link Entity}
Expand Down Expand Up @@ -42,7 +42,7 @@ export class Entity implements EntityArgs {
*/
static fromAccountInfo(
accountInfo: web3.AccountInfo<Buffer>,
offset = 0,
offset = 0
): [Entity, number] {
return Entity.deserialize(accountInfo.data, offset);
}
Expand All @@ -56,11 +56,11 @@ export class Entity implements EntityArgs {
static async fromAccountAddress(
connection: web3.Connection,
address: web3.PublicKey,
commitmentOrConfig?: web3.Commitment | web3.GetAccountInfoConfig,
commitmentOrConfig?: web3.Commitment | web3.GetAccountInfoConfig
): Promise<Entity> {
const accountInfo = await connection.getAccountInfo(
address,
commitmentOrConfig,
commitmentOrConfig
);
if (accountInfo == null) {
throw new Error(`Unable to find Entity account at ${address}`);
Expand All @@ -76,8 +76,8 @@ export class Entity implements EntityArgs {
*/
static gpaBuilder(
programId: web3.PublicKey = new web3.PublicKey(
'WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n',
),
"WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n"
)
) {
return beetSolana.GpaBuilder.fromStruct(programId, entityBeet);
}
Expand Down Expand Up @@ -117,11 +117,11 @@ export class Entity implements EntityArgs {
*/
static async getMinimumBalanceForRentExemption(
connection: web3.Connection,
commitment?: web3.Commitment,
commitment?: web3.Commitment
): Promise<number> {
return connection.getMinimumBalanceForRentExemption(
Entity.byteSize,
commitment,
commitment
);
}

Expand All @@ -141,7 +141,7 @@ export class Entity implements EntityArgs {
return {
id: (() => {
const x = this.id as { toNumber: () => number };
if (typeof x.toNumber === 'function') {
if (typeof x.toNumber === "function") {
try {
return x.toNumber();
} catch (_) {
Expand All @@ -165,9 +165,9 @@ export const entityBeet = new beet.BeetStruct<
}
>(
[
['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)],
['id', beet.u64],
["accountDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
["id", beet.u64],
],
Entity.fromArgs,
'Entity',
"Entity"
);
Loading

0 comments on commit 7947a95

Please sign in to comment.