-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tool for generating fee collection contract (#1501)
Closes #1409 Handing off to @Dentosal The tests contain example of how to withdraw tokens. --------- Co-authored-by: Hannes Karppila <hannes.karppila@gmail.com> Co-authored-by: xgreenx <xgreenx9999@gmail.com>
- Loading branch information
1 parent
e940d1d
commit 65dd6f2
Showing
8 changed files
with
448 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.