From 2704c49bb97eaa47a4ba6a4cfe35070ab027e3e5 Mon Sep 17 00:00:00 2001 From: Fraz Arshad Date: Mon, 29 Apr 2024 13:15:23 +0500 Subject: [PATCH 1/4] fix: update checks for attribute keys --- src/mappings/constants.ts | 3 +++ src/mappings/mappingHandlers.ts | 29 ++++++++++++++++++++++------- tsconfig.json | 3 ++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/mappings/constants.ts b/src/mappings/constants.ts index b1d9f6931..dc24b813f 100644 --- a/src/mappings/constants.ts +++ b/src/mappings/constants.ts @@ -23,3 +23,6 @@ export const VALUE_KEY = b64encode("value"); export const STORE_KEY = b64encode("store"); export const VSTORAGE_VALUE = b64encode("vstorage"); export const KEY_KEY = b64encode("key"); +export const STORE_NAME_KEY = b64encode("store_name"); +export const SUBKEY_KEY = b64encode("store_subkey"); +export const UNPROVED_VALUE_KEY = b64encode("unproved_value"); diff --git a/src/mappings/mappingHandlers.ts b/src/mappings/mappingHandlers.ts index 6c87b46d7..5142fc467 100644 --- a/src/mappings/mappingHandlers.ts +++ b/src/mappings/mappingHandlers.ts @@ -28,7 +28,16 @@ import { dateToDayKey, } from "./utils"; -import { EVENT_TYPES, STORE_KEY, VSTORAGE_VALUE, KEY_KEY, VALUE_KEY } from "./constants"; +import { + EVENT_TYPES, + STORE_KEY, + VSTORAGE_VALUE, + KEY_KEY, + VALUE_KEY, + STORE_NAME_KEY, + SUBKEY_KEY, + UNPROVED_VALUE_KEY, +} from "./constants"; import { psmEventKit } from "./events/psm"; import { boardAuxEventKit } from "./events/boardAux"; import { priceFeedEventKit } from "./events/priceFeed"; @@ -48,18 +57,18 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise< return; } - const storeAttr = event.attributes.find((a) => a.key === STORE_KEY); + const storeAttr = event.attributes.find((a) => a.key === STORE_KEY || a.key === STORE_NAME_KEY); if (!storeAttr || storeAttr.value != VSTORAGE_VALUE) { return; } - const valueAttr = event.attributes.find((a: any) => a.key === VALUE_KEY); + const valueAttr = event.attributes.find((a: any) => a.key === VALUE_KEY || a.key === UNPROVED_VALUE_KEY); if (!valueAttr || !valueAttr.value) { logger.warn("Value attribute is missing or empty."); return; } - const keyAttr = event.attributes.find((a: any) => a.key === KEY_KEY); + const keyAttr = event.attributes.find((a: any) => a.key === KEY_KEY || a.key === SUBKEY_KEY); if (!keyAttr) { logger.warn("Key attribute is missing or empty."); return; @@ -67,7 +76,9 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise< let data = Object(); try { - data = JSON.parse(b64decode(valueAttr.value)); + const decodedValue = + valueAttr.key === UNPROVED_VALUE_KEY ? b64decode(b64decode(valueAttr.value)) : b64decode(valueAttr.value); + data = JSON.parse(decodedValue); } catch (e) { return; } @@ -77,7 +88,11 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise< return; } - const path = extractStoragePath(b64decode(keyAttr.value)); + const decodedKey = + keyAttr.key === SUBKEY_KEY + ? b64decode(b64decode(keyAttr.value)).replaceAll("\u0000", "\x00") + : b64decode(keyAttr.value); + const path = extractStoragePath(decodedKey); const module = getStateChangeModule(path); const recordSaves: (Promise | undefined)[] = []; @@ -91,7 +106,7 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise< path, idx, JSON.stringify(value.slots), - JSON.stringify(payload) + JSON.stringify(payload), ); recordSaves.push(record.save()); diff --git a/tsconfig.json b/tsconfig.json index f3019d720..dba2a8a18 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,8 @@ "outDir": "dist", "rootDir": "src", "target": "es2017", - "strict": true + "strict": true, + "lib": ["es2021"] }, "include": [ "src/**/*", From 8c977b243b89a48547bcf931536c7a77b69c9211 Mon Sep 17 00:00:00 2001 From: Fraz Arshad Date: Mon, 29 Apr 2024 20:41:21 +0500 Subject: [PATCH 2/4] fixup! fix: update checks for attribute keys chore: removed any type --- src/mappings/mappingHandlers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mappings/mappingHandlers.ts b/src/mappings/mappingHandlers.ts index 5142fc467..891acd389 100644 --- a/src/mappings/mappingHandlers.ts +++ b/src/mappings/mappingHandlers.ts @@ -62,13 +62,13 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise< return; } - const valueAttr = event.attributes.find((a: any) => a.key === VALUE_KEY || a.key === UNPROVED_VALUE_KEY); + const valueAttr = event.attributes.find((a) => a.key === VALUE_KEY || a.key === UNPROVED_VALUE_KEY); if (!valueAttr || !valueAttr.value) { logger.warn("Value attribute is missing or empty."); return; } - const keyAttr = event.attributes.find((a: any) => a.key === KEY_KEY || a.key === SUBKEY_KEY); + const keyAttr = event.attributes.find((a) => a.key === KEY_KEY || a.key === SUBKEY_KEY); if (!keyAttr) { logger.warn("Key attribute is missing or empty."); return; From 828b25869299e0bb42f05d415a89f9927ad9219c Mon Sep 17 00:00:00 2001 From: Touseef Liaqat Date: Mon, 29 Apr 2024 16:47:40 -0700 Subject: [PATCH 3/4] Update node version in CI --- .github/workflows/pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 93b6fc5b5..b212cdbdb 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -12,7 +12,7 @@ jobs: - name: Setup Node.js environment uses: actions/setup-node@v2 with: - node-version: 16 + node-version: 18 - run: yarn - name: Codegen run: yarn codegen From aa9172e387ee934ed2b82203d8135940ba95fbf9 Mon Sep 17 00:00:00 2001 From: Touseef Liaqat Date: Mon, 29 Apr 2024 19:04:28 -0700 Subject: [PATCH 4/4] Temporarily disable CI on PR --- .github/workflows/pr.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index b212cdbdb..a291cd85d 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,8 +1,8 @@ name: PR -on: - pull_request: - paths-ignore: - - ".github/workflows/**" +# on: +# pull_request: +# paths-ignore: +# - ".github/workflows/**" jobs: pr: name: pr