From 3eb88d9fc2736ef7ef824b44a4442882ca77834a Mon Sep 17 00:00:00 2001 From: clabby Date: Sun, 28 Apr 2024 22:55:21 -0400 Subject: [PATCH] broomhilda --- input.json | 77 ------------------------------------------------- out.md | 42 --------------------------- rustfmt.toml | 11 +++++++ src/generate.rs | 56 +++++++++++++++-------------------- src/render.rs | 15 +++++----- src/types.rs | 2 +- 6 files changed, 43 insertions(+), 160 deletions(-) delete mode 100644 input.json delete mode 100644 out.md create mode 100644 rustfmt.toml diff --git a/input.json b/input.json deleted file mode 100644 index 279ba63..0000000 --- a/input.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "chainId": 11155111, - "metadata": { - "name": "FPAC Upgrade Mk2 - Sepolia Testnet", - "description": "Upgrades the `DisputeGameFactory` and `OptimismPortal` proxy implementations, as well as the dispute games, anchor state registry, preimage oracle, and MIPS VM" - }, - "transactions": [ - { - "metadata": { - "name": "Upgrade `DisputeGameFactory` to `StorageSetter`", - "description": "Upgrades the `DisputeGameFactory` to the `StorageSetter` contract, and clears the `initialized` slot so that we may change the owner." - }, - "to": "0x189abaaaa82dfc015a588a7dbad6f13b1d3485bc", - "value": "0x0", - "data": "0x9623609d00000000000000000000000005f9613adb30026ffd634f38e5c4dfd30a197fa100000000000000000000000054f8076f4027e21a010b4b3900c86211dd2c2deb00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044abfdcced0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "contractMethod": { - "type": "function", - "name": "upgradeAndCall", - "inputs": [ - { - "name": "unnamed_param0", - "type": "address" - }, - { - "name": "unnamed_param1", - "type": "address" - }, - { - "name": "unnamed_param2", - "type": "bytes" - } - ], - "outputs": [], - "stateMutability": "nonpayable" - }, - "contractInputsValues": { - "unnamed_param2": "0xabfdcced00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "unnamed_param1": "0x54F8076f4027e21A010b4B3900C86211Dd2C2DEB", - "unnamed_param0": "0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1" - } - }, - { - "metadata": { - "name": "Re-initialize `DisputeGameFactory`", - "description": "Re-initializes the `DisputeGameFactory` and sets the final implementation" - }, - "to": "0x189abaaaa82dfc015a588a7dbad6f13b1d3485bc", - "value": "0x0", - "data": "0x9623609d00000000000000000000000005f9613adb30026ffd634f38e5c4dfd30a197fa1000000000000000000000000c658fddbfbe85b59c9fdabb9e78598967e33cb9600000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024c4d66de80000000000000000000000001eb2ffc903729a0f03966b917003800b145f56e200000000000000000000000000000000000000000000000000000000", - "contractMethod": { - "type": "function", - "name": "upgradeAndCall", - "inputs": [ - { - "name": "unnamed_param0", - "type": "address" - }, - { - "name": "unnamed_param1", - "type": "address" - }, - { - "name": "unnamed_param2", - "type": "bytes" - } - ], - "outputs": [], - "stateMutability": "nonpayable" - }, - "contractInputsValues": { - "unnamed_param0": "0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1", - "unnamed_param2": "0xc4d66de80000000000000000000000001eb2ffc903729a0f03966b917003800b145f56e2", - "unnamed_param1": "0xC658FDDBfbe85B59C9FDaBB9E78598967e33Cb96" - } - } - ] -} \ No newline at end of file diff --git a/out.md b/out.md deleted file mode 100644 index ec4d42b..0000000 --- a/out.md +++ /dev/null @@ -1,42 +0,0 @@ -# FPAC Upgrade Mk2 - Sepolia Testnet -Upgrades the `DisputeGameFactory` and `OptimismPortal` proxy implementations, as well as the dispute games, anchor state registry, preimage oracle, and MIPS VM - -The batch will be executed on chain ID `11155111`, and contains `2` transactions. - -## Tx #1: Upgrade `DisputeGameFactory` to `StorageSetter` -Upgrades the `DisputeGameFactory` to the `StorageSetter` contract, and clears the `initialized` slot so that we may change the owner. - -**Function Signature:** `upgradeAndCall(address,address,bytes)` - -**To:** `0x189aBAAaa82DfC015A588A7dbaD6F13b1D3485Bc` - -**Value:** `0 WEI` - -**Raw Input Data:** `0x9623609d00000000000000000000000005f9613adb30026ffd634f38e5c4dfd30a197fa100000000000000000000000054f8076f4027e21a010b4b3900c86211dd2c2deb00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044abfdcced0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000` - -### Inputs -**unnamed_param2:** `0xabfdcced00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000` - -**unnamed_param1:** `0x54F8076f4027e21A010b4B3900C86211Dd2C2DEB` - -**unnamed_param0:** `0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1` - - -## Tx #2: Re-initialize `DisputeGameFactory` -Re-initializes the `DisputeGameFactory` and sets the final implementation - -**Function Signature:** `upgradeAndCall(address,address,bytes)` - -**To:** `0x189aBAAaa82DfC015A588A7dbaD6F13b1D3485Bc` - -**Value:** `0 WEI` - -**Raw Input Data:** `0x9623609d00000000000000000000000005f9613adb30026ffd634f38e5c4dfd30a197fa1000000000000000000000000c658fddbfbe85b59c9fdabb9e78598967e33cb9600000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024c4d66de80000000000000000000000001eb2ffc903729a0f03966b917003800b145f56e200000000000000000000000000000000000000000000000000000000` - -### Inputs -**unnamed_param2:** `0xc4d66de80000000000000000000000001eb2ffc903729a0f03966b917003800b145f56e2` - -**unnamed_param1:** `0xC658FDDBfbe85B59C9FDaBB9E78598967e33Cb96` - -**unnamed_param0:** `0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1` - diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..68c3c93 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,11 @@ +reorder_imports = true +imports_granularity = "Crate" +use_small_heuristics = "Max" +comment_width = 100 +wrap_comments = true +binop_separator = "Back" +trailing_comma = "Vertical" +trailing_semicolon = false +use_field_init_shorthand = true +format_code_in_doc_comments = true +doc_comment_code_block_width = 100 diff --git a/src/generate.rs b/src/generate.rs index 09b6b32..21d6e4f 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -1,26 +1,25 @@ -//! This module contains CLI prompts for generating a [MultisigBatch] definition from user input, with type safety. +//! This module contains CLI prompts for generating a [MultisigBatch] definition from user input, +//! with type safety. -use crate::types::{BatchTransaction, MultisigBatch, ObjectMetadata}; -use crate::util::encode_function_args; +use crate::{ + types::{BatchTransaction, MultisigBatch, ObjectMetadata}, + util::encode_function_args, +}; use alloy_json_abi::Function; use alloy_primitives::{hex::FromHex, Address, U256}; use anyhow::Result; use inquire::Text; -use std::path::PathBuf; -use std::{fs::File, io::Write}; +use std::{fs::File, io::Write, path::Path}; use yansi::Paint; -pub(crate) fn generate_batch_definition(output_path: &PathBuf) -> Result<()> { - let num_transactions = u64::from_str_radix( - &Text::new("Number of transactions in the multisig batch:").prompt()?, - 10, - )?; +pub(crate) fn generate_batch_definition(output_path: &Path) -> Result<()> { + let num_transactions = + (Text::new("Number of transactions in the multisig batch:").prompt()?).parse::()?; let mut batch_definition = MultisigBatch { - chain_id: u64::from_str_radix( - &Text::new("Chain ID that the batch transaction will be performed on:").prompt()?, - 10, - )?, + chain_id: (Text::new("Chain ID that the batch transaction will be performed on:") + .prompt()?) + .parse::()?, metadata: ObjectMetadata { name: Text::new("Enter the name of the batch:").prompt()?, description: Text::new("Enter the description of the batch:").prompt()?, @@ -35,7 +34,7 @@ pub(crate) fn generate_batch_definition(output_path: &PathBuf) -> Result<()> { Ok::<_, anyhow::Error>(()) })?; - let mut output = File::create("input.json")?; + let mut output = File::create(output_path)?; output.write_all(serde_json::to_string_pretty(&batch_definition)?.as_bytes())?; println!("Batch definition saved to {}", output_path.display().cyan()); @@ -51,22 +50,18 @@ fn prompt_batch_transaction(i: u64) -> Result { description: Text::new("Description:").prompt()?, }; - let to = Address::from_hex(&Text::new("Address of the contract to call:").prompt()?)?; + let to = Address::from_hex(Text::new("Address of the contract to call:").prompt()?)?; let value = U256::from_str_radix(&Text::new("Value to send (in WEI):").prompt()?, 10)?; - let contract_signature = Text::new("Enter the function signature of the contract to call") + let contract_signature = Text::new("Enter the function signature of the contract to call:") .with_help_message("Example: `deposit(uint256 amount)(bytes32 depositHash)`") .prompt()?; let mut function = Function::parse(&contract_signature)?; - function - .inputs - .iter_mut() - .enumerate() - .for_each(|(i, input)| { - input.name = (input.name.is_empty()) - .then(|| format!("unnamed_param{}", i)) - .unwrap_or_else(|| input.name.clone()) - }); + function.inputs.iter_mut().enumerate().for_each(|(i, input)| { + input.name = (input.name.is_empty()) + .then(|| format!("unnamed_param{}", i)) + .unwrap_or_else(|| input.name.clone()) + }); let inputs = prompt_raw_function_inputs(&function)?; let input_map = function @@ -93,12 +88,9 @@ fn prompt_raw_function_inputs(function: &Function) -> Result> { .iter() .enumerate() .map(|(i, input)| { - let input_value = Text::new(&format!( - "Enter the value for input #{} ({}):", - i + 1, - input.name - )) - .prompt()?; + let input_value = + Text::new(&format!("Enter the value for input #{} ({}):", i + 1, input.name)) + .prompt()?; Ok(input_value) }) diff --git a/src/render.rs b/src/render.rs index 5a5a980..64f0026 100644 --- a/src/render.rs +++ b/src/render.rs @@ -3,6 +3,7 @@ use crate::types::{BatchTransaction, MultisigBatch}; use anyhow::Result; use std::{fs::File, io::Write, path::PathBuf}; +use yansi::Paint; /// Renders a Markdown document from a [MultisigBatch] definition. pub fn render_batch_doc(input: &PathBuf, output: &PathBuf) -> Result<()> { @@ -20,6 +21,8 @@ pub fn render_batch_doc(input: &PathBuf, output: &PathBuf) -> Result<()> { // Write the document to the output file File::create(output)?.write_all(document.as_bytes())?; + println!("Document rendered to {}", output.display().green()); + Ok(()) } @@ -43,29 +46,25 @@ fn append_header(writer: &mut String, batch: &MultisigBatch) { /// Appends a [BatchTransaction] at index `i` to the writer. fn append_transaction(writer: &mut String, i: usize, tx: &BatchTransaction) { // Newline - writer.push_str("\n"); + writer.push('\n'); // Transaction Header writer.push_str(format!("## Tx #{}: {}\n", i, tx.metadata.name).as_ref()); writer.push_str(format!("{}\n", tx.metadata.description).as_ref()); // Newline - writer.push_str("\n"); + writer.push('\n'); // Transaction Details writer.push_str( - format!( - "**Function Signature:** `{}`\n\n", - tx.contract_method.signature() - ) - .as_ref(), + format!("**Function Signature:** `{}`\n\n", tx.contract_method.signature()).as_ref(), ); writer.push_str(format!("**To:** `{}`\n\n", tx.to).as_ref()); writer.push_str(format!("**Value:** `{} WEI`\n\n", tx.value).as_ref()); writer.push_str(format!("**Raw Input Data:** `{}`\n", tx.data).as_ref()); // Newline - writer.push_str("\n"); + writer.push('\n'); // Transaction Inputs writer.push_str("### Inputs\n"); diff --git a/src/types.rs b/src/types.rs index 11a22a3..8fe15d6 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,9 +1,9 @@ //! This module contains the definiteions for the upgrade JSON schema. -use std::collections::HashMap; use alloy_json_abi::Function; use alloy_primitives::{Address, Bytes, U256}; use serde::{Deserialize, Serialize}; +use std::collections::HashMap; /// Describes the definition of a multisig batch. #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]