Skip to content

Importing types from cip 57 files#288

Open
nicolasLuduena wants to merge 20 commits intomainfrom
259-feat-plutusjson-imports-new
Open

Importing types from cip 57 files#288
nicolasLuduena wants to merge 20 commits intomainfrom
259-feat-plutusjson-imports-new

Conversation

@nicolasLuduena
Copy link
Contributor

This pull request introduces support for imports in the tx3-lang language, allowing programs to reference external files such as JSON blueprints. It adds a new cip-57 crate for Cardano CIP-57 compatibility, updates parsing and AST structures to handle imports, and demonstrates the feature with a new example. The most important changes are grouped below.

Import system integration

  • Added ImportDef struct to the AST and updated Program to support a list of imports. Parsing logic and grammar were extended to recognize and process import statements.

CIP-57 blueprint support

  • Added the new cip-57 crate, including its Cargo.toml and a comprehensive lib.rs defining blueprint structures for JSON parsing and serialization according to CIP-57.
  • Registered the cip-57 crate as a workspace member and as a dependency in tx3-lang.

Example and test coverage

  • Added examples/imported_datum.tx3 to demonstrate how an external JSON blueprint can be imported and used in a transaction definition.
  • Expanded parsing tests to include import handling and updated test fixtures for the new import feature.

These changes collectively enable the tx3-lang language to import and reference external data and schemas, improving extensibility and interoperability with Cardano standards.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an import system to tx3-lang and introduces a new cip-57 crate to parse Cardano CIP-57 Plutus blueprints, enabling external JSON-defined types to be referenced from Tx3 programs.

Changes:

  • Extended the Tx3 grammar/AST/parser to support import "path" as alias;.
  • Added an import resolver that loads CIP-57 JSON blueprints and converts definitions into Tx3 TypeDefs.
  • Added a new cip-57 crate plus an example Tx3 program and snapshot fixture demonstrating the feature.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
examples/imported_datum.tx3 Demonstrates importing a CIP-57 blueprint and constructing imported types.
examples/imported_datum.ast New AST snapshot fixture for the example program.
crates/tx3-lang/src/tx3.pest Adds import_def grammar and allows imports at program top-level.
crates/tx3-lang/src/parsing.rs Parses import statements into the AST and updates tests/fixtures.
crates/tx3-lang/src/lib.rs Exposes the new importing module.
crates/tx3-lang/src/importing.rs Implements CIP-57 JSON loading + mapping definitions to Tx3 types, with tests.
crates/tx3-lang/src/facade.rs Resolves imports during Workspace::parse() when a filesystem root is available.
crates/tx3-lang/src/cardano.rs Minor test import cleanup.
crates/tx3-lang/src/ast.rs Adds Program.imports and new ImportDef AST node.
crates/tx3-lang/Cargo.toml Adds cip-57 and serde_json dependencies.
crates/cip-57/src/lib.rs Implements CIP-57 blueprint structures for serde (de)serialization.
crates/cip-57/examples/plutus.json Adds a sample Plutus blueprint JSON used by examples/tests.
crates/cip-57/Cargo.toml New crate manifest for cip-57.
Cargo.toml Registers crates/cip-57 as a workspace member.
Cargo.lock Adds cip-57 to the lockfile and updates dependency graph.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +66 to +69
fn load_source(&self, path: &str) -> std::io::Result<String> {
let full_path = self.root.join(path);
std::fs::read_to_string(full_path)
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FsLoader::load_source allows absolute paths (where PathBuf::join ignores root) and .. path traversal, so an import can read files outside the intended project root. Consider rejecting absolute paths and normalizing/canonicalizing the joined path, then enforcing it stays under root before reading.

Copilot uses AI. Check for mistakes.
Comment on lines +209 to +220
if key == "Data" {
return Ok(Some(TypeDef {
name: Identifier::new(import_type_name(key, alias)),
cases: vec![VariantCase {
name: Identifier::new("Default"),
fields: vec![],
span: Span::DUMMY,
}],
span: Span::DUMMY,
}));
}
return Ok(None);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitions without anyOf (and without a primitive/list/map dataType) are currently skipped unless the key is exactly Data. However resolve_ref_to_type will still return Type::Custom for these refs (e.g. cardano/transaction/Redeemer in the included example blueprint), which can lead to unresolved types during analysis. Consider importing such definitions as an opaque placeholder (e.g. a single empty Default case) or mapping them to an existing "any data" type, instead of skipping them here.

Suggested change
if key == "Data" {
return Ok(Some(TypeDef {
name: Identifier::new(import_type_name(key, alias)),
cases: vec![VariantCase {
name: Identifier::new("Default"),
fields: vec![],
span: Span::DUMMY,
}],
span: Span::DUMMY,
}));
}
return Ok(None);
return Ok(Some(TypeDef {
name: Identifier::new(import_type_name(key, alias)),
cases: vec![VariantCase {
name: Identifier::new("Default"),
fields: vec![],
span: Span::DUMMY,
}],
span: Span::DUMMY,
}));

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

feat: plutus.json imports

2 participants