Skip to content

Commit 28caeb1

Browse files
authored
chore(script): avoid cloning script sequences when writing sensitive output (#12085)
* chore(script): avoid cloning script sequences when writing sensitive output * Update sequence.rs * Update multi_sequence.rs * Update sequence.rs * Update multi_sequence.rs
1 parent ab160b3 commit 28caeb1

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

crates/script-sequence/src/sequence.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ pub struct SensitiveScriptSequence {
5151
pub transactions: VecDeque<SensitiveTransactionMetadata>,
5252
}
5353

54-
impl From<ScriptSequence> for SensitiveScriptSequence {
55-
fn from(sequence: ScriptSequence) -> Self {
54+
impl From<&ScriptSequence> for SensitiveScriptSequence {
55+
fn from(sequence: &ScriptSequence) -> Self {
5656
Self {
5757
transactions: sequence
5858
.transactions
@@ -99,31 +99,31 @@ impl ScriptSequence {
9999
return Ok(());
100100
}
101101

102-
let Some((path, sensitive_path)) = self.paths.clone() else { return Ok(()) };
103-
104102
self.timestamp = now().as_millis();
105103
let ts_name = format!("run-{}.json", self.timestamp);
106104

107-
let sensitive_script_sequence: SensitiveScriptSequence = self.clone().into();
105+
let sensitive_script_sequence = SensitiveScriptSequence::from(&*self);
106+
107+
let Some((path, sensitive_path)) = self.paths.as_ref() else { return Ok(()) };
108108

109109
// broadcast folder writes
110110
//../run-latest.json
111-
let mut writer = BufWriter::new(fs::create_file(&path)?);
111+
let mut writer = BufWriter::new(fs::create_file(path)?);
112112
serde_json::to_writer_pretty(&mut writer, &self)?;
113113
writer.flush()?;
114114
if save_ts {
115115
//../run-[timestamp].json
116-
fs::copy(&path, path.with_file_name(&ts_name))?;
116+
fs::copy(path, path.with_file_name(&ts_name))?;
117117
}
118118

119119
// cache folder writes
120120
//../run-latest.json
121-
let mut writer = BufWriter::new(fs::create_file(&sensitive_path)?);
121+
let mut writer = BufWriter::new(fs::create_file(sensitive_path)?);
122122
serde_json::to_writer_pretty(&mut writer, &sensitive_script_sequence)?;
123123
writer.flush()?;
124124
if save_ts {
125125
//../run-[timestamp].json
126-
fs::copy(&sensitive_path, sensitive_path.with_file_name(&ts_name))?;
126+
fs::copy(sensitive_path, sensitive_path.with_file_name(&ts_name))?;
127127
}
128128

129129
if !silent {

crates/script/src/multi_sequence.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ pub struct SensitiveMultiChainSequence {
2929
}
3030

3131
impl SensitiveMultiChainSequence {
32-
fn from_multi_sequence(sequence: MultiChainSequence) -> Self {
32+
fn from_multi_sequence(sequence: &MultiChainSequence) -> Self {
3333
Self {
34-
deployments: sequence.deployments.into_iter().map(|sequence| sequence.into()).collect(),
34+
deployments: sequence.deployments.iter().map(SensitiveScriptSequence::from).collect(),
3535
}
3636
}
3737
}
@@ -115,7 +115,7 @@ impl MultiChainSequence {
115115

116116
self.timestamp = now().as_millis();
117117

118-
let sensitive_sequence = SensitiveMultiChainSequence::from_multi_sequence(self.clone());
118+
let sensitive_sequence = SensitiveMultiChainSequence::from_multi_sequence(&*self);
119119

120120
// broadcast writes
121121
//../Contract-latest/run.json

0 commit comments

Comments
 (0)