-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
@@ -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)[] = []; | ||
|
@@ -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()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ | |
"outDir": "dist", | ||
"rootDir": "src", | ||
"target": "es2017", | ||
"strict": true | ||
"strict": true, | ||
"lib": ["es2021"] | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you added the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it enables us to use |
||
"include": [ | ||
"src/**/*", | ||
|
There was a problem hiding this comment.
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:
Line 25 too :D
There was a problem hiding this comment.
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