Skip to content

Commit

Permalink
feat: ✨ Entities extra_seed should be bytes rather than an optional s…
Browse files Browse the repository at this point in the history
…tring, to avoid issues with encoding/decoding
  • Loading branch information
iamnamananand996 authored and GabrielePicco committed Oct 16, 2024
1 parent 2d08db1 commit 2383818
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clients/bolt-sdk/src/generated/idl/world.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
{
"name": "extra_seed",
"type": {
"option": "string"
"option": "bytes"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions clients/bolt-sdk/src/generated/instructions/addEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as web3 from "@solana/web3.js";
* @category generated
*/
export interface AddEntityInstructionArgs {
extraSeed: beet.COption<string>;
extraSeed: beet.COption<Uint8Array>;
}
/**
* @category Instructions
Expand All @@ -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",
);
Expand Down
2 changes: 1 addition & 1 deletion clients/bolt-sdk/src/generated/types/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export type World = {
{
name: "extraSeed";
type: {
option: "string";
option: "bytes";
};
},
];
Expand Down
2 changes: 1 addition & 1 deletion clients/bolt-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion clients/bolt-sdk/src/world/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export async function AddEntity({
}: {
payer: PublicKey;
world: PublicKey;
seed?: string;
seed?: Uint8Array;
connection: Connection;
}): Promise<{
instruction: TransactionInstruction;
Expand Down
6 changes: 3 additions & 3 deletions programs/world/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub mod world {
}

#[allow(unused_variables)]
pub fn add_entity(ctx: Context<AddEntity>, extra_seed: Option<String>) -> Result<()> {
pub fn add_entity(ctx: Context<AddEntity>, extra_seed: Option<Vec<u8>>) -> Result<()> {
require!(
ctx.accounts.world.key() == ctx.accounts.world.pda().0,
WorldError::WorldAccountMismatch
Expand Down Expand Up @@ -403,7 +403,7 @@ pub struct RemoveSystem<'info> {
}

#[derive(Accounts)]
#[instruction(extra_seed: Option<String>)]
#[instruction(extra_seed: Option<Vec<u8>>)]
pub struct AddEntity<'info> {
#[account(mut)]
pub payer: Signer<'info>,
Expand All @@ -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>,
Expand Down
2 changes: 1 addition & 1 deletion tests/bolt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2383818

Please sign in to comment.