-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: open tcx scan_keystores api[R2D2-13481] #141
Closed
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8af78fb
feat: open tcx scan_keystores api
xiaoguang1010 0619725
build: fix CI error
xiaoguang1010 6d1fd89
chore: KeystoreResult and ImportPrivateKeyResult add is_migrated field
xiaoguang1010 a87c53a
test: fix unit test failure
xiaoguang1010 4739f82
chore: optimized scan_keystores return data
xiaoguang1010 2448fe1
chore: modify scan_keystores api return data
xiaoguang1010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ use crate::api::{ | |
ReadKeystoreMnemonicPathResult, ScanLegacyKeystoresResult, WalletId, | ||
}; | ||
use crate::error_handling::Result; | ||
use crate::filemanager::{cache_keystore, KEYSTORE_MAP, WALLET_FILE_DIR}; | ||
use crate::filemanager::{cache_keystore, KEYSTORE_MAP, WALLET_FILE_DIR, WALLET_V1_DIR}; | ||
use crate::filemanager::{flush_keystore, LEGACY_WALLET_FILE_DIR}; | ||
use crate::handler::{encode_message, encrypt_xpub}; | ||
use anyhow::anyhow; | ||
|
@@ -191,6 +191,7 @@ pub(crate) fn migrate_keystore(data: &[u8]) -> Result<Vec<u8>> { | |
source_fingerprint: keystore.fingerprint().to_string(), | ||
is_existed, | ||
existed_id, | ||
status: "migrated".to_string(), | ||
}; | ||
|
||
let ret = encode_message(MigrateKeystoreResult { | ||
|
@@ -442,12 +443,14 @@ fn parse_legacy_kesytore(contents: String) -> Result<LegacyKeystoreResult> { | |
NumberOrNumberStr::Number(t) => t, | ||
NumberOrNumberStr::NumberStr(t) => f64::from_str(&t).expect("f64 from timestamp") as i64, | ||
}; | ||
let status = get_migrated_status(WALLET_V1_DIR, &legacy_keystore.id)?; | ||
let keystore_result = LegacyKeystoreResult { | ||
id: legacy_keystore.id.to_string(), | ||
name: meta.name.to_string(), | ||
source: meta.source.as_ref().unwrap_or(&"".to_string()).to_string(), | ||
created_at: created_at.to_string(), | ||
accounts: vec![account], | ||
status, | ||
}; | ||
Ok(keystore_result) | ||
} | ||
|
@@ -500,12 +503,14 @@ fn parse_tcx_keystore(v: &Value) -> Result<LegacyKeystoreResult> { | |
} | ||
let id = v["id"].as_str().expect("keystore id").to_string(); | ||
let meta: Metadata = serde_json::from_value(v["imTokenMeta"].clone())?; | ||
let status = get_migrated_status(WALLET_V1_DIR, &id)?; | ||
let keystore_result = LegacyKeystoreResult { | ||
id, | ||
name: meta.name.to_string(), | ||
source: meta.source.to_string(), | ||
created_at: meta.timestamp.to_string(), | ||
accounts: account_responses, | ||
status, | ||
}; | ||
Ok(keystore_result) | ||
} | ||
|
@@ -523,6 +528,21 @@ fn merge_migrate_source(id: &str, ori_source: &str) -> String { | |
} | ||
} | ||
|
||
pub fn get_migrated_status(dir: &str, id: &str) -> Result<String> { | ||
let migrated_id_map = read_migrated_map().1; | ||
let is_migrated = migrated_id_map | ||
.values() | ||
.any(|ids| ids.contains(&id.to_string())); | ||
let status = match (dir, is_migrated) { | ||
(WALLET_V1_DIR, true) => "migrated".to_string(), | ||
(WALLET_V1_DIR, false) => "unmigrated".to_string(), | ||
(WALLET_V2_DIR, true) => "migrated".to_string(), | ||
(WALLET_V2_DIR, false) => "new".to_string(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xiaoguang1010 需要确认这里如果两个老的 keystore 都有相同的助记词,并且都迁移之后,这里是否会正确的返回migrated |
||
_ => return Err(anyhow!("{}", "get_migrated_status_error")), | ||
}; | ||
Ok(status) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::fs; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里直接叫 status 太过于generic 了。建议改成 migration_status