Skip to content

Commit

Permalink
Updating to Kinobi 0.18.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Apr 17, 2024
1 parent 5159c91 commit 16c6076
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 56 deletions.
2 changes: 1 addition & 1 deletion clients/js/src/generated/accounts/myPdaAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function findMyPdaAccountPda(
string({ size: 'variable' }).serialize('myPdaAccount'),
publicKeySerializer().serialize(programId),
publicKeySerializer().serialize(seeds.authority),
string({ size: 'variable' }).serialize(seeds.name),
string().serialize(seeds.name),
]);
}

Expand Down
6 changes: 3 additions & 3 deletions clients/js/src/generated/errors/mplProjectName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const nameToErrorMap: Map<string, ProgramErrorConstructor> = new Map();

/** InvalidSystemProgram: Invalid System Program */
export class InvalidSystemProgramError extends ProgramError {
readonly name: string = 'InvalidSystemProgram';
override readonly name: string = 'InvalidSystemProgram';

readonly code: number = 0x0; // 0

Expand All @@ -30,7 +30,7 @@ nameToErrorMap.set('InvalidSystemProgram', InvalidSystemProgramError);

/** DeserializationError: Error deserializing account */
export class DeserializationErrorError extends ProgramError {
readonly name: string = 'DeserializationError';
override readonly name: string = 'DeserializationError';

readonly code: number = 0x1; // 1

Expand All @@ -43,7 +43,7 @@ nameToErrorMap.set('DeserializationError', DeserializationErrorError);

/** SerializationError: Error serializing account */
export class SerializationErrorError extends ProgramError {
readonly name: string = 'SerializationError';
override readonly name: string = 'SerializationError';

readonly code: number = 0x2; // 2

Expand Down
24 changes: 18 additions & 6 deletions clients/js/src/generated/instructions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,28 @@ export function create(
);

// Accounts.
const resolvedAccounts: ResolvedAccountsWithIndices = {
address: { index: 0, isWritable: true, value: input.address ?? null },
authority: { index: 1, isWritable: false, value: input.authority ?? null },
payer: { index: 2, isWritable: true, value: input.payer ?? null },
const resolvedAccounts = {
address: {
index: 0,
isWritable: true as boolean,
value: input.address ?? null,
},
authority: {
index: 1,
isWritable: false as boolean,
value: input.authority ?? null,
},
payer: {
index: 2,
isWritable: true as boolean,
value: input.payer ?? null,
},
systemProgram: {
index: 3,
isWritable: false,
isWritable: false as boolean,
value: input.systemProgram ?? null,
},
};
} satisfies ResolvedAccountsWithIndices;

// Arguments.
const resolvedArgs: CreateInstructionArgs = { ...input };
Expand Down
8 changes: 4 additions & 4 deletions clients/rust/src/generated/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//! [https://github.com/metaplex-foundation/kinobi]
//!

pub(crate) mod my_account;
pub(crate) mod my_pda_account;
pub(crate) mod r#my_account;
pub(crate) mod r#my_pda_account;

pub use self::my_account::*;
pub use self::my_pda_account::*;
pub use self::r#my_account::*;
pub use self::r#my_pda_account::*;
14 changes: 12 additions & 2 deletions clients/rust/src/generated/accounts/my_pda_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ pub struct MyPdaAccount {
impl MyPdaAccount {
pub const LEN: usize = 2;

/// Prefix values used to generate a PDA for this account.
///
/// Values are positional and appear in the following order:
///
/// 0. `MyPdaAccount::PREFIX`
/// 1. `crate::MPL_PROJECT_NAME_ID`
/// 2. authority (`Pubkey`)
/// 3. name (`String`)
pub const PREFIX: &'static [u8] = "myPdaAccount".as_bytes();

pub fn create_pda(
authority: Pubkey,
name: &str,
name: String,
bump: u8,
) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
solana_program::pubkey::Pubkey::create_program_address(
Expand All @@ -37,7 +47,7 @@ impl MyPdaAccount {
)
}

pub fn find_pda(authority: &Pubkey, name: &str) -> (solana_program::pubkey::Pubkey, u8) {
pub fn find_pda(authority: &Pubkey, name: String) -> (solana_program::pubkey::Pubkey, u8) {
solana_program::pubkey::Pubkey::find_program_address(
&[
"myPdaAccount".as_bytes(),
Expand Down
18 changes: 16 additions & 2 deletions clients/rust/src/generated/instructions/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ pub struct CreateInstructionArgs {
pub arg2: u32,
}

/// Instruction builder.
/// Instruction builder for `Create`.
///
/// ### Accounts:
///
/// 0. `[writable, signer]` address
/// 1. `[]` authority
/// 2. `[writable, signer]` payer
/// 3. `[optional]` system_program (default to `11111111111111111111111111111111`)
#[derive(Default)]
pub struct CreateBuilder {
address: Option<solana_program::pubkey::Pubkey>,
Expand Down Expand Up @@ -295,7 +302,14 @@ impl<'a, 'b> CreateCpi<'a, 'b> {
}
}

/// `create` CPI instruction builder.
/// Instruction builder for `Create` via CPI.
///
/// ### Accounts:
///
/// 0. `[writable, signer]` address
/// 1. `[]` authority
/// 2. `[writable, signer]` payer
/// 3. `[]` system_program
pub struct CreateCpiBuilder<'a, 'b> {
instruction: Box<CreateCpiBuilderInstruction<'a, 'b>>,
}
Expand Down
4 changes: 2 additions & 2 deletions clients/rust/src/generated/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
//! [https://github.com/metaplex-foundation/kinobi]
//!

pub(crate) mod create;
pub(crate) mod r#create;

pub use self::create::*;
pub use self::r#create::*;
5 changes: 4 additions & 1 deletion clients/rust/src/generated/types/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use num_derive::FromPrimitive;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
#[derive(
BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash, FromPrimitive,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Key {
Uninitialized,
Expand Down
8 changes: 4 additions & 4 deletions clients/rust/src/generated/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//! [https://github.com/metaplex-foundation/kinobi]
//!

pub(crate) mod key;
pub(crate) mod my_data;
pub(crate) mod r#key;
pub(crate) mod r#my_data;

pub use self::key::*;
pub use self::my_data::*;
pub use self::r#key::*;
pub use self::r#my_data::*;
26 changes: 14 additions & 12 deletions configs/kinobi.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,40 @@ const kinobi = k.createFromIdls([path.join(idlDir, "mpl_project_name_program.jso

// Update programs.
kinobi.update(
new k.UpdateProgramsVisitor({
new k.updateProgramsVisitor({
mplProjectNameProgram: { name: "mplProjectName" },
})
);

// Update accounts.
kinobi.update(
new k.UpdateAccountsVisitor({
new k.updateAccountsVisitor({
myPdaAccount: {
seeds: [
k.stringConstantSeed("myPdaAccount"),
k.programSeed(),
k.publicKeySeed("authority", "The address of the authority"),
k.stringSeed("name", "The name of the account"),
k.constantPdaSeedNodeFromString("myPdaAccount"),
k.programIdPdaSeedNode(),
k.variablePdaSeedNode("authority", k.publicKeyTypeNode(), "The address of the authority"),
k.variablePdaSeedNode("name", k.stringTypeNode(), "The name of the account"),
],
},
})
);

// Update instructions.
kinobi.update(
new k.UpdateInstructionsVisitor({
new k.updateInstructionsVisitor({
create: {
bytesCreatedOnChain: k.bytesFromAccount("myAccount"),
byteDeltas: [
k.instructionByteDeltaNode(k.accountLinkNode("myAccount")),
],
},
})
);

// Set ShankAccount discriminator.
const key = (name) => ({ field: "key", value: k.vEnum("Key", name) });
const key = (name) => ({ field: "key", value: k.enumValueNode("Key", name) });
kinobi.update(
new k.SetAccountDiscriminatorFromFieldVisitor({
new k.setAccountDiscriminatorFromFieldVisitor({
myAccount: key("MyAccount"),
myPdaAccount: key("MyPdaAccount"),
})
Expand All @@ -50,13 +52,13 @@ kinobi.update(
// Render JavaScript.
const jsDir = path.join(clientDir, "js", "src", "generated");
const prettier = require(path.join(clientDir, "js", ".prettierrc.json"));
kinobi.accept(new k.RenderJavaScriptVisitor(jsDir, { prettier }));
kinobi.accept(new k.renderJavaScriptVisitor(jsDir, { prettier }));

// Render Rust.
const crateDir = path.join(clientDir, "rust");
const rustDir = path.join(clientDir, "rust", "src", "generated");
kinobi.accept(
new k.RenderRustVisitor(rustDir, {
new k.renderRustVisitor(rustDir, {
formatCode: true,
crateFolder: crateDir,
})
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"validator:stop": "amman stop"
},
"devDependencies": {
"@metaplex-foundation/kinobi": "^0.16.0",
"@metaplex-foundation/shank-js": "^0.1.0",
"@metaplex-foundation/kinobi": "^0.18.4",
"@metaplex-foundation/shank-js": "^0.1.7",
"@metaplex-foundation/amman": "^0.12.1",
"typescript": "^4.9.4"
},
"packageManager": "pnpm@8.9.0"
}
}
Loading

0 comments on commit 16c6076

Please sign in to comment.