Skip to content

Commit

Permalink
Merge pull request #28398 from ProvableHQ/only-testnet
Browse files Browse the repository at this point in the history
only_testnet feature.
  • Loading branch information
d0cd authored Oct 16, 2024
2 parents 3d21dd5 + e7d1645 commit 00fcc07
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ path = "leo/cli/main.rs"
default = [ ]
ci_skip = [ "leo-compiler/ci_skip" ]
noconfig = [ ]
# TODO: Consider refactoring to `testnet`, `mainnet`, and `canary` features, with all three being the default.
only_testnet = [ ]

[dependencies]
dialoguer = "0.11.0"
Expand Down
60 changes: 51 additions & 9 deletions leo/cli/commands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use crossterm::ExecutableCommand;
use leo_retriever::NetworkName;
use rand::SeedableRng;
use rand_chacha::ChaChaRng;
use snarkvm::prelude::{CanaryV0, MainnetV0, Network, TestnetV0};
#[cfg(not(feature = "only_testnet"))]
use snarkvm::prelude::{CanaryV0, MainnetV0};
use snarkvm::prelude::{Network, TestnetV0};
use std::{
io::{self, Read, Write},
path::PathBuf,
Expand Down Expand Up @@ -133,37 +135,77 @@ impl Command for Account {
// Parse the network.
let network = NetworkName::try_from(network.as_str())?;
match network {
NetworkName::MainnetV0 => generate_new_account::<MainnetV0>(seed, write, discreet, &ctx, endpoint),
NetworkName::TestnetV0 => generate_new_account::<TestnetV0>(seed, write, discreet, &ctx, endpoint),
NetworkName::CanaryV0 => generate_new_account::<CanaryV0>(seed, write, discreet, &ctx, endpoint),
NetworkName::MainnetV0 => {
#[cfg(feature = "only_testnet")]
panic!("Mainnet chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
generate_new_account::<MainnetV0>(seed, write, discreet, &ctx, endpoint)
}
NetworkName::CanaryV0 => {
#[cfg(feature = "only_testnet")]
panic!("Canary chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
generate_new_account::<CanaryV0>(seed, write, discreet, &ctx, endpoint)
}
}?
}
Account::Import { private_key, write, discreet, network, endpoint } => {
// Parse the network.
let network = NetworkName::try_from(network.as_str())?;
match network {
NetworkName::MainnetV0 => import_account::<MainnetV0>(private_key, write, discreet, &ctx, endpoint),
NetworkName::TestnetV0 => import_account::<TestnetV0>(private_key, write, discreet, &ctx, endpoint),
NetworkName::CanaryV0 => import_account::<CanaryV0>(private_key, write, discreet, &ctx, endpoint),
NetworkName::MainnetV0 => {
#[cfg(feature = "only_testnet")]
panic!("Mainnet chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
import_account::<MainnetV0>(private_key, write, discreet, &ctx, endpoint)
}
NetworkName::CanaryV0 => {
#[cfg(feature = "only_testnet")]
panic!("Canary chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
import_account::<CanaryV0>(private_key, write, discreet, &ctx, endpoint)
}
}?
}
Self::Sign { message, raw, private_key, private_key_file, network } => {
// Parse the network.
let network = NetworkName::try_from(network.as_str())?;
let result = match network {
NetworkName::MainnetV0 => sign_message::<MainnetV0>(message, raw, private_key, private_key_file),
NetworkName::TestnetV0 => sign_message::<TestnetV0>(message, raw, private_key, private_key_file),
NetworkName::CanaryV0 => sign_message::<MainnetV0>(message, raw, private_key, private_key_file),
NetworkName::MainnetV0 => {
#[cfg(feature = "only_testnet")]
panic!("Mainnet chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
sign_message::<MainnetV0>(message, raw, private_key, private_key_file)
}
NetworkName::CanaryV0 => {
#[cfg(feature = "only_testnet")]
panic!("Canary chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
sign_message::<CanaryV0>(message, raw, private_key, private_key_file)
}
}?;
println!("{result}")
}
Self::Verify { address, signature, message, raw, network } => {
// Parse the network.
let network = NetworkName::try_from(network.as_str())?;
let result = match network {
NetworkName::MainnetV0 => verify_message::<MainnetV0>(address, signature, message, raw),
NetworkName::TestnetV0 => verify_message::<TestnetV0>(address, signature, message, raw),
NetworkName::CanaryV0 => verify_message::<CanaryV0>(address, signature, message, raw),
NetworkName::MainnetV0 => {
#[cfg(feature = "only_testnet")]
panic!("Mainnet chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
verify_message::<MainnetV0>(address, signature, message, raw)
}
NetworkName::CanaryV0 => {
#[cfg(feature = "only_testnet")]
panic!("Canary chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
verify_message::<CanaryV0>(address, signature, message, raw)
}
}?;
println!("{result}")
}
Expand Down
23 changes: 18 additions & 5 deletions leo/cli/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ use dialoguer::{Confirm, theme::ColorfulTheme};
use leo_retriever::NetworkName;
use num_format::{Locale, ToFormattedString};
use snarkvm::{
circuit::{Aleo, AleoCanaryV0, AleoTestnetV0, AleoV0},
circuit::{Aleo, AleoTestnetV0},
ledger::query::Query as SnarkVMQuery,
package::Package as SnarkVMPackage,
prelude::{
CanaryV0,
MainnetV0,
ProgramOwner,
TestnetV0,
VM,
deployment_cost,
store::{ConsensusStore, helpers::memory::ConsensusMemory},
},
};
#[cfg(not(feature = "only_testnet"))]
use snarkvm::{
circuit::{AleoCanaryV0, AleoV0},
prelude::{CanaryV0, MainnetV0},
};
use std::path::PathBuf;
use text_tables;

Expand Down Expand Up @@ -75,9 +78,19 @@ impl Command for Deploy {
let network = NetworkName::try_from(context.get_network(&self.options.network)?)?;
let endpoint = context.get_endpoint(&self.options.endpoint)?;
match network {
NetworkName::MainnetV0 => handle_deploy::<AleoV0, MainnetV0>(&self, context, network, &endpoint),
NetworkName::TestnetV0 => handle_deploy::<AleoTestnetV0, TestnetV0>(&self, context, network, &endpoint),
NetworkName::CanaryV0 => handle_deploy::<AleoCanaryV0, CanaryV0>(&self, context, network, &endpoint),
NetworkName::MainnetV0 => {
#[cfg(feature = "only_testnet")]
panic!("Mainnet chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
return handle_deploy::<AleoV0, MainnetV0>(&self, context, network, &endpoint);
}
NetworkName::CanaryV0 => {
#[cfg(feature = "only_testnet")]
panic!("Canary chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
return handle_deploy::<AleoCanaryV0, CanaryV0>(&self, context, network, &endpoint);
}
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions leo/cli/commands/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ use std::collections::HashMap;
use crate::cli::query::QueryCommands;
use dialoguer::{Confirm, theme::ColorfulTheme};
use leo_retriever::NetworkName;
#[cfg(not(feature = "only_testnet"))]
use snarkvm::circuit::{AleoCanaryV0, AleoV0};
use snarkvm::{
circuit::{Aleo, AleoCanaryV0, AleoTestnetV0, AleoV0},
circuit::{Aleo, AleoTestnetV0},
cli::LOCALE,
ledger::Transaction::Execute as ExecuteTransaction,
package::Package as SnarkVMPackage,
Expand Down Expand Up @@ -92,9 +94,19 @@ impl Command for Execute {
let network = NetworkName::try_from(context.get_network(&self.compiler_options.network)?)?;
let endpoint = context.get_endpoint(&self.compiler_options.endpoint)?;
match network {
NetworkName::MainnetV0 => handle_execute::<AleoV0>(self, context, network, &endpoint),
NetworkName::TestnetV0 => handle_execute::<AleoTestnetV0>(self, context, network, &endpoint),
NetworkName::CanaryV0 => handle_execute::<AleoCanaryV0>(self, context, network, &endpoint),
NetworkName::MainnetV0 => {
#[cfg(feature = "only_testnet")]
panic!("Mainnet chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
return handle_execute::<AleoV0>(self, context, network, &endpoint);
}
NetworkName::CanaryV0 => {
#[cfg(feature = "only_testnet")]
panic!("Canary chosen with only_testnet feature");
#[cfg(not(feature = "only_testnet"))]
return handle_execute::<AleoCanaryV0>(self, context, network, &endpoint);
}
}
}
}
Expand Down

0 comments on commit 00fcc07

Please sign in to comment.