Skip to content

Commit

Permalink
Merge branch 'master' into xunilrj/better-type-inf-numerics
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao authored Nov 11, 2024
2 parents 213be44 + f933f55 commit 6bcd1d2
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 213 deletions.
195 changes: 38 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ unicode-bidi = "0.3"
unicode-xid = "0.2"
url = "2.2"
urlencoding = "2.1"
uwuify = "^0.2"
vec1 = "1.8"
vte = "0.13"
walkdir = "2.3"
Expand Down
9 changes: 7 additions & 2 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
pkg::{built_pkgs, create_proxy_contract, update_proxy_address_in_manifest},
target::Target,
tx::{
prompt_forc_wallet_password, select_account, update_proxy_contract_target,
SignerSelectionMode,
check_and_create_wallet_at_default_path, prompt_forc_wallet_password, select_account,
update_proxy_contract_target, SignerSelectionMode,
},
},
};
Expand Down Expand Up @@ -1002,6 +1002,11 @@ async fn setup_deployment_account(
} else if let Some(arn) = &command.aws_kms_signer {
SignerSelectionMode::AwsSigner(arn.clone())
} else {
// Check if we have a wallet in the default path
// If there is one we will ask for the password
// If not we will ask the user to either create a new one or import one
let wallet_path = default_wallet_path();
check_and_create_wallet_at_default_path(&wallet_path)?;
println_action_green("", &format!("Wallet: {}", default_wallet_path().display()));
let password = prompt_forc_wallet_password()?;
SignerSelectionMode::ForcWallet(password)
Expand Down
47 changes: 30 additions & 17 deletions forc-plugins/forc-client/src/util/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use forc_wallet::{
balance::{
collect_accounts_with_verification, AccountBalances, AccountVerification, AccountsMap,
},
import::{import_wallet_cli, Import},
new::{new_wallet_cli, New},
utils::default_wallet_path,
};
Expand Down Expand Up @@ -45,6 +46,15 @@ fn ask_user_yes_no_question(question: &str) -> Result<bool> {
Ok(answer)
}

fn ask_user_with_options(question: &str, options: &[&str], default: usize) -> Result<usize> {
let selection = Select::with_theme(&ColorfulTheme::default())
.with_prompt(question)
.items(options)
.default(default)
.interact()?;
Ok(selection)
}

fn collect_user_accounts(
wallet_path: &Path,
password: &str,
Expand All @@ -71,21 +81,27 @@ pub(crate) fn prompt_forc_wallet_password() -> Result<String> {

pub(crate) fn check_and_create_wallet_at_default_path(wallet_path: &Path) -> Result<()> {
if !wallet_path.exists() {
let question = format!("Could not find a wallet at {wallet_path:?}, would you like to create a new one? [y/N]: ");
let accepted = ask_user_yes_no_question(&question)?;
let new_options = New {
force: false,
cache_accounts: None,
};
if accepted {
new_wallet_cli(wallet_path, new_options)?;
println!("Wallet created successfully.");
// Derive first account for the fresh wallet we created.
new_at_index_cli(wallet_path, 0)?;
println!("Account derived successfully.");
} else {
anyhow::bail!("Refused to create a new wallet. If you don't want to use forc-wallet, you can sign this transaction manually with --manual-signing flag.")
let question =
format!("Could not find a wallet at {wallet_path:?}, please select an option: ");
let wallet_options = ask_user_with_options(
&question,
&["Create new wallet", "Import existing wallet"],
0,
)?;
match wallet_options {
0 => {
new_wallet_cli(wallet_path, New { force: false, cache_accounts: None })?;
println!("Wallet created successfully.");
}
1 => {
import_wallet_cli(wallet_path, Import { force: false, cache_accounts: None })?;
println!("Wallet imported successfully.");
},
_ => anyhow::bail!("Refused to create or import a new wallet. If you don't want to use forc-wallet, you can sign this transaction manually with --manual-signing flag."),
}
// Derive first account for the fresh wallet we created.
new_at_index_cli(wallet_path, 0)?;
println!("Account derived successfully.");
}
Ok(())
}
Expand Down Expand Up @@ -170,9 +186,6 @@ pub(crate) async fn select_account(
match wallet_mode {
SignerSelectionMode::ForcWallet(password) => {
let wallet_path = default_wallet_path();
check_and_create_wallet_at_default_path(&wallet_path)?;
// TODO: This is a very simple TUI, we should consider adding a nice TUI
// capabilities for selections and answer collection.
let accounts = collect_user_accounts(&wallet_path, password)?;
let account_balances = collect_account_balances(&accounts, provider).await?;
let base_asset_id = provider.base_asset_id();
Expand Down
7 changes: 3 additions & 4 deletions forc-plugins/forc-client/tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ async fn test_non_owner_fails_to_set_target() {
// It would also require overriding `default_wallet_path` function for tests, so as not to interfere with the user's wallet.

#[test]
fn test_deploy_interactive_wrong_password() -> Result<(), rexpect::error::Error> {
fn test_deploy_interactive_missing_wallet() -> Result<(), rexpect::error::Error> {
let (mut node, port) = run_node();
let node_url = format!("http://127.0.0.1:{}/v1/graphql", port);

Expand All @@ -711,9 +711,8 @@ fn test_deploy_interactive_wrong_password() -> Result<(), rexpect::error::Error>
process
.exp_string("\u{1b}[1;32mConfirming\u{1b}[0m transactions [deploy standalone_contract]")?;
process.exp_string(&format!("Network: {node_url}"))?;
process.exp_string("Wallet: ")?;
process.exp_string("Wallet password")?;
process.send_line("mock_password")?;
process.exp_regex("Could not find a wallet at")?;
process.send_line("n")?;

process.process.exit()?;
node.kill().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions forc-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ fn format_diagnostic(diagnostic: &Diagnostic) {
label: if issue.is_in_source() {
None
} else {
Some(issue.friendly_text())
Some(issue.text())
},
id: None,
annotation_type,
Expand All @@ -532,7 +532,7 @@ fn format_diagnostic(diagnostic: &Diagnostic) {
origin: Some(issue.source_path().unwrap().as_str()),
fold: false,
annotations: vec![SourceAnnotation {
label: issue.friendly_text(),
label: issue.text(),
annotation_type,
range: (start_pos, end_pos),
}],
Expand Down Expand Up @@ -594,7 +594,7 @@ fn construct_slice(labels: Vec<&Label>) -> Slice {

for message in labels {
annotations.push(SourceAnnotation {
label: message.friendly_text(),
label: message.text(),
annotation_type: label_type_to_annotation_type(message.label_type()),
range: get_annotation_range(message.span(), source_code, shift_in_bytes),
});
Expand Down
2 changes: 0 additions & 2 deletions forc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ toml = { workspace = true, features = ["parse"] }
toml_edit.workspace = true
tracing.workspace = true
url.workspace = true
uwuify = { workspace = true, optional = true }
walkdir.workspace = true
whoami.workspace = true

[features]
default = []
test = []
util = []
uwu = ["uwuify"]

[dev-dependencies]
completest-pty = "0.5.0"
Expand Down
2 changes: 0 additions & 2 deletions sway-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ smallvec.workspace = true
strsim.workspace = true
sway-types.workspace = true
thiserror.workspace = true
uwuify = { workspace = true, optional = true }

[features]
default = []
uwu = ["uwuify"]

[lints.clippy]
iter_over_hash_type = "deny"
25 changes: 0 additions & 25 deletions sway-error/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ pub struct Label {
label_type: LabelType,
span: Span,
text: String,
friendly_text: String,
source_path: Option<SourcePath>,
}

Expand All @@ -176,13 +175,11 @@ impl Label {
}

fn new(source_engine: &SourceEngine, label_type: LabelType, span: Span, text: String) -> Label {
let friendly_text = Self::maybe_uwuify(text.as_str());
let source_path = Self::get_source_path(source_engine, &span);
Label {
label_type,
span,
text,
friendly_text,
source_path,
}
}
Expand All @@ -204,10 +201,6 @@ impl Label {
self.text.as_ref()
}

pub fn friendly_text(&self) -> &str {
self.friendly_text.as_ref()
}

pub fn source_path(&self) -> Option<&SourcePath> {
self.source_path.as_ref()
}
Expand All @@ -227,23 +220,6 @@ impl Label {
_ => None,
}
}

#[cfg(all(feature = "uwu", any(target_arch = "x86", target_arch = "x86_64")))]
fn maybe_uwuify(raw: &str) -> String {
use uwuifier::uwuify_str_sse;
uwuify_str_sse(raw)
}

#[cfg(all(feature = "uwu", not(any(target_arch = "x86", target_arch = "x86_64"))))]
fn maybe_uwuify(raw: &str) -> String {
compile_error!("The `uwu` feature only works on x86 or x86_64 processors.");
Default::default()
}

#[cfg(not(feature = "uwu"))]
fn maybe_uwuify(raw: &str) -> String {
raw.to_string()
}
}

impl Default for Label {
Expand All @@ -252,7 +228,6 @@ impl Default for Label {
label_type: LabelType::Info,
span: Span::dummy(),
text: "".to_string(),
friendly_text: "".to_string(),
source_path: None,
}
}
Expand Down

0 comments on commit 6bcd1d2

Please # to comment.