Conversation
Workaround turn it into an empty struct basically
There was a problem hiding this comment.
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-57crate 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.
| fn load_source(&self, path: &str) -> std::io::Result<String> { | ||
| let full_path = self.root.join(path); | ||
| std::fs::read_to_string(full_path) | ||
| } |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.
| 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, | |
| })); |
This pull request introduces support for imports in the
tx3-langlanguage, allowing programs to reference external files such as JSON blueprints. It adds a newcip-57crate 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
ImportDefstruct to the AST and updatedProgramto support a list of imports. Parsing logic and grammar were extended to recognize and process import statements.CIP-57 blueprint support
cip-57crate, including itsCargo.tomland a comprehensivelib.rsdefining blueprint structures for JSON parsing and serialization according to CIP-57.cip-57crate as a workspace member and as a dependency intx3-lang.Example and test coverage
examples/imported_datum.tx3to demonstrate how an external JSON blueprint can be imported and used in a transaction definition.These changes collectively enable the
tx3-langlanguage to import and reference external data and schemas, improving extensibility and interoperability with Cardano standards.