-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikolas Haimerl
authored and
Nikolas Haimerl
committed
Jan 16, 2025
1 parent
a00e61b
commit c2ed0ad
Showing
9 changed files
with
31,587 additions
and
31,611 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
import { create } from '@ipld/schema/typed.js' | ||
import { schemaDmt } from './builtin-actor-events-schemas.js' | ||
import { base64pad } from 'multiformats/bases/base64' | ||
import { encode as cborEncode, decode as cborDecode } from '@ipld/dag-cbor' | ||
|
||
const decodeCborInBase64 = (data) => { | ||
return cborDecode(base64pad.baseDecode(data)) | ||
} | ||
|
||
const encodeCborInBase64 = (data) => { | ||
return base64pad.baseEncode(cborEncode(data)) | ||
} | ||
|
||
const rawEventEntriesToEvent = (rawEventEntries) => { | ||
// Each event is defined by a list of even entries which will will transform into a typed event | ||
const event = {} | ||
// TODO handle if there is no type entry | ||
let eventType | ||
for (const entry of rawEventEntries) { | ||
// The key returned by the Lotus API is kebab-case, we convert it to camelCase | ||
const key = entry.Key.replace(/-([a-z])/g, (_, c) => c.toUpperCase()) | ||
const value = decodeCborInBase64(entry.Value) | ||
// In each entry exists an event type declaration which we need to extract | ||
if (key === '$type') { | ||
eventType = value.concat('event') | ||
// The type entry is not part of the event itself | ||
continue | ||
} | ||
event[key] = value | ||
} | ||
return {event, eventType} | ||
return cborDecode(base64pad.baseDecode(data)) | ||
} | ||
|
||
const encodeCborInBase64 = (data) => { | ||
return base64pad.baseEncode(cborEncode(data)) | ||
} | ||
|
||
const rawEventEntriesToEvent = (rawEventEntries) => { | ||
// Each event is defined by a list of even entries which will will transform into a typed event | ||
const event = {} | ||
// TODO handle if there is no type entry | ||
let eventType | ||
for (const entry of rawEventEntries) { | ||
// The key returned by the Lotus API is kebab-case, we convert it to camelCase | ||
const key = entry.Key.replace(/-([a-z])/g, (_, c) => c.toUpperCase()) | ||
const value = decodeCborInBase64(entry.Value) | ||
// In each entry exists an event type declaration which we need to extract | ||
if (key === '$type') { | ||
eventType = value.concat('event') | ||
// The type entry is not part of the event itself | ||
continue | ||
} | ||
event[key] = value | ||
} | ||
return { event, eventType } | ||
} | ||
|
||
export { | ||
decodeCborInBase64, | ||
encodeCborInBase64, | ||
rawEventEntriesToEvent | ||
} | ||
export { | ||
decodeCborInBase64, | ||
encodeCborInBase64, | ||
rawEventEntriesToEvent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.