Skip to content

Commit

Permalink
fix the init_tcx_error when account not contains public_key
Browse files Browse the repository at this point in the history
  • Loading branch information
XuNeal committed Dec 30, 2020
1 parent 0e80ec2 commit 1b94c87
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tcx-chain/src/keystore/hd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl HdKeystore {
network: coin_info.network.to_string(),
ext_pub_key,
seg_wit: coin_info.seg_wit.to_string(),
public_key: hex::encode(public_key.to_bytes()),
public_key: Some(hex::encode(public_key.to_bytes())),
};

if let Some(_) = self
Expand Down Expand Up @@ -328,7 +328,7 @@ mod tests {
seg_wit: "NONE".to_string(),
curve: CurveType::SECP256k1,
coin: "BITCOIN".to_string(),
public_key: "".to_string()
public_key: None
};

assert_eq!(acc, expected);
Expand Down Expand Up @@ -403,7 +403,7 @@ mod tests {
seg_wit: "NONE".to_string(),
curve: CurveType::SECP256k1,
coin: "BITCOIN".to_string(),
public_key: "".to_string()
public_key: None
};

assert_eq!(acc, expected);
Expand Down
2 changes: 1 addition & 1 deletion tcx-chain/src/keystore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub struct Account {
pub network: String,
pub seg_wit: String,
pub ext_pub_key: String,
pub public_key: String,
pub public_key: Option<String>,
}

/// Chain address interface, for encapsulate derivation
Expand Down
2 changes: 1 addition & 1 deletion tcx-chain/src/keystore/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl PrivateKeystore {
network: coin.network.to_string(),
seg_wit: coin.seg_wit.to_string(),
ext_pub_key: "".to_string(),
public_key: hex::encode(pub_key.to_bytes()),
public_key: Some(hex::encode(pub_key.to_bytes())),
};

Ok(acc)
Expand Down
6 changes: 5 additions & 1 deletion tcx/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,11 @@ pub(crate) fn get_public_key(data: &[u8]) -> Result<Vec<u8>> {
"TEZOS" => {
let account = keystore.account(&param.chain_type, &param.address);
if let Some(acc) = account {
let pub_key = hex::decode(acc.public_key.clone())?;
tcx_ensure!(
acc.public_key.is_some(),
format_err!("account_not_contains_public_key")
);
let pub_key = hex::decode(acc.public_key.clone().unwrap())?;
let to_hash = [edpk_prefix, pub_key].concat();
let hashed = dsha256(&to_hash);
let hash_with_checksum = [to_hash, hashed[0..4].to_vec()].concat();
Expand Down

0 comments on commit 1b94c87

Please sign in to comment.