Skip to content

Commit

Permalink
Remove some wrning
Browse files Browse the repository at this point in the history
  • Loading branch information
XuNeal committed Dec 13, 2019
1 parent 4fff38c commit 7c505d4
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 88 deletions.
8 changes: 2 additions & 6 deletions tcx-bch/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ use std::fmt::{Display, Formatter};
use std::str::FromStr;
use tcx_btc_fork::{BtcForkAddress, PubKeyScript, ScriptPubKeyComponent};
use tcx_chain::Address;
use tcx_constants::{network_from_coin, CoinInfo};
use tcx_primitive::{
PrivateKey, PublicKey, Secp256k1PrivateKey, Secp256k1PublicKey, TypedPrivateKey, TypedPublicKey,
};
use tcx_constants::CoinInfo;
use tcx_primitive::TypedPublicKey;

fn _legacy_to_bch(addr: &str) -> Result<String> {
let convert = Converter::new();
Expand Down Expand Up @@ -112,8 +110,6 @@ mod tests {
use crate::address::{remove_bch_prefix, BchAddress};
use bitcoin::util::misc::hex_bytes;

use bch_addr::{AddressFormat, Converter, Network};
use bitcoin::consensus::encode::Error::Secp256k1;
use tcx_chain::Address;
use tcx_constants::coin_info::coin_info_from_param;
use tcx_constants::CurveType;
Expand Down
2 changes: 1 addition & 1 deletion tcx-bch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod tests {
use crate::BchAddress;

use serde_json::Value;
use std::str::FromStr;

use tcx_chain::KeystoreGuard;
use tcx_chain::{HdKeystore, Keystore, Metadata};
use tcx_constants::CoinInfo;
Expand Down
1 change: 0 additions & 1 deletion tcx-bch/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ mod tests {
use super::*;
use crate::address::BchAddress;

use bch_addr::Converter;
use std::marker::PhantomData;
use std::str::FromStr;
use tcx_btc_fork::BtcForkTxInput;
Expand Down
7 changes: 2 additions & 5 deletions tcx-btc-fork/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::signer::ScriptPubKeyComponent;
use crate::Error;
use crate::Result;

use bech32::FromBase32;
use bitcoin::network::constants::Network;
use bitcoin::util::address::Error as BtcAddressError;
use bitcoin::util::address::Payload;
Expand Down Expand Up @@ -304,13 +303,11 @@ mod tests {
use crate::signer::ScriptPubKeyComponent;
use crate::tcx_chain::Address;

use bitcoin::util::bip32::ExtendedPrivKey;
use std::str::FromStr;
use tcx_constants::btc_fork_network::network_from_param;
use tcx_constants::{network_from_coin, CoinInfo, CurveType};
use tcx_constants::{CoinInfo, CurveType};
use tcx_primitive::{
Bip32DeterministicPrivateKey, Derive, DerivePath, DeterministicPrivateKey,
Secp256k1PrivateKey, Ss58Codec,
Bip32DeterministicPrivateKey, Derive, DerivePath, DeterministicPrivateKey, Ss58Codec,
};

#[test]
Expand Down
3 changes: 0 additions & 3 deletions tcx-btc-fork/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ pub mod transaction;

use core::result;
use serde::{Deserialize, Serialize};
use std::iter::IntoIterator;
use std::str::FromStr;
use tcx_chain::Address;

#[macro_use]
extern crate failure;
Expand Down
3 changes: 2 additions & 1 deletion tcx-btc-fork/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ impl<S: ScriptPubKeyComponent + Address, T: BitcoinTransactionSignComponent>
S::address_script_pub_key(&self.tx_input.change_address)
} else {
let from = &self.tx_input.unspents.first().expect("first_utxo").address;
let change_path = format!("1/{}", &self.tx_input.change_address_index);
// todo: address is error
let _change_path = format!("1/{}", &self.tx_input.change_address_index);
let pub_key = dpk.public_key().as_secp256k1()?.0;
S::address_script_like(&from, &pub_key)
}
Expand Down
21 changes: 8 additions & 13 deletions tcx-chain/src/keystore/hd.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
use bip39::{Language, Mnemonic};
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::time::{SystemTime, UNIX_EPOCH};

use uuid::Uuid;

use super::guard::KeystoreGuard;
use super::Account;
use super::Address;
use super::Result;
use super::{Error, Metadata, Source};
use super::{Error, Metadata};

use crate::keystore::{Keystore, Store};
use crate::keystore::Store;

use core::{fmt, result};
use serde_json::Value;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};

use std::str::FromStr;
use tcx_constants::{CoinInfo, CurveType};
use tcx_constants::CoinInfo;
use tcx_crypto::hash::{hex_sha256, sha256, str_sha256};
use tcx_crypto::{Crypto, Pbkdf2Params};
use tcx_primitive::{
Expand Down Expand Up @@ -292,9 +287,9 @@ mod tests {
use super::*;
use crate::keystore::metadata_default_time;
use bitcoin_hashes::hex::ToHex;
use serde_json::Map;

use std::string::ToString;
use tcx_primitive::{PublicKey, TypedPublicKey};
use tcx_primitive::TypedPublicKey;

static PASSWORD: &'static str = "Insecure Pa55w0rd";
static MNEMONIC: &'static str =
Expand All @@ -321,7 +316,7 @@ mod tests {
Ok("mock_address".to_string())
}

fn is_valid(address: &str) -> bool {
fn is_valid(_address: &str) -> bool {
true
}
}
Expand Down
10 changes: 5 additions & 5 deletions tcx-chain/src/keystore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ mod hd;
mod private;

use serde::{Deserialize, Serialize};
use serde_json::Value;

use tcx_constants::{CoinInfo, CurveType};

pub use self::{guard::KeystoreGuard, hd::HdKeystore, private::PrivateKeystore};
use crate::signer::ChainSigner;
use tcx_crypto::{Crypto, Pbkdf2Params};
use tcx_primitive::{
DeterministicPrivateKey, PrivateKey, TypedDeterministicPrivateKey, TypedDeterministicPublicKey,
TypedPrivateKey, TypedPublicKey,
DeterministicPrivateKey, PrivateKey, TypedDeterministicPublicKey, TypedPrivateKey,
TypedPublicKey,
};

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Keystore {
pub fn determinable(&self) -> bool {
match self {
Keystore::PrivateKey(_) => false,
Keystore::Hd(ks) => true,
Keystore::Hd(_) => true,
}
}

Expand Down Expand Up @@ -329,7 +329,7 @@ mod tests {
use crate::{HdKeystore, Keystore, Metadata, PrivateKeystore, Source};
use serde_json::Value;
use std::str::FromStr;
use tcx_constants::coin_info::coin_info_from_param;

use tcx_primitive::{Ss58Codec, ToHex};

static PASSWORD: &'static str = "Insecure Pa55w0rd";
Expand Down
11 changes: 3 additions & 8 deletions tcx-chain/src/keystore/private.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
use super::Account;
use super::{Address, Metadata, Source};
use tcx_constants::{CoinInfo, CurveType};
use tcx_constants::CoinInfo;
use tcx_crypto::{Crypto, Pbkdf2Params};

use super::Error;
use super::Result;
use crate::keystore::{Keystore, Store};
use core::result;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::fmt;
use std::fmt::{Display, Formatter};
use std::iter::Map;
use crate::keystore::Store;

use tcx_crypto::hash::hex_sha256;
use tcx_primitive::{
KeyManage, PrivateKey, PublicKey, Secp256k1PrivateKey, Secp256k1PublicKey, TypedPrivateKey,
Expand Down
1 change: 0 additions & 1 deletion tcx-chain/src/signer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::Result;
use serde::{Deserialize, Serialize};

pub trait TransactionSigner<Input, Output> {
fn sign_transaction(&mut self, symbol: &str, address: &str, tx: &Input) -> Result<Output>;
Expand Down
2 changes: 1 addition & 1 deletion tcx-constants/src/coin_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::curve::CurveType;
use crate::Result;
use failure::format_err;
use serde_json::Value;

use std::sync::RwLock;

/// Blockchain basic config
Expand Down
3 changes: 1 addition & 2 deletions tcx-crypto/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::Result;
use bitcoin_hashes::hex::{FromHex, ToHex};
use digest::Digest;
use serde::{Deserialize, Serialize};
use sha2::Sha256;

const CREDENTIAL_LEN: usize = 64usize;

Expand Down Expand Up @@ -318,7 +317,7 @@ mod tests {

#[test]
pub fn decrypt_crypto() {
let mut crypto: Crypto<Pbkdf2Params> = Crypto::new(PASSWORD, "TokenCoreX".as_bytes());
let crypto: Crypto<Pbkdf2Params> = Crypto::new(PASSWORD, "TokenCoreX".as_bytes());
let cipher_bytes = crypto.decrypt(PASSWORD).expect("cipher bytes");
assert_eq!("TokenCoreX", String::from_utf8(cipher_bytes).unwrap());

Expand Down
4 changes: 2 additions & 2 deletions tcx-tester/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use bytes::BytesMut;
use prost::Message;
use std::env;
use std::ffi::{CStr, CString};
use std::ffi::CString;
use std::os::raw::c_char;
use tcx::api::InitTokenCoreXParam;
use tcx::{call_tcx_api, get_last_err_message, wrap_buffer};
use tcx::{call_tcx_api, get_last_err_message};

pub fn encode_message(msg: impl Message) -> Vec<u8> {
let mut buf = BytesMut::with_capacity(msg.encoded_len());
Expand Down
8 changes: 3 additions & 5 deletions tcx-tron/src/address.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use bitcoin::util::base58;

use crate::keccak;
use failure::Fail;

use tcx_chain::Address as TraitAddress;
use tcx_chain::Result;
use tcx_constants::CoinInfo;
use tcx_primitive::{
PrivateKey, PublicKey, Secp256k1PrivateKey, Secp256k1PublicKey, TypedPublicKey,
};
use tcx_primitive::TypedPublicKey;

pub struct Address(pub String);

Expand Down Expand Up @@ -36,7 +34,7 @@ mod tests {
use super::Address;
use tcx_chain::Address as TraitAddress;
use tcx_constants::{CoinInfo, CurveType};
use tcx_primitive::{PublicKey, Secp256k1PublicKey, TypedPublicKey};
use tcx_primitive::{PublicKey, TypedPublicKey};

#[test]
fn tron_address() {
Expand Down
9 changes: 2 additions & 7 deletions tcx-tron/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use tcx_chain::{
use bitcoin_hashes::sha256::Hash;
use bitcoin_hashes::Hash as TraitHash;

use serde_json::Value;
use std::convert::{TryFrom, TryInto};
use tcx_primitive::PrivateKey;

use failure::format_err;
Expand Down Expand Up @@ -54,7 +52,6 @@ impl TraitTransactionSigner<TronTxInput, TronTxOutput> for Keystore {
tx: &TronTxInput,
) -> Result<TronTxOutput> {
// let mut raw = tx.raw.clone();
let coin_info = coin_info_from_param(&"TRON", "", "")?;
let data = hex::decode(&tx.raw_data)?;
let hash = Hash::hash(&data);

Expand All @@ -77,7 +74,6 @@ impl TraitMessageSigner<TronMessageInput, TronMessageOutput> for Keystore {
address: &str,
message: &TronMessageInput,
) -> Result<TronMessageOutput> {
let coin_info = coin_info_from_param(&"TRON", "", "")?;
let data = match message.is_hex {
true => {
let mut raw_hex: String = message.value.to_owned();
Expand Down Expand Up @@ -108,11 +104,10 @@ impl TraitMessageSigner<TronMessageInput, TronMessageOutput> for Keystore {
mod tests {
use super::*;
use crate::address::Address;
use bitcoin::util::contracthash::Error::Secp;

use bitcoin::util::misc::hex_bytes;
use digest::Digest;
use serde_json::Value;
use std::convert::TryFrom;

use tcx_chain::{HdKeystore, Keystore, KeystoreGuard};
use tcx_chain::{Metadata, TransactionSigner};
use tcx_constants::CoinInfo;
Expand Down
25 changes: 12 additions & 13 deletions tcx/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,30 @@ use tcx_btc_fork::{
address::BtcForkAddress, BtcForkSegWitTransaction, BtcForkSignedTxOutput, BtcForkTransaction,
BtcForkTxInput,
};
use tcx_chain::Keystore;
use tcx_chain::{Account, HdKeystore, Metadata, PrivateKeystore, Source};
use tcx_chain::{Keystore, KeystoreGuard};
use tcx_ckb::{CkbAddress, CkbTxInput, CkbTxOutput};
use tcx_ckb::{CkbAddress, CkbTxInput};
use tcx_crypto::{XPUB_COMMON_IV, XPUB_COMMON_KEY_128};
use tcx_tron::TrxAddress;

use crate::api::hd_store_derive_param::Derivation;
use crate::api::{
AccountResponse, AccountsResponse, ExternalAddressParam, HdStoreCreateParam,
HdStoreDeriveParam, HdStoreImportParam, KeyType, KeystoreCommonAccountsParam,
KeystoreCommonExistsParam, KeystoreCommonExistsResult, KeystoreCommonExportResult,
PrivateKeyStoreExportParam, PrivateKeyStoreImportParam, Response, WalletKeyParam, WalletResult,
AccountResponse, AccountsResponse, HdStoreCreateParam, HdStoreDeriveParam, HdStoreImportParam,
KeyType, KeystoreCommonAccountsParam, KeystoreCommonExistsParam, KeystoreCommonExistsResult,
KeystoreCommonExportResult, PrivateKeyStoreExportParam, PrivateKeyStoreImportParam, Response,
WalletKeyParam, WalletResult,
};
use crate::api::{InitTokenCoreXParam, SignParam};
use crate::error_handling::Result;
use crate::filemanager::{
cache_keystore, clean_keystore, find_keystore_id_by_address, flush_keystore, WALLET_FILE_DIR,
};
use crate::filemanager::{delete_keystore_file, KEYSTORE_MAP};
use std::collections::HashMap;
use std::process::exit;

use std::sync::RwLockReadGuard;
use tcx_chain::{MessageSigner, TransactionSigner};
use tcx_constants::coin_info::coin_info_from_param;
use tcx_constants::{CoinInfo, CurveType};
use tcx_constants::CurveType;
use tcx_crypto::aes::cbc::encrypt_pkcs7;
use tcx_crypto::hash::{hex_sha256, str_sha256};
use tcx_primitive::{Bip32DeterministicPublicKey, Ss58Codec};
Expand Down Expand Up @@ -159,7 +158,7 @@ pub fn hd_store_import(data: &[u8]) -> Result<Vec<u8>> {
{
let key_hash = str_sha256(&param.mnemonic);
let map = KEYSTORE_MAP.read().unwrap();
let founded: Option<&Keystore> = map
founded = map
.values()
.find(|keystore| keystore.key_hash() == key_hash);
}
Expand All @@ -173,7 +172,7 @@ pub fn hd_store_import(data: &[u8]) -> Result<Vec<u8>> {
meta.password_hint = param.password_hint.to_owned();
meta.source = Source::Mnemonic;

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

let mut keystore = Keystore::Hd(ks);

Expand Down Expand Up @@ -217,7 +216,7 @@ pub fn hd_store_derive(data: &[u8]) -> Result<Vec<u8>> {
let param: HdStoreDeriveParam =
HdStoreDeriveParam::decode(data).expect("hd_store_derive_param");
let mut map = KEYSTORE_MAP.write().unwrap();
let mut keystore: &mut Keystore = match map.get_mut(&param.id) {
let keystore: &mut Keystore = match map.get_mut(&param.id) {
Some(keystore) => Ok(keystore),
_ => Err(format_err!("{}", "wallet_not_found")),
}?;
Expand Down Expand Up @@ -285,7 +284,7 @@ pub fn private_key_store_import(data: &[u8]) -> Result<Vec<u8>> {

keystore.unlock_by_password(&param.password)?;

let mut coin_info = coin_info_from_param(&param.chain_type, &param.network, &param.seg_wit)?;
let coin_info = coin_info_from_param(&param.chain_type, &param.network, &param.seg_wit)?;
// coin_info.derivation_path = param.path.to_string();
let account = match param.chain_type.as_str() {
"BITCOINCASH" => keystore.derive_coin::<BchAddress>(&coin_info),
Expand Down
Loading

0 comments on commit 7c505d4

Please sign in to comment.