Skip to content

Commit

Permalink
:recucle: Keeping Entity PDA derivation from World ID
Browse files Browse the repository at this point in the history
  • Loading branch information
notdanilo committed Jan 7, 2025
1 parent afcc44d commit 398c4a4
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 728 deletions.
2 changes: 1 addition & 1 deletion clients/bolt-sdk/idl/world.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
],
"args": [
{
"name": "seed",
"name": "extraSeed",
"type": {
"option": "string"
}
Expand Down
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 @@ -78,7 +78,7 @@
],
"args": [
{
"name": "seed",
"name": "extra_seed",
"type": {
"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 {
seed: beet.COption<Uint8Array>;
extraSeed: beet.COption<Uint8Array>;
}
/**
* @category Instructions
Expand All @@ -28,7 +28,7 @@ export const addEntityStruct = new beet.FixableBeetArgsStruct<
>(
[
["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
["seed", beet.coption(beet.bytes)],
["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 @@ -66,7 +66,7 @@ export type World = {
];
args: [
{
name: "seed";
name: "extra_seed";
type: {
option: "bytes";
};
Expand Down
11 changes: 6 additions & 5 deletions clients/bolt-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PublicKey } from "@solana/web3.js";
import type BN from "bn.js";
import * as PROGRAM_IDL from "./world/idl.json";
import { PROGRAM_ID } from "./generated";
import { World as PROGRAM_IDL } from "./generated/types/world";
export * from "./generated/accounts";
export * from "./generated/instructions";
export * from "./world/transactions";
Expand Down Expand Up @@ -42,22 +42,23 @@ export function FindWorldPda({
}

export function FindEntityPda({
world,
worldId,
entityId,
seed,
programId,
}: {
world: PublicKey;
worldId: BN;
entityId?: BN;
seed?: Uint8Array;
programId?: PublicKey;
}) {
const seeds = [Buffer.from("entity"), world.toBytes()];
const worldIdBuffer = Buffer.from(worldId.toArrayLike(Buffer, "be", 8));
const seeds = [Buffer.from("entity"), worldIdBuffer];
if (seed !== undefined) {
seeds.push(Buffer.from(new Uint8Array(8)));
seeds.push(Buffer.from(seed));
} else if (entityId !== undefined) {
const entityIdBuffer = entityId.toArrayLike(Buffer, "be", 8);
const entityIdBuffer = Buffer.from(entityId.toArrayLike(Buffer, "be", 8));
seeds.push(entityIdBuffer);
} else {
throw new Error("An entity must have either an Id or a Seed");
Expand Down
Loading

0 comments on commit 398c4a4

Please sign in to comment.