Skip to content

Commit

Permalink
resolve linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellfalcao committed Aug 28, 2024
1 parent 70cf8f5 commit 6ca5243
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
38 changes: 13 additions & 25 deletions packages/kos-mobile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,32 @@ use hex::ToHex;

use kos_crypto::cipher;
use kos_crypto::cipher::CipherAlgo;
use kos_sdk;
use kos_sdk::chain::Chain;
use kos_sdk::models::PathOptions;
use kos_sdk::wallet::Wallet;
use kos_types::error::Error as KosError;

use crate::kos_sdk::chain::Chain;

uniffi::setup_scaffolding!();

#[derive(Debug, thiserror::Error, uniffi::Error)]
enum KOSError {
#[error("UnsupportedChainError: Unsupported chain {id}")]
UnsupportedChainError { id: String },
UnsupportedChain { id: String },
#[error("KOSDelegateError: {0}")]
KOSDelegateError(String),
KOSDelegate(String),
#[error("HexDecodeError: {0}")]
HexDecodeError(String),
HexDecode(String),
}

impl From<KosError> for KOSError {
fn from(err: KosError) -> Self {
KOSError::KOSDelegateError(err.to_string())
KOSError::KOSDelegate(err.to_string())
}
}

impl From<FromHexError> for KOSError {
fn from(err: FromHexError) -> Self {
KOSError::HexDecodeError(err.to_string())
KOSError::HexDecode(err.to_string())
}
}

Expand Down Expand Up @@ -111,15 +109,14 @@ fn encrypt_with_cfb(data: String, password: String) -> Result<String, KOSError>
#[uniffi::export]
fn decrypt(data: String, password: String) -> Result<String, KOSError> {
let data_in_byte = hex::decode(data)?;
let decrypted_data = cipher::decrypt(&*data_in_byte, password.as_str())?;
let decrypted_data = cipher::decrypt(&data_in_byte, password.as_str())?;
Ok(String::from_utf8_lossy(&decrypted_data).to_string())
}

fn get_chain_by(id: i32) -> Result<Chain, KOSError> {
let id_u8 =
u8::try_from(id).map_err(|_| KOSError::UnsupportedChainError { id: id.to_string() })?;
let id_u8 = u8::try_from(id).map_err(|_| KOSError::UnsupportedChain { id: id.to_string() })?;
let chain = Chain::get_by_code(id_u8)
.ok_or_else(|| KOSError::UnsupportedChainError { id: id.to_string() })?;
.ok_or_else(|| KOSError::UnsupportedChain { id: id.to_string() })?;
Ok(chain)
}

Expand All @@ -141,10 +138,7 @@ mod tests {
let size = -1;
match generate_mnemonic(size) {
Ok(_) => panic!("A error was expected but found a mnemonic"),
Err(e) => assert!(
matches!(e, KOSError::KOSDelegateError(..)),
" Invalid error"
),
Err(e) => assert!(matches!(e, KOSError::KOSDelegate(..)), "Invalid error"),
}
}

Expand All @@ -170,7 +164,7 @@ mod tests {
match generate_wallet_from_mnemonic(mnemonic, chain_id, index, false) {
Ok(_) => panic!("A error was expected but found a mnemonic"),
Err(e) => {
if let KOSError::UnsupportedChainError { id } = e {
if let KOSError::UnsupportedChain { id } = e {
assert_eq!(id, chain_id.to_string(), "Invalid error");
} else {
panic!("Expected UnsupportedChainError but found different error");
Expand Down Expand Up @@ -270,10 +264,7 @@ mod tests {
"A error was expected but found a pk {}.",
account.private_key
),
Err(e) => assert!(
matches!(e, KOSError::KOSDelegateError(..)),
" Invalid error"
),
Err(e) => assert!(matches!(e, KOSError::KOSDelegate(..)), " Invalid error"),
}
}

Expand Down Expand Up @@ -311,10 +302,7 @@ mod tests {
let encrypted_data = encrypt_with_gmc(original_data.clone(), password.clone()).unwrap();
match decrypt(encrypted_data, "wrong".to_string()) {
Ok(_) => panic!("A error was expected but found a decrypted data"),
Err(e) => assert!(
matches!(e, KOSError::KOSDelegateError(..)),
" Invalid error"
),
Err(e) => assert!(matches!(e, KOSError::KOSDelegate(..)), " Invalid error"),
}
}
}
4 changes: 2 additions & 2 deletions packages/kos-sdk/src/chains/bitcoin/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl BTCTransaction {
match self.tx.inputs[inp_idx].partial_sigs.first_key_value() {
Some((pubkey, sig)) => {
let mut script_witness = bitcoin::Witness::new();
script_witness.push(&sig.to_vec());
script_witness.push(&pubkey.to_bytes());
script_witness.push(sig.to_vec());
script_witness.push(pubkey.to_bytes());
script_witness
}
_ => return Err(Error::TransportError("No signature found".to_string())),
Expand Down

0 comments on commit 6ca5243

Please sign in to comment.