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

Refactor #2947

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ jobs:
jsr:
uses: planetarium/.github/.github/workflows/publish_jsr.yaml@bfb34283b538003768d19bff9ea05bcbd709d643
with:
workspace_directory: "@planetarium"
working_directory: "@planetarium/lib9c"
workspace_directory: "integrations/javascript/@planetarium"
working_directory: "integrations/javascript/@planetarium/lib9c"
pnpm_version: "9"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Address } from "@planetarium/account";
import { BencodexDictionary, type Dictionary } from "@planetarium/bencodex";
import type { RuneSlotInfo } from "../models/rune_slot_info.js";
import { GameAction, type GameActionArgs } from "./common.js";

export type JoinArenaArgs = {
avatarAddress: Address;
championshipId: bigint;
round: bigint;
costumes: Array<Uint8Array>;
equipments: Array<Uint8Array>;
runeInfos: Array<RuneSlotInfo>;
} & GameActionArgs;

export class JoinArena extends GameAction {
protected readonly type_id: string = "join_arena4";

public readonly avatarAddress: Address;
public readonly championshipId: bigint;
public readonly round: bigint;
public readonly costumes: Array<Uint8Array>;
public readonly equipments: Array<Uint8Array>;
public readonly runeInfos: Array<RuneSlotInfo>;

constructor({
avatarAddress,
championshipId,
round,
costumes,
equipments,
runeInfos,
id,
}: JoinArenaArgs) {
super({ id });
this.avatarAddress = avatarAddress;
this.championshipId = championshipId;
this.round = round;
this.costumes = costumes;
this.equipments = equipments;
this.runeInfos = runeInfos;
}

protected plain_value_internal(): Dictionary {
return new BencodexDictionary([
["avatarAddress", this.avatarAddress.toBytes()],
["championshipId", this.championshipId.toString()],
["round", this.round.toString()],
["costumes", this.costumes.map((costume) => costume)],
["equipments", this.equipments.map((equipment) => equipment)],
["runeInfos", this.runeInfos.map((rune) => rune.serialize())],
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export {
ChargeActionPoint,
type ChargeActionPointArgs,
} from "./actions/charge_action_point.js";
export {
JoinArena,
type JoinArenaArgs,
} from "./actions/join_arena.js";
export { DailyReward, type DailyRewardArgs } from "./actions/daily_reward.js";
export {
TransferAsset,
Expand Down Expand Up @@ -47,6 +51,7 @@ export {
} from "./models/currencies.js";
export { HashDigest, type AlgorithmNames } from "./models/hashdigest.js";
export { ODIN_GENESIS_HASH, HEIMDALL_GENESIS_HASH } from "./models/networks.js";
export { RuneSlotInfo } from "./models/rune_slot_info.js";

export {
CreateAvatar,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Value } from "@planetarium/bencodex";

export class RuneSlotInfo {
public readonly slotIndex: bigint;
public readonly runeId: bigint;

constructor(slotIndex: bigint, runeId: bigint) {
this.slotIndex = slotIndex;
this.runeId = runeId;
}

public serialize(): Value[] {
return [this.slotIndex.toString(), this.runeId.toString()];
}

static deserialize(data: {
slotIndex: string;
runeId: string;
}): RuneSlotInfo {
return new RuneSlotInfo(BigInt(data.slotIndex), BigInt(data.runeId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe } from "vitest";
import { JoinArena, uuidToGuidBytes, RuneSlotInfo } from "../../src/index.js";
import { runTests } from "./common.js";
import { avatarAddress } from "./fixtures.js";

describe("JoinArena", () => {
describe("odin", () => {
runTests("valid case", [
new JoinArena({
id: uuidToGuidBytes("ae195a5e-b43f-4c6d-8fd3-9f38311a45eb"),
avatarAddress,
championshipId: BigInt(1),
round: BigInt(1),
costumes: [uuidToGuidBytes("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")],
equipments: [uuidToGuidBytes("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")],
runeInfos: [new RuneSlotInfo(BigInt(1), BigInt(1))],
}),
]);
});
describe("heimdall", () => {
runTests("valid case", [
new JoinArena({
id: uuidToGuidBytes("ae195a5e-b43f-4c6d-8fd3-9f38311a45eb"),
avatarAddress,
championshipId: BigInt(1),
round: BigInt(1),
costumes: [uuidToGuidBytes("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")],
equipments: [uuidToGuidBytes("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")],
runeInfos: [new RuneSlotInfo(BigInt(1), BigInt(1))],
}),
]);
});
});
Loading