Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ Entities extra_seed should be bytes rather than an optional string, to avoid issues with encoding/decoding #86

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading