Skip to content

Commit

Permalink
seed mneumonic phrase processing
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed Aug 6, 2024
1 parent d4fcf32 commit b6f716c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions dusk-deploy-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ wallet = { path = "../wallet" }
rusk-http-client = { path = "../rusk-http-client" }
execution-core = { path = "../../rusk/execution-core" }
rusk-prover = { path = "../../rusk/rusk-prover" }
tiny-bip39 = "0.8"
dusk-bls12_381 = "0.12"
dusk-plonk = "0.19"
poseidon-merkle = { version = "0.6", features = ["rkyv-impl"] }
Expand Down
16 changes: 4 additions & 12 deletions dusk-deploy-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,13 @@ use clap::Parser;
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Args {
/// Wallet directory [default: `$HOME/.dusk/rusk-wallet`]
#[clap(short, long, default_value = concat!(env!("HOME"), "/.dusk/rusk-wallet"))]
pub wallet_path: PathBuf,

/// Blockchain access config directory
#[clap(long, default_value = "./config.toml")]
pub config_path: PathBuf,

/// Password for the wallet
#[clap(long, default_value_t = String::from(""), env = "RUSK_WALLET_PWD")]
pub wallet_pass: String,

/// Hash of the password for the wallet [default: ``]
#[clap(short, long, default_value_t = String::from(""))]
pub pwd_hash: String,
/// Seed phrase [default: ``]
#[clap(long, default_value_t = String::from("spice property autumn primary undo innocent pole legend stereo mom eternal topic"))]
pub seed: String,

/// Gas limit [default: `500000000`]
#[clap(long, default_value_t = 500000000)]
Expand All @@ -37,7 +29,7 @@ pub struct Args {
pub gas_price: u64,

/// Path to contract code
#[clap(short, long, default_value = "./test/alice.wasm")]
#[clap(short, long, default_value = "./test/bob.wasm")]
pub contract_path: PathBuf,

/// Hexadecimal string of contract's owner [default: ``]
Expand Down
5 changes: 4 additions & 1 deletion dusk-deploy-cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ pub enum Error {
/// Prover Errors
#[error("Prover error occurred: {0:?}")]
Prover(Arc<rusk_prover::ProverError>),
/// Wallet2 Errors
/// Wallet Errors
#[error("Wallet error occurred")] // todo
Wallet(Arc<wallet::Error<DCliStore, DCliStateClient, DCliProverClient>>),
/// Seed phrase is not valid
#[error("Invalid recovery phrase")]
InvalidMnemonicPhrase,
}

impl From<wallet::Error<DCliStore, DCliStateClient, DCliProverClient>> for Error {
Expand Down
55 changes: 44 additions & 11 deletions dusk-deploy-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ mod wallet_builder;
use crate::args::Args;
use crate::config::BlockchainAccessConfig;
use crate::error::Error;
use bip39::{Language, Mnemonic, Seed};
use clap::Parser;
use execution_core::transfer::ContractId;
use rusk_http_client::{ContractInquirer, RuskHttpClient};
use std::fs::File;
use std::io::Read;
use std::thread;
use toml_base_config::BaseConfig;

use crate::deployer::Deployer;
Expand All @@ -32,9 +36,7 @@ async fn main() -> Result<(), Error> {
let cli = Args::parse();

let config_path = cli.config_path.as_path();
let _wallet_path = cli.wallet_path.as_path();
let _password = cli.wallet_pass;
let _pwd_hash = cli.pwd_hash;
let seed_phrase = cli.seed;
let gas_limit = cli.gas_limit;
let gas_price = cli.gas_price;
let contract_path = cli.contract_path.as_path();
Expand All @@ -47,19 +49,26 @@ async fn main() -> Result<(), Error> {
let mut bytecode = Vec::new();
bytecode_file.read_to_end(&mut bytecode)?;

let constructor_args: Option<Vec<u8>> = None;
let constructor_args: Option<Vec<u8>> = Some(vec![38u8]);

let wallet_index = 0;

let seed_vec = hex::decode("7965013909185294fa0f0d2a2be850ee89389e45d17e0c7da9a7588901648086c5b3ac52d95b6fd421104b6a77ca21772f0a041f031c3c8039ae3b24c48467bd")
.expect("decoding seed should succeed");
// let seed_vec = hex::decode("7965013909185294fa0f0d2a2be850ee89389e45d17e0c7da9a7588901648086c5b3ac52d95b6fd421104b6a77ca21772f0a041f031c3c8039ae3b24c48467bd")
// .expect("decoding seed should succeed");
// let mut seed = [0u8; 64];
// seed.copy_from_slice(seed_vec.as_slice());

let phrase = seed_phrase.to_string();
let mnemonic = Mnemonic::from_phrase(&phrase, Language::English)
.map_err(|_| Error::InvalidMnemonicPhrase)?;
let seed_obj = Seed::new(&mnemonic, "");
let mut seed = [0u8; 64];
seed.copy_from_slice(seed_vec.as_slice());
seed.copy_from_slice(seed_obj.as_bytes());

let owner = hex::decode(owner).expect("decoding owner should succeed");

let result = Deployer::deploy(
blockchain_access_config.rusk_address,
blockchain_access_config.rusk_address.clone(),
blockchain_access_config.prover_address,
&bytecode,
&owner,
Expand All @@ -71,11 +80,35 @@ async fn main() -> Result<(), Error> {
&seed,
);

println!("deployment result = {:?}", result);
println!(
"deployed contract id = {}",
hex::encode(gen_contract_id(bytecode, nonce, owner))
"deployment result for contract: {:?} is: {:?}",
contract_path, result
);
let deployed_id = gen_contract_id(bytecode, nonce, owner);
println!("deployed contract id: {}", hex::encode(&deployed_id));

verify_deployment(deployed_id, blockchain_access_config.rusk_address).await;

Ok(())
}

async fn verify_deployment(contract_id: [u8; 32], rusk_url: impl AsRef<str>) {
const METHOD: &str = "value";
println!(
"verifying deployment by calling contract's method: {}",
METHOD
);

thread::sleep(std::time::Duration::from_secs(10));

let client = RuskHttpClient::new(rusk_url.as_ref().to_string());
let r = ContractInquirer::query_contract::<(), u8>(
&client,
(),
ContractId::from(contract_id),
METHOD,
)
.await;

println!("result of calling the contract's method: {:?}", r);
}
Binary file added test/bob.wasm
Binary file not shown.

0 comments on commit b6f716c

Please sign in to comment.