Crate cubist_config

source ·
Expand description

This crate exposes the Cubist app/project configuration interface Config.

All cubist applications have a JSON config file cubist-config.json, which specifies:

  • type: the kind of project (ProjType) the off-chain application code is written in,
  • build_dir: where Cubist will write build output (can be overridden via CUBIST_BUILD_DIR env var),
  • deploy_dir: where Cubist will generate deployment scripts and information (can be overridden via CUBIST_DEPLOY_DIR env var),
  • contracts: assignment of contracts to chains (currently per contract source file, not per contract)
  • network_profiles: named profiles containing network/chain configuration (see network configuration),
  • current_network_profile: currently selected network profile (can be overridden via CUBIST_NETWORK_PROFILE env var).

Example JSON file:

{
   "type": "TypeScript",
   "build_dir": "./build",
   "deploy_dir": "./deploy",
   "contracts": {
      "root_dir": "./contracts",
      "targets": {
        "avalanche": { "files": [ "./contracts/ava.sol" ] },
        "polygon":   { "files": [ "./contracts/poly.sol" ] },
        "ethereum":  { "files": [ "./contracts/eth1.sol", "./contracts/eth2.sol" ] }
      }
   },
   "network_profiles": {
     "default": {
       "avalanche": { "url": "http://localhost:9560", "autostart": true },
       "ethereum":  { "url": "http://localhost:7545", "autostart": true },
       "polygon":   { "url": "http://localhost:9545", "autostart": true }
     },
     "dev": {
       "avalanche": { "url": "http://otherhost:9560" },
       "ethereum":  { "url": "http://otherhost:7545" },
       "polygon":   {
         "url": "wss://polygon-mumbai.g.alchemy.com/v2/${{env.ALCHEMY_MUMBAI_API_KEY}}",
         "proxy": {
           "port": 9545,
           "chain_id": 80001,
           "creds": [{
             "mnemonic": { "seed": { "env": "MUMBAI_ACCOUNT_MNEMONIC" } }
           }]
         }
       }
     }
   },
   "current_network_profile": "dev"
}

You can load config files with Config::nearest, which finds the JSON file in the current directory or any parent directory:

use cubist_config::Config;
let cfg = Config::nearest().unwrap();

Alternatively, you can load the default config in the directory:

use cubist_config::Config;
let cfg = Config::from_dir("/path/to/my-app").unwrap();

Alternatively, you can just use Config::from_file if you have the filename of the config file.

use cubist_config::Config;
let cfg = Config::from_file("/path/to/cubist-config.json").unwrap();

Network Configuration

Check the documentation for the network module for more details on:

  • how to configure Cubist to automatically start local chains
  • how to configure Cubist to use public testnets
  • how to put a Cubist Proxy (to automatically handle transaction signing) in front of a public testnet
  • how to pass secrets (e.g., an account mnemonic, or a URL containing a secret API key)

Re-exports

pub use network::AvalancheConfig;
pub use network::CommonConfig;
pub use network::CredConfig;
pub use network::EndpointConfig;
pub use network::EthereumConfig;
pub use network::NetworkProfile;
pub use network::PolygonConfig;
pub use network::ProxyConfig;
pub use pre_compile_manifest::FileArtifact;
pub use pre_compile_manifest::PreCompileManifest;

Modules

Bridge metadata
Interpolated string containing secrets
This module exposes the Cubist network configuration interface NetworkProfile.
Well-known paths
Manifest produced by the ‘pre-compile’ step
Secret management
Various utilities

Structs

Compiler configuration, i.e., configurations that result in compiler flags
Top-level cubist application configuration.
Contract configuration.
A glob pattern for matching files.
Target configuration.

Enums

Bridge provider options Cubist supports
The compiler used for compiling contract code.
Errors raised handling configurations.
Various sources for glob errors
A list of globs or paths (always desrialzed as globs).
The project type. We support writing off-chain code in JavaScript, TypeScript, and Rust.
Target chains (e.g., Avalanche, Polygon, Ethereum) for which we can deploy contracts.

Constants

Default cubist config filename

Type Definitions

A source file that may contain contracts
Type alias for contract name.
Type alias for event name
Type alias for function name
Type alias for “network name” to be used in hash maps
Type alias for “network profile name” to be used in hash maps
An object name (i.e., foo in uint256 foo)
A parameter name
Result with error type defaulting to ConfigError.
A map of chains to target configs