Support decoding codama program events#25
Conversation
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 20833600 | Triggered | Generic High Entropy Secret | a9f5992 | packages/node/src/solana/decoder.spec.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Coverage reportCaution Test run failed
Test suite run failedFailed tests: 4/54. Failed suites: 1/8.Report generated by 🧪jest coverage report action from db2ea61 |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for decoding logs from Codama programs by implementing event decoding functionality. The implementation extends the existing decoder to handle Codama IDL events alongside the already supported Anchor IDL v0.1.0 events.
- Enhanced log decoding to support Codama program events
- Added discriminator generation utility for event name matching
- Included comprehensive test coverage for the new functionality
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/node/test/8t2R21V3vjS1ucZzmX2memtGptjYZi2yGY3cYVa8dak7.idl.json | Added test IDL file for Codama program event testing |
| packages/node/src/solana/decoder.ts | Enhanced log decoding logic to support Codama IDL events |
| packages/node/src/solana/decoder.spec.ts | Added test case for Codama event decoding |
| packages/node/CHANGELOG.md | Documented the new feature addition |
| packages/common-solana/src/codegen/idl.ts | Added discriminator generation utility function |
| packages/common-solana/CHANGELOG.md | Documented the new utility function |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| return root.program.definedTypes.find( | ||
| (t) => | ||
| // Warning this is fragile as there can be various casings of the type names, but because it requires hashing data we can only go one way | ||
| logDisc.indexOf(getDiscriminator(t.name)) === 0 || | ||
| logDisc.indexOf(getDiscriminator(pascalCase(t.name))) === 0, | ||
| ); |
There was a problem hiding this comment.
[nitpick] The comment indicates this is fragile due to casing variations. Consider using a more robust approach by trying additional common naming conventions (camelCase, titleCase) or storing discriminators in a map to avoid repeated hash computations.
| return root.program.definedTypes.find( | |
| (t) => | |
| // Warning this is fragile as there can be various casings of the type names, but because it requires hashing data we can only go one way | |
| logDisc.indexOf(getDiscriminator(t.name)) === 0 || | |
| logDisc.indexOf(getDiscriminator(pascalCase(t.name))) === 0, | |
| ); | |
| // Build a map from all possible discriminators to their type nodes, covering common casing conventions | |
| const discriminatorToType = new Map<string, typeof root.program.definedTypes[0]>(); | |
| for (const t of root.program.definedTypes) { | |
| const nameVariants = [ | |
| t.name, | |
| pascalCase(t.name), | |
| camelCase(t.name), | |
| titleCase(t.name), | |
| ]; | |
| for (const variant of nameVariants) { | |
| const disc = getDiscriminator(variant); | |
| discriminatorToType.set(disc.toString('hex'), t); | |
| } | |
| } | |
| const logDiscHex = logDisc.toString('hex'); | |
| return discriminatorToType.get(logDiscHex); |
| // Copyright 2020-2025 SubQuery Pte Ltd authors & contributors | ||
| // SPDX-License-Identifier: GPL-3.0 | ||
|
|
||
| import {createHash} from 'node:crypto'; |
There was a problem hiding this comment.
The import is correctly using the 'node:' prefix for the built-in crypto module, which is good practice for Node.js 16+.
Description
Support decoding logs from codama programs
Type of change
Please delete options that are not relevant.
Checklist