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

Allow user to override initial storage slots in forc-deploy #5311

Merged
merged 2 commits into from
Nov 29, 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
20 changes: 20 additions & 0 deletions forc-plugins/forc-client/src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,24 @@ pub struct Command {
/// Sign the deployment transaction manually.
#[clap(long)]
pub manual_signing: bool,
/// Override storage slot initialization.
///
/// By default, storage slots are initialized with the values defined in the storage block in
/// the contract. You can override the initialization by providing the file path to a JSON file
/// containing the overriden values.
///
/// The file format and key values should match the compiler-generated `*-storage_slots.json` file in the output
/// directory of the compiled contract.
///
/// Example: `forc deploy --override-storage-slots my_override.json`
///
/// my_override.json:
/// [
/// {
/// "key": "<key from out/debug/storage_slots.json>",
/// "value": "0000000000000000000000000000000000000000000000000000000000000001"
/// }
/// ]
#[clap(long, verbatim_doc_comment, name = "JSON_FILE_PATH")]
pub override_storage_slots: Option<String>,
}
9 changes: 8 additions & 1 deletion forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,14 @@ pub async fn deploy_pkg(

let bytecode = &compiled.bytecode.bytes;

let mut storage_slots = compiled.storage_slots.clone();
let mut storage_slots =
if let Some(storage_slot_override_file) = &command.override_storage_slots {
let storage_slots_file = std::fs::read_to_string(storage_slot_override_file)?;
let storage_slots: Vec<StorageSlot> = serde_json::from_str(&storage_slots_file)?;
storage_slots
} else {
compiled.storage_slots.clone()
};
storage_slots.sort();

let contract = Contract::from(bytecode.clone());
Expand Down
Loading