Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate forc-wallet and forc-deploy #4752

Merged
merged 7 commits into from
Jul 6, 2023
Merged
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
194 changes: 193 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions forc-plugins/forc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ forc-pkg = { version = "0.42.0", path = "../../forc-pkg" }
forc-tracing = { version = "0.42.0", path = "../../forc-tracing" }
forc-tx = { version = "0.42.0", path = "../forc-tx" }
forc-util = { version = "0.42.0", path = "../../forc-util" }
forc-wallet = "0.2.3"
fuel-abi-types = "0.3"
fuel-core-client = { workspace = true }
fuel-crypto = { workspace = true }
Expand All @@ -29,6 +30,7 @@ fuels-core = { workspace = true }
futures = "0.3"
hex = "0.4.3"
rand = "0.8"
rpassword = "7.2"
serde = "1.0"
serde_json = "1"
sway-core = { version = "0.42.0", path = "../../sway-core" }
Expand Down
3 changes: 3 additions & 0 deletions forc-plugins/forc-client/src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ pub struct Command {
pub unsigned: bool,
/// Set the key to be used for signing.
pub signing_key: Option<SecretKey>,
/// Sign the deployment transaction manually.
#[clap(long)]
pub manual_signing: bool,
}
3 changes: 3 additions & 0 deletions forc-plugins/forc-client/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ pub struct Command {
pub unsigned: bool,
/// Set the key to be used for signing.
pub signing_key: Option<SecretKey>,
/// Sign the deployment transaction manually.
#[clap(long)]
pub manual_signing: bool,
}
15 changes: 13 additions & 2 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
cmd,
util::{
pkg::built_pkgs,
tx::{TransactionBuilderExt, TX_SUBMIT_TIMEOUT_MS},
tx::{TransactionBuilderExt, WalletSelectionMode, TX_SUBMIT_TIMEOUT_MS},
},
};
use anyhow::{bail, Context, Result};
Expand Down Expand Up @@ -178,12 +178,23 @@ pub async fn deploy_pkg(
let contract_id = contract.id(&salt, &root, &state_root);
info!("Contract id: 0x{}", hex::encode(contract_id));

let wallet_mode = if command.manual_signing {
WalletSelectionMode::Manual
} else {
WalletSelectionMode::ForcWallet
};

let tx = TransactionBuilder::create(bytecode.as_slice().into(), salt, storage_slots.clone())
.gas_limit(command.gas.limit)
.gas_price(command.gas.price)
.maturity(command.maturity.maturity.into())
.add_output(Output::contract_created(contract_id, state_root))
.finalize_signed(client.clone(), command.unsigned, command.signing_key)
.finalize_signed(
client.clone(),
command.unsigned,
command.signing_key,
wallet_mode,
)
.await?;

let tx = Transaction::from(tx);
Expand Down
14 changes: 12 additions & 2 deletions forc-plugins/forc-client/src/op/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
cmd,
util::{
pkg::built_pkgs,
tx::{TransactionBuilderExt, TX_SUBMIT_TIMEOUT_MS},
tx::{TransactionBuilderExt, WalletSelectionMode, TX_SUBMIT_TIMEOUT_MS},
},
};
use anyhow::{anyhow, bail, Context, Result};
Expand Down Expand Up @@ -77,12 +77,22 @@ pub async fn run_pkg(
.map_err(|e| anyhow!("Failed to parse contract id: {}", e))
})
.collect::<Result<Vec<ContractId>>>()?;
let wallet_mode = if command.manual_signing {
WalletSelectionMode::Manual
} else {
WalletSelectionMode::ForcWallet
};
let tx = TransactionBuilder::script(compiled.bytecode.bytes.clone(), script_data)
.gas_limit(command.gas.limit)
.gas_price(command.gas.price)
.maturity(command.maturity.maturity.into())
.add_contracts(contract_ids)
.finalize_signed(client.clone(), command.unsigned, command.signing_key)
.finalize_signed(
client.clone(),
command.unsigned,
command.signing_key,
wallet_mode,
)
.await?;
if command.dry_run {
info!("{:?}", tx);
Expand Down
Loading