Skip to content

Commit a48eafe

Browse files
foriequal0mergify[bot]
authored andcommitted
Extract a function to verify a new CommonParams compare to the current params
1 parent 9afd0a8 commit a48eafe

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

core/src/consensus/stake/actions.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,7 @@ impl Action {
105105
params,
106106
signatures,
107107
} => {
108-
let current_network_id = current_params.network_id();
109-
let transaction_network_id = params.network_id();
110-
if current_network_id != transaction_network_id {
111-
return Err(SyntaxError::InvalidCustomAction(format!(
112-
"The current network id is {} but the transaction tries to change the network id to {}",
113-
current_network_id, transaction_network_id
114-
)))
115-
}
116-
params.verify().map_err(SyntaxError::InvalidCustomAction)?;
108+
params.verify_change(current_params).map_err(SyntaxError::InvalidCustomAction)?;
117109
let action = Action::ChangeParams {
118110
metadata_seq: *metadata_seq,
119111
params: params.clone(),

types/src/common_params.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ impl CommonParams {
214214
}
215215
Ok(())
216216
}
217+
218+
pub fn verify_change(&self, current_params: &Self) -> Result<(), String> {
219+
self.verify()?;
220+
let current_network_id = current_params.network_id();
221+
let transaction_network_id = self.network_id();
222+
if current_network_id != transaction_network_id {
223+
return Err(format!(
224+
"The current network id is {} but the transaction tries to change the network id to {}",
225+
current_network_id, transaction_network_id
226+
))
227+
}
228+
Ok(())
229+
}
217230
}
218231

219232
const DEFAULT_PARAMS_SIZE: usize = 23;

0 commit comments

Comments
 (0)