Skip to content

Commit 59e1696

Browse files
committed
Make CommonParams be verified with the current CommonParams
1 parent f43138b commit 59e1696

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
@@ -220,6 +220,19 @@ impl CommonParams {
220220
}
221221
Ok(())
222222
}
223+
224+
pub fn verify_change(&self, current_params: &Self) -> Result<(), String> {
225+
self.verify()?;
226+
let current_network_id = current_params.network_id();
227+
let transaction_network_id = self.network_id();
228+
if current_network_id != transaction_network_id {
229+
return Err(format!(
230+
"The current network id is {} but the transaction tries to change the network id to {}",
231+
current_network_id, transaction_network_id
232+
))
233+
}
234+
235+
}
223236
}
224237

225238
const DEFAULT_PARAMS_SIZE: usize = 23;

0 commit comments

Comments
 (0)