Skip to content

Commit

Permalink
Merge pull request #6 from Agoric/fix/attrbutes-check-missing
Browse files Browse the repository at this point in the history
fix: update checks for old format
  • Loading branch information
toliaqat authored Apr 30, 2024
2 parents ffe1876 + aa9172e commit ae2e935
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
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 @@ -28,3 +28,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");
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) {
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"]
},
"include": [
"src/**/*",
Expand Down

0 comments on commit ae2e935

Please sign in to comment.