Expand description
This crate deals with Leo packages on the file system and network.
The main type is Package, which deals with Leo packages on the local filesystem.
A Leo package directory is intended to have a structure like this:
.
├── program.json
├── build
│ ├── my_program
│ │ ├── my_program.aleo
│ │ └── abi.json
│ └── credits
│ └── credits.aleo
├── src
│ └── main.leo
└── tests
└── test_something.leo
Inside build, every compilation unit - the package’s own program or
library, its local dependencies, and fetched network imports - gets its own
build/<name>/ directory with the same shape. When compiler-debug AST
snapshots are requested they appear under build/<name>/snapshots/.
The file program.json is a manifest containing the program name, version, description,
and license, together with information about its dependencies.
Such a directory structure, together with a .gitignore file, may be created
on the file system using Package::initialize.
let path = Package::initialize("my_package", "path/to/parent", false).unwrap();tests is where unit test files may be placed.
Given an existing directory with such a structure, a Package may be created from it with
Package::from_directory:
use leo_package::Package;
let package = Package::from_directory("path/to/package", "/home/me/.aleo", false, false, Some(NetworkName::TestnetV0), Some("http://localhost:3030"), 3).unwrap();This will read the manifest and keep their data in package.manifest.
It will also process dependencies and store them in topological order in package.compilation_units. This processing
will involve fetching bytecode from the network for network dependencies.
If the no_cache option (3rd parameter) is set to true, the package will not use the dependency cache.
The endpoint and network are optional and are only needed if the package has network dependencies.
If you want to simply read the manifest file without processing dependencies, use
Package::from_directory_no_graph.
CompilationUnit generally doesn’t need to be created directly, as Package will create CompilationUnits
for the main program and all dependencies. However, if you’d like to fetch bytecode for
a program, you can use CompilationUnit::fetch.
Structs§
- Compilation
Unit - Information about a single Leo compilation unit.
- Dependency
- Information about a dependency, as represented in the
program.jsonmanifest. - Manifest
- Struct representation of program’s
program.jsonspecification. - Package
- A Leo package.
- Workspace
- A Leo workspace - a collection of member packages under a single root.
- Workspace
Manifest - The contents of a
workspace.jsonmanifest.
Enums§
- Location
- Package
Kind - The kind of a Leo compilation unit: a deployable program, a library, or a test.
- Program
Data - Either the bytecode of an Aleo program (if it was a network dependency) or a path to its source (if it was local).
Constants§
- ABI_
FILENAME - BUILD_
DIRECTORY - INTERFACES_
DIRNAME - Name of the per-unit subdirectory holding interface ABI JSON files.
- LIB_
FILENAME - MAIN_
FILENAME - MANIFEST_
FILENAME - MAX_
PROGRAM_ SIZE - Maximum allowed program size in bytes.
- SNAPSHOTS_
DIRNAME - Name of the per-unit subdirectory holding compiler-debug AST snapshots. Created lazily on first write; absent on builds that don’t request snapshots.
- SOURCE_
DIRECTORY - TESTS_
DIRECTORY - WORKSPACE_
MANIFEST_ FILENAME
Functions§
- bare_
unit_ name - Strips a trailing
.aleo(the Aleo program-ID suffix) from a compilation unit name, yielding the bare name. - create_
http_ agent - Creates a configured ureq agent for Leo network requests.
- fetch_
from_ network - fetch_
from_ network_ plain - fetch_
latest_ edition - Fetch the latest edition of a program from the network.
- fetch_
program_ from_ network - Fetch the given program from the network and return the program as a string.
- filename_
no_ aleo_ extension - filename_
no_ leo_ extension - is_
valid_ library_ name - Checks whether a string is a valid Aleo library name.
- is_
valid_ program_ name - Checks whether a string is a valid Aleo program name.
- reserved_
keywords - Get the list of all reserved and restricted keywords from snarkVM. These keywords cannot be used as program names. See: https://github.com/ProvableHQ/snarkVM/blob/046a2964f75576b2c4afbab9aa9eabc43ceb6dc3/synthesizer/program/src/lib.rs#L192
- resolve_
workspace_ dependency - Resolve a
Location::Workspacedependency by looking up its name in the enclosing workspace, returning a newDependencywithLocation::Localand the resolved absolute path. - retry_
network_ call - Retries a fallible network operation with exponential backoff.
- verify_
valid_ program
Type Aliases§
- Edition
- The edition of a deployed program on the Aleo network. Edition 0 is the initial deployment, and increments with each upgrade.