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

fix: update checks for old format #6

Merged
merged 4 commits into from
Apr 30, 2024
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: PR
on:
pull_request:
paths-ignore:
- ".github/workflows/**"
# on:
# pull_request:
# paths-ignore:
# - ".github/workflows/**"
jobs:
pr:
name: pr
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/mappings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUBKEY_KEY ......... KEY KEY :D Perhaps, SUB_KEY?

I think this is cleaner:

export const STORE_NAME = b64encode("store_name");
export const SUB_KEY = b64encode("store_subkey");
export const UNPROVED_VALUE = b64encode("unproved_value");

Line 25 too :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the repetition is there intentionally to indicate the actual name of the key. for keys that end with "key" the name might look strange but i think we should keep the same pattern among all consts to avoid confusion

29 changes: 22 additions & 7 deletions src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -48,26 +57,28 @@ 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) => 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) => a.key === KEY_KEY || a.key === SUBKEY_KEY);
if (!keyAttr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use :any on line 65 and 71 but not on 60?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidentally added

logger.warn("Key attribute is missing or empty.");
return;
}

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;
}
Expand All @@ -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<void> | undefined)[] = [];
Expand All @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"outDir": "dist",
"rootDir": "src",
"target": "es2017",
"strict": true
"strict": true,
"lib": ["es2021"]
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you added the lib option in tsconfig.json. Why make this change and which features from ES2021 you want to use?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it enables us to use replaceAll function

"include": [
"src/**/*",
Expand Down