diff --git a/@planetarium/lib9c/src/actions/charge_action_point.ts b/@planetarium/lib9c/src/actions/charge_action_point.ts new file mode 100644 index 0000000000..73ca5ebf4f --- /dev/null +++ b/@planetarium/lib9c/src/actions/charge_action_point.ts @@ -0,0 +1,37 @@ +import type { Address } from "@planetarium/account"; +import { BencodexDictionary, Dictionary, type Value } from "@planetarium/bencodex"; +import { GameAction, type GameActionArgs } from "./common.js"; + +/** + * The arguments of the `ChargeActionPoint` action. + */ +export type ChargeActionPointArgs = { + avatarAddress: Address; +} & GameActionArgs; + +/** + * The `ChargeActionPoint` action is used to charge action points for an avatar. + */ +export class ChargeActionPoint extends GameAction { + protected readonly type_id: string = "charge_action_point3"; + + public readonly avatarAddress: Address; + + /** + * Create a new `ChargeActionPoint` action. + * @param params The arguments of the `ChargeActionPoint` action. + */ + constructor({ avatarAddress, id }: ChargeActionPointArgs) { + super({ id }); + this.avatarAddress = avatarAddress; + } + + /** + * Serialize the action data to Bencodex format. + */ + protected plain_value_internal(): Dictionary { + return new BencodexDictionary([ + ["avatarAddress", this.avatarAddress.toBytes()], + ]); +} +} \ No newline at end of file diff --git a/@planetarium/lib9c/src/index.ts b/@planetarium/lib9c/src/index.ts index bf11110b53..1373e63f67 100644 --- a/@planetarium/lib9c/src/index.ts +++ b/@planetarium/lib9c/src/index.ts @@ -3,6 +3,7 @@ export { type ClaimStakeRewardArgs, } from "./actions/claim_stake_reward.js"; export { Stake, type StakeArgs } from "./actions/stake.js"; +export { ChargeActionPoint, type ChargeActionPointArgs } from "./actions/charge_action_point.js"; export { DailyReward, type DailyRewardArgs } from "./actions/daily_reward.js"; export { TransferAsset, diff --git a/@planetarium/lib9c/tests/actions/charge_action_point.test.ts b/@planetarium/lib9c/tests/actions/charge_action_point.test.ts new file mode 100644 index 0000000000..841c208bc6 --- /dev/null +++ b/@planetarium/lib9c/tests/actions/charge_action_point.test.ts @@ -0,0 +1,23 @@ +import { describe } from "vitest"; +import { ChargeActionPoint, uuidToGuidBytes } from "../../src/index.js"; +import { runTests } from "./common.js"; +import { avatarAddress } from "./fixtures.js"; + +describe("ChargeActionPoint", () => { + describe("odin", () => { + runTests("valid case", [ + new ChargeActionPoint({ + id: uuidToGuidBytes("ae195a5e-b43f-4c6d-8fd3-9f38311a45eb"), + avatarAddress, + }), + ]); + }); + describe("heimdall", () => { + runTests("valid case", [ + new ChargeActionPoint({ + id: uuidToGuidBytes("97b69171-6482-4e11-b2c9-1c671615321b"), + avatarAddress, + }), + ]); + }); +});