Browse Source

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

Naman Anand 11 months ago
parent
commit
1bad82f3be

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

@@ -80,7 +80,7 @@
         {
           "name": "extra_seed",
           "type": {
-            "option": "string"
+            "option": "bytes"
           }
         }
       ]

+ 2 - 2
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<string>;
+  extraSeed: beet.COption<Uint8Array>;
 }
 /**
  * @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",
 );

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

@@ -68,7 +68,7 @@ export type World = {
         {
           name: "extraSeed";
           type: {
-            option: "string";
+            option: "bytes";
           };
         },
       ];

+ 1 - 1
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));

+ 1 - 1
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;

+ 3 - 3
programs/world/src/lib.rs

@@ -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
@@ -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>,
@@ -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>,

+ 1 - 1
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);