diff --git a/frame/cosmos/x/auth/signing/src/sign_mode_handler/mod.rs b/frame/cosmos/x/auth/signing/src/sign_mode_handler/mod.rs index 5d87b8c..fcb167b 100644 --- a/frame/cosmos/x/auth/signing/src/sign_mode_handler/mod.rs +++ b/frame/cosmos/x/auth/signing/src/sign_mode_handler/mod.rs @@ -25,9 +25,12 @@ use alloc::{ use cosmos_sdk_proto::{ cosmos::{ bank, - tx::v1beta1::{ - mode_info::{Single, Sum}, - ModeInfo, SignDoc, Tx, TxRaw, + tx::{ + signing::v1beta1::SignMode, + v1beta1::{ + mode_info::{Single, Sum}, + ModeInfo, SignDoc, Tx, TxRaw, + }, }, }, cosmwasm::wasm, @@ -64,6 +67,9 @@ pub enum SignModeHandlerError { UnsupportedMode, } +const SIGN_MODE_DIRECT: i32 = SignMode::Direct as i32; +const SIGN_MODE_LEGACY_AMINO_JSON: i32 = SignMode::LegacyAminoJson as i32; + pub struct SignModeHandler; impl traits::SignModeHandler for SignModeHandler { fn get_sign_bytes( @@ -73,17 +79,19 @@ impl traits::SignModeHandler for SignModeHandler { ) -> Result, SignModeHandlerError> { let sum = mode.sum.as_ref().ok_or(SignModeHandlerError::EmptyModeInfo)?; let sign_bytes = match sum { - Sum::Single(Single { mode }) => match mode { - 1 /* SIGN_MODE_DIRECT */ => { - let tx_raw = TxRaw::decode(&mut &*tx.encode_to_vec()).map_err(|_| SignModeHandlerError::DecodeTxError)?; + Sum::Single(Single { mode }) => match *mode { + SIGN_MODE_DIRECT => { + let tx_raw = TxRaw::decode(&mut &*tx.encode_to_vec()) + .map_err(|_| SignModeHandlerError::DecodeTxError)?; SignDoc { body_bytes: tx_raw.body_bytes, auth_info_bytes: tx_raw.auth_info_bytes, chain_id: data.chain_id.clone(), account_number: data.account_number, - }.encode_to_vec() + } + .encode_to_vec() }, - 127 /* SIGN_MODE_LEGACY_AMINO_JSON */ => { + SIGN_MODE_LEGACY_AMINO_JSON => { let body = tx.body.as_ref().ok_or(SignModeHandlerError::EmptyTxBody)?; let mut msgs = Vec::::new(); for msg in body.messages.iter() { @@ -100,7 +108,11 @@ impl traits::SignModeHandler for SignModeHandler { msgs.push(legacy_msg); } - let fee = tx.auth_info.as_ref().and_then(|auth_info| auth_info.fee.as_ref()).ok_or(SignModeHandlerError::EmptyFee)?; + let fee = tx + .auth_info + .as_ref() + .and_then(|auth_info| auth_info.fee.as_ref()) + .ok_or(SignModeHandlerError::EmptyFee)?; let sign_doc = StdSignDoc { account_number: data.account_number.to_string(), chain_id: data.chain_id.clone(), @@ -110,7 +122,8 @@ impl traits::SignModeHandler for SignModeHandler { sequence: data.sequence.to_string(), }; - serde_json::to_vec(&sign_doc).map_err(|_| SignModeHandlerError::SerializeError)? + serde_json::to_vec(&sign_doc) + .map_err(|_| SignModeHandlerError::SerializeError)? }, _ => return Err(SignModeHandlerError::UnsupportedMode), },