Skip to content

Commit 1535c9f

Browse files
committed
Update sqs push decoder
1 parent 85478e3 commit 1535c9f

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

packages/store-indexer/src/sqs-reveal-hook.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ describe("extractRevealCodes", () => {
4545
}) as unknown as StorageAdapterLog;
4646

4747
it("extracts code from a reveal log (state=IDLE)", () => {
48-
// TaruchiStatus static layout: affinity(1) + state(1) + level(4) + tp(4) + traits(5) = 15 bytes
48+
// TaruchiStatus static layout: affinity(1) + state(1) + level(4) + xp(4) + tp(4) + traits(5) = 19 bytes
4949
// traits packed as uint40: flower | body<<8 | eye<<16 | mouth<<24 | equipment<<32
5050
// body=1,eye=3,mouth=5,equip=2,flower=1 -> big-endian uint40 = 0x0205030101
5151
const staticData =
5252
"0x" +
5353
"03" + // affinity: 3
5454
"01" + // state: 1 (IDLE)
5555
"00000001" + // level: 1
56+
"00000000" + // xp: 0
5657
"00000000" + // trainingPoints: 0
5758
"0205030101"; // traits: body=1,eye=3,mouth=5,equip=2,flower=1
5859

@@ -62,29 +63,29 @@ describe("extractRevealCodes", () => {
6263
});
6364

6465
it("ignores non-SetRecord events", () => {
65-
const staticData = "0x" + "03" + "01" + "00000001" + "00000000" + "0205030101";
66+
const staticData = "0x" + "03" + "01" + "00000001" + "00000000" + "00000000" + "0205030101";
6667
const logs = [makeLog("Store_DeleteRecord", TARUCHI_STATUS_TABLE_ID, staticData)];
6768
expect(extractRevealCodes(logs)).toEqual([]);
6869
});
6970

7071
it("ignores wrong table ID", () => {
7172
const otherTableId = resourceToHex({ type: "table", namespace: "app", name: "TaruchiCore" });
72-
const staticData = "0x" + "03" + "01" + "00000001" + "00000000" + "0205030101";
73+
const staticData = "0x" + "03" + "01" + "00000001" + "00000000" + "00000000" + "0205030101";
7374
const logs = [makeLog("Store_SetRecord", otherTableId, staticData)];
7475
expect(extractRevealCodes(logs)).toEqual([]);
7576
});
7677

7778
it("ignores non-IDLE state", () => {
7879
// state=2 (ENROLLED)
79-
const staticData = "0x" + "03" + "02" + "00000001" + "00000000" + "0205030101";
80+
const staticData = "0x" + "03" + "02" + "00000001" + "00000000" + "00000000" + "0205030101";
8081
const logs = [makeLog("Store_SetRecord", TARUCHI_STATUS_TABLE_ID, staticData)];
8182
expect(extractRevealCodes(logs)).toEqual([]);
8283
});
8384

8485
it("extracts multiple reveals from one block", () => {
85-
const staticData1 = "0x" + "03" + "01" + "00000001" + "00000000" + "0205030101";
86+
const staticData1 = "0x" + "03" + "01" + "00000001" + "00000000" + "00000000" + "0205030101";
8687
// body=12,eye=5,mouth=3,equip=0,flower=0 -> uint40 = 0x0003050c00
87-
const staticData2 = "0x" + "05" + "01" + "00000001" + "00000000" + "0003050c00";
88+
const staticData2 = "0x" + "05" + "01" + "00000001" + "00000000" + "00000000" + "0003050c00";
8889
const logs = [
8990
makeLog("Store_SetRecord", TARUCHI_STATUS_TABLE_ID, staticData1),
9091
makeLog("Store_SetRecord", TARUCHI_STATUS_TABLE_ID, staticData2),

packages/store-indexer/src/sqs-reveal-hook.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ const IDLE_STATE = 1;
2323
// offset 0: affinity (uint8, 1 byte)
2424
// offset 1: state (uint8, 1 byte)
2525
// offset 2: level (uint32, 4 bytes)
26-
// offset 6: tp (uint32, 4 bytes)
27-
// offset 10: traits (uint40, 5 bytes)
26+
// offset 6: xp (uint32, 4 bytes)
27+
// offset 10: tp (uint32, 4 bytes)
28+
// offset 14: traits (uint40, 5 bytes)
2829

2930
export function unpackTraits(traits: bigint): string {
3031
const body = (traits >> 8n) & 0xffn;
@@ -47,7 +48,7 @@ export function extractRevealCodes(logs: readonly StorageAdapterLog[]): string[]
4748
const state = hexToNumber(sliceHex(staticData, 1, 2));
4849
if (state !== IDLE_STATE) continue;
4950

50-
const traits = hexToBigInt(sliceHex(staticData, 10, 15));
51+
const traits = hexToBigInt(sliceHex(staticData, 14, 19));
5152
codes.push(unpackTraits(traits));
5253
}
5354

0 commit comments

Comments
 (0)