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

Tool for generating fee collection contract #1501

Merged
merged 16 commits into from
Nov 22, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Description of the upcoming release here.
- [#1263](https://github.com/FuelLabs/fuel-core/pull/1263): Add gas benchmarks for `ED19` and `ECR1` instructions.
- [#1331](https://github.com/FuelLabs/fuel-core/pull/1331): Add peer reputation reporting to block import code
- [#1405](https://github.com/FuelLabs/fuel-core/pull/1405): Use correct names for service metrics.
- [#1501](https://github.com/FuelLabs/fuel-core/pull/1501): Add a CLI command for generating a fee collection contract.

### Changed

Expand Down
6 changes: 6 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions bin/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const_format = { version = "0.2", optional = true }
dirs = "4.0"
dotenvy = { version = "0.15", optional = true }
fuel-core = { workspace = true }
fuel-core-chain-config = { workspace = true }
fuel-core-types = { workspace = true }
hex = "0.4"
humantime = "2.1"
lazy_static = { workspace = true }
pyroscope = "0.5"
Expand Down
3 changes: 3 additions & 0 deletions bin/fuel-core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lazy_static::lazy_static! {
pub static ref DEFAULT_DB_PATH: PathBuf = dirs::home_dir().unwrap().join(".fuel").join("db");
}

pub mod fee_contract;
pub mod run;
pub mod snapshot;

Expand All @@ -38,6 +39,7 @@ pub struct Opt {
pub enum Fuel {
Run(run::Command),
Snapshot(snapshot::Command),
GenerateFeeContract(fee_contract::Command),
}

pub const LOG_FILTER: &str = "RUST_LOG";
Expand Down Expand Up @@ -117,6 +119,7 @@ pub async fn run_cli() -> anyhow::Result<()> {
Ok(opt) => match opt.command {
Fuel::Run(command) => run::exec(command).await,
Fuel::Snapshot(command) => snapshot::exec(command).await,
Fuel::GenerateFeeContract(command) => fee_contract::exec(command).await,
},
Err(e) => {
// Prints the error and exits.
Expand Down
40 changes: 40 additions & 0 deletions bin/fuel-core/src/cli/fee_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use clap::Parser;
use fuel_core_chain_config::fee_collection_contract;
use fuel_core_types::fuel_tx::Address;
use std::{
fs::OpenOptions,
io::Write,
path::PathBuf,
};

#[derive(Debug, Parser)]
pub struct Command {
/// Address to withdraw fees to
withdrawal_address: Address,
/// Output file. If not provided, will print hex representation to stdout.
#[clap(short, long)]
output: Option<PathBuf>,
/// Overwrite output file if it exists. No effect if `output` is not provided.
#[clap(short, long)]
force: bool,
}

pub async fn exec(cmd: Command) -> anyhow::Result<()> {
let contract = fee_collection_contract::generate(cmd.withdrawal_address);

if let Some(output) = cmd.output.as_ref() {
let mut open_opt = OpenOptions::new();
if cmd.force {
open_opt.create(true).write(true).truncate(true);
} else {
open_opt.create_new(true).write(true);
}

let mut file = open_opt.open(output)?;
file.write_all(&contract)?;
} else {
println!("{}", hex::encode(contract));
}

Ok(())
}
3 changes: 3 additions & 0 deletions crates/chain-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ serde_with = "1.11"
tracing = "0.1"

[dev-dependencies]
fuel-core = { workspace = true }
fuel-core-client = { workspace = true }
fuel-core-types = { workspace = true, default-features = false, features = ["random", "serde"] }
insta = { workspace = true }
rand = { workspace = true }
serde_json = { version = "1.0", features = ["raw_value"] }
tokio = { workspace = true, features = ["full"] }

[features]
default = ["std"]
Expand Down
Loading
Loading