Skip to content

Commit 1bad82f

Browse files
feat: ✨ Entities extra_seed should be bytes rather than an optional string, to avoid issues with encoding/decoding (#86)
1 parent fe3a235 commit 1bad82f

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

clients/bolt-sdk/src/generated/idl/world.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
{
8181
"name": "extra_seed",
8282
"type": {
83-
"option": "string"
83+
"option": "bytes"
8484
}
8585
}
8686
]

clients/bolt-sdk/src/generated/instructions/addEntity.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as web3 from "@solana/web3.js";
1414
* @category generated
1515
*/
1616
export interface AddEntityInstructionArgs {
17-
extraSeed: beet.COption<string>;
17+
extraSeed: beet.COption<Uint8Array>;
1818
}
1919
/**
2020
* @category Instructions
@@ -28,7 +28,7 @@ export const addEntityStruct = new beet.FixableBeetArgsStruct<
2828
>(
2929
[
3030
["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
31-
["extraSeed", beet.coption(beet.utf8String)],
31+
["extraSeed", beet.coption(beet.bytes)],
3232
],
3333
"AddEntityInstructionArgs",
3434
);

clients/bolt-sdk/src/generated/types/world.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export type World = {
6868
{
6969
name: "extraSeed";
7070
type: {
71-
option: "string";
71+
option: "bytes";
7272
};
7373
},
7474
];

clients/bolt-sdk/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function FindEntityPda({
4242
}: {
4343
worldId: BN;
4444
entityId?: BN;
45-
seed?: string;
45+
seed?: Uint8Array;
4646
programId?: PublicKey;
4747
}) {
4848
const worldIdBuffer = Buffer.from(worldId.toArrayLike(Buffer, "be", 8));

clients/bolt-sdk/src/world/transactions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export async function AddEntity({
229229
}: {
230230
payer: PublicKey;
231231
world: PublicKey;
232-
seed?: string;
232+
seed?: Uint8Array;
233233
connection: Connection;
234234
}): Promise<{
235235
instruction: TransactionInstruction;

programs/world/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub mod world {
247247
}
248248

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

405405
#[derive(Accounts)]
406-
#[instruction(extra_seed: Option<String>)]
406+
#[instruction(extra_seed: Option<Vec<u8>>)]
407407
pub struct AddEntity<'info> {
408408
#[account(mut)]
409409
pub payer: Signer<'info>,
@@ -413,7 +413,7 @@ pub struct AddEntity<'info> {
413413
None => world.entities.to_be_bytes()
414414
},
415415
match extra_seed {
416-
Some(ref seed) => seed.as_bytes(),
416+
Some(ref seed) => seed,
417417
None => &[],
418418
}], bump)]
419419
pub entity: Account<'info, Entity>,

tests/bolt.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe("bolt", () => {
215215
const addEntity = await AddEntity({
216216
payer: provider.wallet.publicKey,
217217
world: worldPda,
218-
seed: "extra-seed",
218+
seed: Buffer.from("extra-seed"),
219219
connection: provider.connection,
220220
});
221221
await provider.sendAndConfirm(addEntity.transaction);

0 commit comments

Comments
 (0)