Skip to content

Commit

Permalink
feat: integrate forc-wallet and forc-deploy (FuelLabs#4752)
Browse files Browse the repository at this point in the history
## Description
closes FuelLabs#4743.

This PR integrates forc-wallet and forc-deploy together so that
forc-deploy can offer to sign your transactions without running a second
terminal window. Below there are some inputs and outputs after this
change.
  • Loading branch information
kayagokalp authored Jul 6, 2023
1 parent c4e4ef7 commit 87b6228
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 11 deletions.
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

0 comments on commit 87b6228

Please sign in to comment.