Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/modality-cli-contract/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ pub async fn make(opts: &Opts) -> Result<Option<Committed>> {

// Validate against contract rules (signature predicates, etc.)
store.validate_commit_against_rules(&commit)?;
#[cfg_attr(not(feature = "model-status"), allow(unused_mut))]
let mut model_repair = None;
let theory_preview = match validate_commit_against_model(&dir, &store, &commit, &opts.theory) {
Ok(preview) => preview,
Expand Down
46 changes: 43 additions & 3 deletions rust/modality-cli-contract/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,56 @@ async fn create(opts: &CreateOpts) -> Result<()> {
Ok(())
}

fn local_address(opts: &WalletOpts) -> Result<String> {
let dir = wallet_dir(&opts.dir)?;
let store = ContractStore::open(&dir)
.with_context(|| format!("no wallet at {}; run `modal wallet create`", dir.display()))?;
let _: WalletFile = serde_json::from_str(
&std::fs::read_to_string(store.contract_dir().join(WALLET_FILE))
.with_context(|| format!("{} is a contract, not a wallet", dir.display()))?,
)?;
Ok(store.load_config()?.contract_id)
}

fn address(opts: &WalletOpts) -> Result<()> {
let wallet = Wallet::open(opts)?;
// Sharing an address only needs local wallet metadata, not a configured node.
let id = local_address(opts)?;
if opts.output == "json" {
println!("{}", json!({ "address": wallet.id }));
println!("{}", json!({ "address": id }));
} else {
println!("{}", wallet.id);
println!("{}", id);
}
Ok(())
}

#[cfg(test)]
mod address_tests {
use super::*;

#[test]
fn address_does_not_require_a_remote() -> Result<()> {
let dir = tempfile::tempdir()?;
let store = ContractStore::init(dir.path(), "wallet-id".to_string())?;
std::fs::write(
store.contract_dir().join(WALLET_FILE),
serde_json::to_string(&WalletFile {
key: dir.path().join("owner.mod_passfile"),
})?,
)?;
let opts = WalletOpts {
dir: Some(dir.path().to_path_buf()),
remote: None,
output: "text".to_string(),
};
assert_eq!(local_address(&opts)?, "wallet-id");
assert!(
Wallet::open(&opts).is_err(),
"network commands still need a remote"
);
Ok(())
}
}

async fn balance(opts: &WalletOpts) -> Result<()> {
let wallet = Wallet::open(opts)?;
let account = wallet.account().await?;
Expand Down
Loading