Skip to content

Commit

Permalink
use a default caller address if not using Leo project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebenfield committed Nov 22, 2024
1 parent b2b0513 commit a453ad3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
29 changes: 18 additions & 11 deletions leo/cli/commands/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ impl Command for LeoDebug {
}

fn prelude(&self, context: Context) -> Result<Self::Input> {
(LeoBuild { options: self.compiler_options.clone() }).execute(context)
if self.paths.is_empty() {
(LeoBuild { options: self.compiler_options.clone() }).execute(context)
} else {
Ok(())
}
}

fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
Expand All @@ -74,19 +78,19 @@ impl Command for LeoDebug {
}

fn handle_debug<N: Network>(command: &LeoDebug, context: Context) -> Result<()> {
// Get the package path.
let package_path = context.dir()?;
let home_path = context.home()?;
if command.paths.is_empty() {
// Get the package path.
let package_path = context.dir()?;
let home_path = context.home()?;

// Get the program id.
let manifest = Manifest::read_from_dir(&package_path)?;
let program_id = ProgramID::<N>::from_str(manifest.program())?;
// Get the program id.
let manifest = Manifest::read_from_dir(&package_path)?;
let program_id = ProgramID::<N>::from_str(manifest.program())?;

// Get the private key.
let private_key = context.get_private_key(&None)?;
let address = Address::try_from(&private_key)?;
// Get the private key.
let private_key = context.get_private_key(&None)?;
let address = Address::try_from(&private_key)?;

if command.paths.is_empty() {
// Retrieve all local dependencies in post order
let main_sym = Symbol::intern(&program_id.name().to_string());
let mut retriever = Retriever::<N>::new(
Expand All @@ -112,6 +116,9 @@ fn handle_debug<N: Network>(command: &LeoDebug, context: Context) -> Result<()>

leo_interpreter::interpret(&paths, &[], address, command.block_height)
} else {
let private_key: PrivateKey<TestnetV0> = PrivateKey::from_str(leo_package::VALIDATOR_0_PRIVATE_KEY)?;
let address = Address::try_from(&private_key)?;

let leo_paths: Vec<PathBuf> = command
.paths
.iter()
Expand Down
2 changes: 2 additions & 0 deletions leo/package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use std::{fs, fs::ReadDir, path::PathBuf};

pub static LEO_FILE_EXTENSION: &str = ".leo";

pub static VALIDATOR_0_PRIVATE_KEY: &str = "APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH";

pub(crate) fn parse_file_paths(directory: ReadDir, file_paths: &mut Vec<PathBuf>) -> Result<()> {
for file_entry in directory {
let file_entry = file_entry.map_err(PackageError::failed_to_get_leo_file_entry)?;
Expand Down
7 changes: 2 additions & 5 deletions leo/package/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use crate::{
VALIDATOR_0_PRIVATE_KEY,
root::{Env, Gitignore},
source::{MainFile, SourceDirectory},
};
Expand Down Expand Up @@ -148,11 +149,7 @@ impl Package {

// Create the .env file.
// Include the private key of validator 0 for ease of use with local devnets, as it will automatically be seeded with funds.
Env::<N>::new(
Some(PrivateKey::<N>::from_str("APrivateKey1zkp8CZNn3yeCseEtxuVPbDCwSyhGW6yZKUYKfgXmcpoGPWH")?),
endpoint,
)?
.write_to(&path)?;
Env::<N>::new(Some(PrivateKey::<N>::from_str(VALIDATOR_0_PRIVATE_KEY)?), endpoint)?.write_to(&path)?;

// Create a manifest.
let manifest = Manifest::default(package_name);
Expand Down

0 comments on commit a453ad3

Please sign in to comment.