Cogoma is a comprehensive Go implementation of the Codama IDL ecosystem, providing multiple packages for parsing, processing, and generating code from Solana IDL files. The project includes a complete Go language implementation aligned with the TypeScript version 1.3.4.
The Cogoma project aims to provide a complete Go language implementation of the Codama IDL ecosystem, achieving full alignment with the functionality of the TypeScript version 1.3.4 and providing additional Go-specific utilities.
- node_types: Complete implementation of 67/67 (100%) node types with comprehensive type and value systems
- visitors: Full visitor pattern implementation for node traversal and manipulation
- nodes_from_anchor: IDL parsing functionality for converting Anchor IDL to Codama nodes
- dynamic_parsers: Dynamic parsing utilities for Solana programs
- dynamic_codecs: Runtime encoding/decoding functionality
- renderers_py: Python code generation from IDL
- Implemented path resolver functions identical to the TypeScript version of Codama
- Expand test coverage across all packages
- Optimize performance for large-scale IDL processing
- Enhance integration with Solana Go ecosystem
- Add more code generation targets (beyond Python)
- Implement advanced validation and error reporting
The core package providing complete Codama IDL node type implementations.
Features:
- 67/67 (100%) node types implemented
- Comprehensive type and value systems
- Builder patterns for complex node construction
- JSON serialization/deserialization
- Validation and error handling
- Convenience functions for common operations
Installation:
go get github.com/daog1/cogoma/node_typesImplementation of the visitor pattern for traversing and manipulating node trees.
Features:
- NodePath: Path manipulation utilities
- NodeStack: Stack-based node traversal
- LinkableDictionary: Linkable node management
- Visitor Pattern: Core traversal functionality
- Pipe: Function composition utilities
- RecordLinkables: Link recording during traversal
Installation:
go get github.com/daog1/cogoma/visitorsIDL parsing functionality for converting Anchor IDL files to Codama nodes.
Features:
- Anchor IDL v0.0 and v0.1 support
- Complete node type conversion
- Path resolution and validation
- Support for complex Solana programs
Dynamic parsing utilities for Solana program analysis.
Features:
- Runtime program parsing
- Discriminator handling
- Type identification and parsing
- Solana-specific optimizations
Runtime encoding and decoding functionality.
Features:
- Dynamic codec generation
- Type-safe encoding/decoding
- Performance optimizations
- Error handling and validation
Python code generation from IDL definitions.
Features:
- Python compatible code generation
- Complete type system support
- Template-based rendering
- Extensible architecture
Implemented path resolver functions identical to the TypeScript version of Codama:
GetLastNodeFromPath- Get the last node from a pathFindFirstNodeFromPath- Find the first specified type node in a pathFindLastNodeFromPath- Find the last specified type node in a pathFindProgramNodeFromPath- Find the program node in a pathFindInstructionNodeFromPath- Find the instruction node in a pathGetNodePathUntilLastNode- Get the path to the last specified type nodeIsFilledNodePath- Check if the path is non-emptyNodePathToStringArray- Convert node path to string arrayNodePathToString- Convert node path to string representation
Complete implementation of all 67 node types, including:
- All basic type nodes (Number, String, Boolean, Bytes, PublicKey)
- All composite type nodes (Struct, Array, Option, Enum, Map, Set, Tuple)
- All modifier type nodes (SizePrefix, HiddenPrefix, PostOffset, PreOffset)
- All link nodes (DefinedTypeLink, ProgramLink, AccountLink, PDALink)
- All PDA-related nodes (PDANode, PDASeed nodes)
- All contextual value nodes (AccountBump, PDASeed, Resolver values)
- All discriminator nodes (Constant, Field, Size discriminators)
- All count nodes (FixedCount, RemainderCount, PrefixedCount)
- All value nodes (Number, String, Boolean, Bytes, PublicKey, Struct, Array, Enum, Map, Set, Tuple values)
- All enum variant type nodes (Empty, Struct, Tuple variants)
- All type and value base interfaces
Documentation on node types can be found in node_types/README.md
go get github.com/daog1/cogoma// Import the main packages
import (
"github.com/daog1/cogoma/node_types"
"github.com/daog1/cogoma/visitors"
)
// Create a simple struct type
structType := node_types.Struct(
node_types.U64Field("id"),
node_types.StringField("name"),
)
// Use visitor pattern for traversal
counter := &NodeCounter{}
walker := node_types.NewWalker(counter)
err := walker.Walk(structType)Run tests for all packages:
go test ./...Run tests for specific package:
go test ./node_types/...
go test ./visitors/...- node_types - Core node type implementations
- node_types/README_zh.md - 中文文档
- visitors - Visitor pattern implementation
- nodes_from_anchor - Anchor IDL parsing
- dynamic_parsers - Dynamic parsing utilities
We welcome contributions! Please:
- Ensure all tests pass:
go test ./... - Follow Go coding standards
- Add tests for new features
- Update documentation as needed
MIT