Skip to content

daog1/cogoma

Repository files navigation

Cogoma

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.

Project Goals

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.

Current Status

  • 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

Future Goals

  1. Expand test coverage across all packages
  2. Optimize performance for large-scale IDL processing
  3. Enhance integration with Solana Go ecosystem
  4. Add more code generation targets (beyond Python)
  5. Implement advanced validation and error reporting

Packages

node_types

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_types

visitors

Implementation 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/visitors

nodes_from_anchor

IDL 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_parsers

Dynamic parsing utilities for Solana program analysis.

Features:

  • Runtime program parsing
  • Discriminator handling
  • Type identification and parsing
  • Solana-specific optimizations

dynamic_codecs

Runtime encoding and decoding functionality.

Features:

  • Dynamic codec generation
  • Type-safe encoding/decoding
  • Performance optimizations
  • Error handling and validation

renderers_py2

Python code generation from IDL definitions.

Features:

  • Python compatible code generation
  • Complete type system support
  • Template-based rendering
  • Extensible architecture

Core Features

Path Resolver Functions

Implemented path resolver functions identical to the TypeScript version of Codama:

  • GetLastNodeFromPath - Get the last node from a path
  • FindFirstNodeFromPath - Find the first specified type node in a path
  • FindLastNodeFromPath - Find the last specified type node in a path
  • FindProgramNodeFromPath - Find the program node in a path
  • FindInstructionNodeFromPath - Find the instruction node in a path
  • GetNodePathUntilLastNode - Get the path to the last specified type node
  • IsFilledNodePath - Check if the path is non-empty
  • NodePathToStringArray - Convert node path to string array
  • NodePathToString - Convert node path to string representation

Node Type Implementation

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

Getting Started

Installation

go get github.com/daog1/cogoma

Basic Usage

// 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)

Testing

Run tests for all packages:

go test ./...

Run tests for specific package:

go test ./node_types/...
go test ./visitors/...

Documentation

Contributing

We welcome contributions! Please:

  1. Ensure all tests pass: go test ./...
  2. Follow Go coding standards
  3. Add tests for new features
  4. Update documentation as needed

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages