Skip to content

Commit

Permalink
Rename a few field and organize options (#50)
Browse files Browse the repository at this point in the history
* Rename a few field and organize options

* rename
  • Loading branch information
leighmcculloch authored Jul 29, 2022
1 parent 111f4c7 commit 2f2462a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
16 changes: 8 additions & 8 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use crate::utils;
#[derive(Parser, Debug)]
pub struct Cmd {
#[clap(long = "id")]
/// Contract ID in Hexadecimal
/// Contract ID to deploy to
contract_id: String,
/// File that contains a WASM contract
/// WASM file to deploy
#[clap(long, parse(from_os_str))]
file: std::path::PathBuf,
/// File to read and write ledger
wasm: std::path::PathBuf,
/// File to persist ledger state
#[clap(long, parse(from_os_str), default_value("ledger.json"))]
snapshot_file: std::path::PathBuf,
ledger_file: std::path::PathBuf,
}

#[derive(thiserror::Error, Debug)]
Expand All @@ -36,12 +36,12 @@ pub enum Error {
impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let contract_id: [u8; 32] = utils::contract_id_from_str(&self.contract_id)?;
let contract = fs::read(&self.file).unwrap();
let contract = fs::read(&self.wasm).unwrap();

let mut ledger_entries = snapshot::read(&self.snapshot_file)?;
let mut ledger_entries = snapshot::read(&self.ledger_file)?;
utils::add_contract_to_ledger_entries(&mut ledger_entries, contract_id, contract)?;

snapshot::commit(ledger_entries, None, &self.snapshot_file)?;
snapshot::commit(ledger_entries, None, &self.ledger_file)?;
Ok(())
}
}
8 changes: 4 additions & 4 deletions src/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::{fmt::Debug, fs, io, io::Cursor, str::Utf8Error};

#[derive(Parser, Debug)]
pub struct Cmd {
/// WASM file containing contract
/// WASM file to inspect
#[clap(long, parse(from_os_str))]
file: std::path::PathBuf,
wasm: std::path::PathBuf,
}

#[derive(thiserror::Error, Debug)]
Expand All @@ -26,10 +26,10 @@ pub enum Error {

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let contents = fs::read(&self.file)?;
let contents = fs::read(&self.wasm)?;
let h = Host::default();
let vm = Vm::new(&h, [0; 32].into(), &contents)?;
println!("File: {}", self.file.to_string_lossy());
println!("File: {}", self.wasm.to_string_lossy());
println!("Functions:");
for f in vm.functions() {
println!(
Expand Down
34 changes: 18 additions & 16 deletions src/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,32 @@ use crate::utils;

#[derive(Parser, Debug)]
pub struct Cmd {
/// Name of function to invoke
#[clap(long = "fn")]
function: String,
/// File to read and write ledger
#[clap(long, parse(from_os_str), default_value("ledger.json"))]
snapshot_file: std::path::PathBuf,
/// Output the cost of the invocation to stderr
#[clap(long = "cost")]
cost: bool,
#[clap(long, parse(from_os_str))]
file: Option<std::path::PathBuf>,
/// Contract ID to invoke
#[clap(long = "id")]
contract_id: String,
/// Argument to pass to the contract function
/// WASM file to deploy to the contract ID and invoke
#[clap(long, parse(from_os_str))]
wasm: Option<std::path::PathBuf>,
/// Function name to execute
#[clap(long = "fn")]
function: String,
/// Argument to pass to the function
#[clap(long = "arg", value_name = "arg", multiple = true)]
args: Vec<String>,
/// Argument to pass to the contract function (base64-encoded xdr)
/// Argument to pass to the function (base64-encoded xdr)
#[clap(
long = "arg-xdr",
value_name = "arg-xdr",
multiple = true,
conflicts_with = "args"
)]
args_xdr: Vec<String>,
/// Output the cost execution to stderr
#[clap(long = "cost")]
cost: bool,
/// File to persist ledger state
#[clap(long, parse(from_os_str), default_value("ledger.json"))]
ledger_file: std::path::PathBuf,
}

#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -71,10 +73,10 @@ impl Cmd {

// Initialize storage and host
// TODO: allow option to separate input and output file
let mut ledger_entries = snapshot::read(&self.snapshot_file)?;
let mut ledger_entries = snapshot::read(&self.ledger_file)?;

//If a file is specified, deploy the contract to storage
if let Some(f) = &self.file {
if let Some(f) = &self.wasm {
let contract = fs::read(f).unwrap();
utils::add_contract_to_ledger_entries(&mut ledger_entries, contract_id, contract)?;
}
Expand Down Expand Up @@ -136,7 +138,7 @@ impl Cmd {
))
})?;

snapshot::commit(ledger_entries, Some(&storage.map), &self.snapshot_file)?;
snapshot::commit(ledger_entries, Some(&storage.map), &self.ledger_file)?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum Cmd {
Invoke(invoke::Cmd),
/// Inspect a WASM file listing contract functions, meta, etc
Inspect(inspect::Cmd),
/// Writes a contractID and WASM contract directly to storage
/// Deploy a WASM file as a contract
Deploy(deploy::Cmd),
/// Print version information
Version(version::Cmd),
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl SnapshotSource for Snap {
}
}

// snapshot_file format is the default serde JSON representation of VecM<(LedgerKey, LedgerEntry)>
// Ledger file format is the default serde JSON representation of VecM<(LedgerKey, LedgerEntry)>
pub fn read(input_file: &std::path::PathBuf) -> Result<OrdMap<LedgerKey, LedgerEntry>, Error> {
let mut res = OrdMap::new();

Expand Down

0 comments on commit 2f2462a

Please sign in to comment.