From 2383818e1dcb785c4d9dc3f3be4d37ea19707a84 Mon Sep 17 00:00:00 2001 From: Naman Anand Date: Sat, 12 Oct 2024 11:57:09 +0530 Subject: [PATCH] feat: :sparkles: Entities extra_seed should be bytes rather than an optional string, to avoid issues with encoding/decoding --- clients/bolt-sdk/src/generated/idl/world.json | 2 +- clients/bolt-sdk/src/generated/instructions/addEntity.ts | 4 ++-- clients/bolt-sdk/src/generated/types/world.ts | 2 +- clients/bolt-sdk/src/index.ts | 2 +- clients/bolt-sdk/src/world/transactions.ts | 2 +- programs/world/src/lib.rs | 6 +++--- tests/bolt.ts | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/clients/bolt-sdk/src/generated/idl/world.json b/clients/bolt-sdk/src/generated/idl/world.json index 1554550..7bb261d 100644 --- a/clients/bolt-sdk/src/generated/idl/world.json +++ b/clients/bolt-sdk/src/generated/idl/world.json @@ -80,7 +80,7 @@ { "name": "extra_seed", "type": { - "option": "string" + "option": "bytes" } } ] diff --git a/clients/bolt-sdk/src/generated/instructions/addEntity.ts b/clients/bolt-sdk/src/generated/instructions/addEntity.ts index 98fd60a..fb7914c 100644 --- a/clients/bolt-sdk/src/generated/instructions/addEntity.ts +++ b/clients/bolt-sdk/src/generated/instructions/addEntity.ts @@ -14,7 +14,7 @@ import * as web3 from "@solana/web3.js"; * @category generated */ export interface AddEntityInstructionArgs { - extraSeed: beet.COption; + extraSeed: beet.COption; } /** * @category Instructions @@ -28,7 +28,7 @@ export const addEntityStruct = new beet.FixableBeetArgsStruct< >( [ ["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)], - ["extraSeed", beet.coption(beet.utf8String)], + ["extraSeed", beet.coption(beet.bytes)], ], "AddEntityInstructionArgs", ); diff --git a/clients/bolt-sdk/src/generated/types/world.ts b/clients/bolt-sdk/src/generated/types/world.ts index e9092d8..4c8cc3f 100644 --- a/clients/bolt-sdk/src/generated/types/world.ts +++ b/clients/bolt-sdk/src/generated/types/world.ts @@ -68,7 +68,7 @@ export type World = { { name: "extraSeed"; type: { - option: "string"; + option: "bytes"; }; }, ]; diff --git a/clients/bolt-sdk/src/index.ts b/clients/bolt-sdk/src/index.ts index 006bfd5..da9a0d9 100644 --- a/clients/bolt-sdk/src/index.ts +++ b/clients/bolt-sdk/src/index.ts @@ -42,7 +42,7 @@ export function FindEntityPda({ }: { worldId: BN; entityId?: BN; - seed?: string; + seed?: Uint8Array; programId?: PublicKey; }) { const worldIdBuffer = Buffer.from(worldId.toArrayLike(Buffer, "be", 8)); diff --git a/clients/bolt-sdk/src/world/transactions.ts b/clients/bolt-sdk/src/world/transactions.ts index 7635475..5f86f35 100644 --- a/clients/bolt-sdk/src/world/transactions.ts +++ b/clients/bolt-sdk/src/world/transactions.ts @@ -229,7 +229,7 @@ export async function AddEntity({ }: { payer: PublicKey; world: PublicKey; - seed?: string; + seed?: Uint8Array; connection: Connection; }): Promise<{ instruction: TransactionInstruction; diff --git a/programs/world/src/lib.rs b/programs/world/src/lib.rs index d3e1bf5..b97f4a9 100644 --- a/programs/world/src/lib.rs +++ b/programs/world/src/lib.rs @@ -247,7 +247,7 @@ pub mod world { } #[allow(unused_variables)] - pub fn add_entity(ctx: Context, extra_seed: Option) -> Result<()> { + pub fn add_entity(ctx: Context, extra_seed: Option>) -> Result<()> { require!( ctx.accounts.world.key() == ctx.accounts.world.pda().0, WorldError::WorldAccountMismatch @@ -403,7 +403,7 @@ pub struct RemoveSystem<'info> { } #[derive(Accounts)] -#[instruction(extra_seed: Option)] +#[instruction(extra_seed: Option>)] pub struct AddEntity<'info> { #[account(mut)] pub payer: Signer<'info>, @@ -413,7 +413,7 @@ pub struct AddEntity<'info> { None => world.entities.to_be_bytes() }, match extra_seed { - Some(ref seed) => seed.as_bytes(), + Some(ref seed) => seed, None => &[], }], bump)] pub entity: Account<'info, Entity>, diff --git a/tests/bolt.ts b/tests/bolt.ts index ebd15c4..fd784fe 100644 --- a/tests/bolt.ts +++ b/tests/bolt.ts @@ -215,7 +215,7 @@ describe("bolt", () => { const addEntity = await AddEntity({ payer: provider.wallet.publicKey, world: worldPda, - seed: "extra-seed", + seed: Buffer.from("extra-seed"), connection: provider.connection, }); await provider.sendAndConfirm(addEntity.transaction);