Skip to content

Commit

Permalink
chore: clippy check optimization、upgrade forest_message and forest_cr…
Browse files Browse the repository at this point in the history
…ypto version
  • Loading branch information
xiaoguang1010 committed Dec 29, 2023
1 parent f8eb9ec commit 197357b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 38 deletions.
18 changes: 4 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions imkey-core/ikc-wallet/coin-filecoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ serde_cbor = "=0.11.1"
serde_json = "=1.0.89"

forest_vm = "=0.3.2"
forest_message = "=0.6.1"
forest_message = "=0.7.2"
forest_address = "=0.3.2"
forest_encoding = "=0.2.2"
forest_cid = "=0.3.0"
forest_crypto = "=0.4.1"
forest_crypto = "=0.5.3"
num_bigint_chainsafe = { package = "forest_bigint", version = "=0.1.4"}

10 changes: 6 additions & 4 deletions token-core/tcx-crypto/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub type Credential = [u8; CREDENTIAL_LEN];

fn default_kdf_rounds() -> u32 {
let v = env::var("KDF_ROUNDS");
if let Ok(val) = v {
val.parse::<u32>().unwrap()
if let Ok(v) = v {
v.parse::<u32>().unwrap()
} else {
*crate::KDF_ROUNDS.read() as u32
}
Expand Down Expand Up @@ -257,8 +257,10 @@ impl Crypto {
}

pub fn new(password: &str, origin: &[u8]) -> Crypto {
let mut param = Pbkdf2Params::default();
param.salt = random_u8_32().to_hex();
let param = Pbkdf2Params {
salt: random_u8_32().to_hex(),
..Pbkdf2Params::default()
};

Self::new_with_kdf(password, origin, KdfType::Pbkdf2(param))
}
Expand Down
2 changes: 1 addition & 1 deletion token-core/tcx-eos/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Address for EosAddress {
impl FromStr for EosAddress {
type Err = failure::Error;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
if s.starts_with("EOS") {
if let Some(s) = s.strip_prefix("EOS") {
let s = &s[3..];
let bytes = base58::from(s).map_err(|_| CommonError::InvalidAddress)?;
let checksum = bytes[bytes.len() - 4..].to_vec();
Expand Down
4 changes: 2 additions & 2 deletions token-core/tcx-eth/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ impl EthRecoverAddressInput {
}

fn parse_u64(s: &str) -> Result<U64> {
if s.starts_with("0x") {
Ok(U64::from_str_radix(&s[2..], 16)?)
if let Some(s) = s.strip_prefix("0x") {
Ok(U64::from_str_radix(s, 16)?)
} else {
let r = U64::from_dec_str(s);
if r.is_err() {
Expand Down
2 changes: 2 additions & 0 deletions token-core/tcx/src/error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ fn lock_all_keystore() {

/// catch any error and format to string
/// ref: <https://doc.rust-lang.org/edition-guide/rust-2018/error-handling-and-panics/controlling-panics-with-std-panic.html>
/// # Safety
///
#[cfg_attr(tarpaulin, ignore)]
pub unsafe fn landingpad<F: FnOnce() -> Result<T> + panic::UnwindSafe, T>(f: F) -> Result<T> {
match panic::catch_unwind(f) {
Expand Down
31 changes: 17 additions & 14 deletions token-core/tcx/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ use crate::api::{
GeneralResult, GetExtendedPublicKeysParam, GetExtendedPublicKeysResult, GetPublicKeysParam,
GetPublicKeysResult, ImportJsonParam, ImportMnemonicParam, ImportPrivateKeyParam,
ImportPrivateKeyResult, KeystoreMigrationParam, KeystoreResult, MnemonicToPublicKeyParam,
MnemonicToPublicKeyResult, RemoveWalletParam, RemoveWalletResult,
SignAuthenticationMessageParam, SignAuthenticationMessageResult, SignHashesParam,
SignHashesResult, WalletKeyParam,
MnemonicToPublicKeyResult, SignAuthenticationMessageParam, SignAuthenticationMessageResult,
SignHashesParam, SignHashesResult, WalletKeyParam,
};
use crate::api::{InitTokenCoreXParam, SignParam};
use crate::error_handling::Result;
use crate::filemanager::{
self, cache_keystore, clean_keystore, copy_to_v2_if_need, flush_keystore, KEYSTORE_BASE_DIR,
cache_keystore, clean_keystore, copy_to_v2_if_need, flush_keystore, KEYSTORE_BASE_DIR,
WALLET_FILE_DIR, WALLET_V2_DIR,
};
use crate::filemanager::{delete_keystore_file, KEYSTORE_MAP};
Expand Down Expand Up @@ -92,7 +91,7 @@ pub(crate) fn encode_message(msg: impl Message) -> Result<Vec<u8>> {
Ok(buf.to_vec())
}

fn derive_account<'a, 'b>(keystore: &mut Keystore, derivation: &Derivation) -> Result<Account> {
fn derive_account(keystore: &mut Keystore, derivation: &Derivation) -> Result<Account> {
let mut coin_info = coin_info_from_param(
&derivation.chain_type,
&derivation.network,
Expand Down Expand Up @@ -399,11 +398,13 @@ pub(crate) fn create_keystore(data: &[u8]) -> Result<Vec<u8>> {
let param: CreateKeystoreParam =
CreateKeystoreParam::decode(data).expect("create_keystore param");

let mut meta = Metadata::default();
meta.name = param.name;
meta.password_hint = param.password_hint.to_owned();
meta.source = Source::NewMnemonic;
meta.network = IdentityNetwork::from_str(&param.network)?;
let meta = Metadata {
name: param.name,
password_hint: param.password_hint,
source: Source::NewMnemonic,
network: IdentityNetwork::from_str(&param.network)?,
..Metadata::default()
};

let ks = HdKeystore::new(&param.password, meta);

Expand Down Expand Up @@ -448,10 +449,12 @@ pub(crate) fn import_mnemonic(data: &[u8]) -> Result<Vec<u8>> {
return Err(format_err!("{}", "address_already_exist"));
}

let mut meta = Metadata::default();
meta.name = param.name.to_owned();
meta.password_hint = param.password_hint.to_owned();
meta.source = Source::Mnemonic;
let meta = Metadata {
name: param.name,
password_hint: param.password_hint,
source: Source::Mnemonic,
..Metadata::default()
};

let ks = HdKeystore::from_mnemonic(&param.mnemonic, &param.password, meta)?;

Expand Down
9 changes: 8 additions & 1 deletion token-core/tcx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ lazy_static! {

pub type Result<T> = result::Result<T, Error>;

/// # Safety
///
#[no_mangle]
pub unsafe extern "C" fn free_const_string(s: *const c_char) {
if s.is_null() {
Expand All @@ -52,8 +54,9 @@ pub unsafe extern "C" fn free_const_string(s: *const c_char) {
let _ = CStr::from_ptr(s);
}

/// dispatch protobuf rpc call
/// # Safety
///
/// dispatch protobuf rpc call
#[allow(deprecated)]
#[no_mangle]
pub unsafe extern "C" fn call_tcx_api(hex_str: *const c_char) -> *const c_char {
Expand Down Expand Up @@ -123,6 +126,8 @@ pub unsafe extern "C" fn call_tcx_api(hex_str: *const c_char) -> *const c_char {
}
}

/// # Safety
///
#[no_mangle]
pub unsafe extern "C" fn clear_err() {
LAST_ERROR.with(|e| {
Expand All @@ -133,6 +138,8 @@ pub unsafe extern "C" fn clear_err() {
});
}

/// # Safety
///
#[no_mangle]
pub unsafe extern "C" fn get_last_err_message() -> *const c_char {
LAST_ERROR.with(|e| {
Expand Down

0 comments on commit 197357b

Please sign in to comment.