Browse Source

Remove friend wallet in UI and check restore

pull/41/head
Neo Sun 3 years ago
parent
commit
f2149818bd
  1. 2
      lib/apps/chat/detail.dart
  2. 14
      lib/apps/chat/models.dart
  3. 37
      lib/pages/account_restore.dart
  4. 48
      src/account.rs
  5. 4
      src/apps/wallet/rpc.rs
  6. 12
      src/group/handle.rs
  7. 25
      src/group/models/friend.rs
  8. 10
      src/group/rpc.rs
  9. 1
      src/migrate/account.rs
  10. 1
      src/migrate/chat.rs
  11. 1
      src/own/mod.rs
  12. 23
      src/rpc.rs

2
lib/apps/chat/detail.dart

@ -273,7 +273,7 @@ class _ChatDetailState extends State<ChatDetail> { @@ -273,7 +273,7 @@ class _ChatDetailState extends State<ChatDetail> {
sid: session.id,
online: this._friend.online,
callback: _send,
transferTo: this._friend.wallet,
transferTo: this._friend.pid,
waiting: session.online == OnlineType.Waiting
),
]

14
lib/apps/chat/models.dart

@ -10,7 +10,6 @@ class Friend { @@ -10,7 +10,6 @@ class Friend {
int id = 0;
String pid = '';
String name = '';
String wallet = '';
String cloud = '';
String remark = '';
bool isClosed = false;
@ -36,13 +35,12 @@ class Friend { @@ -36,13 +35,12 @@ class Friend {
this.id = params[0];
this.pid = params[1];
this.name = params[2];
this.wallet = params[3];
this.cloud = params[4];
this.remark = params[5];
this.isClosed = params[6];
this.time = RelativeTime.fromInt(params[7]);
if (params.length == 9) {
this.online = params[8];
this.cloud = params[3];
this.remark = params[4];
this.isClosed = params[5];
this.time = RelativeTime.fromInt(params[6]);
if (params.length == 8) {
this.online = params[7];
}
}
}

37
lib/pages/account_restore.dart

@ -31,6 +31,7 @@ class _AccountRestorePageState extends State<AccountRestorePage> { @@ -31,6 +31,7 @@ class _AccountRestorePageState extends State<AccountRestorePage> {
List<String> _mnemoicWords = [];
bool _wordChecked = false;
bool _loading = false;
String _account = '';
@override
initState() {
@ -227,7 +228,9 @@ class _AccountRestorePageState extends State<AccountRestorePage> { @@ -227,7 +228,9 @@ class _AccountRestorePageState extends State<AccountRestorePage> {
color: Colors.white))),
))),
])),
const SizedBox(height: 32.0),
SizedBox(height: 40.0, child: Center(child: Text(
this._account.isEmpty ? '' : "Account: " + this._account
))),
ButtonText(
text: this._loading ? lang.waiting : lang.next,
enable: _statusChecked && !this._loading,
@ -260,24 +263,34 @@ class _AccountRestorePageState extends State<AccountRestorePage> { @@ -260,24 +263,34 @@ class _AccountRestorePageState extends State<AccountRestorePage> {
})));
}
_addWord() {
_addWord() async {
final word = this._wordController.text.trim();
if (word.length == 0) {
return;
}
setState(() {
this._mnemoicWords.add(word);
if (this._mnemoicWords.length < 12) {
this._wordController.text = '';
this._wordFocus.requestFocus();
this._wordChecked = false;
} else {
this._wordController.text = '';
this._wordChecked = false;
this._mnemoicWords.add(word);
if (this._mnemoicWords.length < 12) {
this._wordController.text = '';
this._wordFocus.requestFocus();
this._wordChecked = false;
} else {
this._wordController.text = '';
this._wordChecked = false;
// check
final mnemonic = this._mnemoicWords.join(' ');
final res = await httpPost('account-check', [_selectedLang.toInt(), mnemonic, ""]);
if (res.isOk) {
this._account = res.params[0];
this._statusChecked = true;
} else {
// TODO tostor error
print(res.error);
}
});
}
setState(() {});
}
_deleteWord(int index) {

48
src/account.rs

@ -61,7 +61,6 @@ pub(crate) struct Account { @@ -61,7 +61,6 @@ pub(crate) struct Account {
pub lock: String, // hashed-lock.
pub secret: Vec<u8>, // encrypted value.
pub encrypt: Vec<u8>, // encrypted encrypt key.
pub wallet: String, // main wallet info.
pub cloud: PeerId, // main cloud service.
pub cloud_key: [u8; 32], // main cloud session key.
pub pub_height: u64, // public information height.
@ -84,7 +83,6 @@ impl Account { @@ -84,7 +83,6 @@ impl Account {
secret: Vec<u8>,
encrypt: Vec<u8>,
plainkey: Vec<u8>,
wallet: String,
cloud: PeerId,
cloud_key: [u8; 32],
) -> Self {
@ -108,7 +106,6 @@ impl Account { @@ -108,7 +106,6 @@ impl Account {
mnemonic,
secret,
encrypt,
wallet,
cloud,
cloud_key,
plainkey,
@ -133,22 +130,25 @@ impl Account { @@ -133,22 +130,25 @@ impl Account {
) -> Result<(Account, PeerKey, Address)> {
let lang = lang_from_i64(rlang);
println!("Lang: {:?}, seed :{}", lang, mnemonic);
// Default ETH wallet account.
let wallet_pass = if pass.len() > 0 { Some(pass) } else { None };
let wallet_sk = generate_eth_account(lang, mnemonic, index, 0, wallet_pass)?;
let wallet_address = format!("{:?}", (&wallet_sk).peer_id());
let wallet = ChainToken::ETH.update_main(&wallet_address, "");
let w = Address::new(ChainToken::ETH, 0, wallet_address, true);
let wpass = if pass.len() > 0 { Some(pass) } else { None };
let key = generate_eth_account(lang, mnemonic, index, 0, wpass)?;
let address = key.peer_id().to_hex();
println!("Lang: {:?}, seed: {}, address: {}", lang, mnemonic, address);
let w = Address::new(ChainToken::ETH, 0, address, true);
let mut rng = ChaChaRng::from_entropy();
let mut key = [0u8; 32];
rng.fill_bytes(&mut key);
let ckey = encrypt_key(salt, lock, &key)?;
let mut eckey = [0u8; 32];
rng.fill_bytes(&mut eckey);
let ckey = encrypt_key(salt, lock, &eckey)?;
let mut ebytes = encrypt_multiple(
salt,
lock,
&ckey,
vec![&wallet_sk.to_db_bytes(), mnemonic.as_bytes()],
vec![&key.to_db_bytes(), mnemonic.as_bytes()],
)?;
let mnemonic = ebytes.pop().unwrap_or(vec![]);
let secret = ebytes.pop().unwrap_or(vec![]);
@ -156,7 +156,7 @@ impl Account { @@ -156,7 +156,7 @@ impl Account {
Ok((
Account::new(
wallet_sk.peer_id(),
key.peer_id(),
index,
rlang,
pass.to_string(),
@ -166,12 +166,11 @@ impl Account { @@ -166,12 +166,11 @@ impl Account {
mnemonic,
secret,
ckey,
key.to_vec(),
wallet,
eckey.to_vec(),
PeerId::default(),
[0u8; 32],
),
wallet_sk,
key,
w,
))
}
@ -231,7 +230,6 @@ impl Account { @@ -231,7 +230,6 @@ impl Account {
})
.unwrap_or([0u8; 32]),
cloud: PeerId::from_hex(v.pop().unwrap().as_str()).unwrap_or(PeerId::default()),
wallet: v.pop().unwrap().as_string(),
avatar: base64::decode(v.pop().unwrap().as_str()).unwrap_or(vec![]),
encrypt: base64::decode(v.pop().unwrap().as_str()).unwrap_or(vec![]),
secret: base64::decode(v.pop().unwrap().as_str()).unwrap_or(vec![]),
@ -249,7 +247,7 @@ impl Account { @@ -249,7 +247,7 @@ impl Account {
pub fn get(db: &DStorage, pid: &PeerId) -> Result<Account> {
let sql = format!(
"SELECT id, pid, indx, lang, pass, name, lock, mnemonic, secret, encrypt, avatar, wallet, cloud, cloud_key, pub_height, own_height, event, datetime FROM accounts WHERE pid = '{}'",
"SELECT id, pid, indx, lang, pass, name, lock, mnemonic, secret, encrypt, avatar, cloud, cloud_key, pub_height, own_height, event, datetime FROM accounts WHERE pid = '{}'",
id_to_str(pid)
);
let mut matrix = db.query(&sql)?;
@ -263,7 +261,7 @@ impl Account { @@ -263,7 +261,7 @@ impl Account {
pub fn all(db: &DStorage) -> Result<Vec<Account>> {
let matrix = db.query(
"SELECT id, pid, indx, lang, pass, name, lock, mnemonic, secret, encrypt, avatar, wallet, cloud, cloud_key, pub_height, own_height, event, datetime FROM accounts ORDER BY datetime DESC",
"SELECT id, pid, indx, lang, pass, name, lock, mnemonic, secret, encrypt, avatar, cloud, cloud_key, pub_height, own_height, event, datetime FROM accounts ORDER BY datetime DESC",
)?;
let mut accounts = vec![];
for values in matrix {
@ -282,7 +280,7 @@ impl Account { @@ -282,7 +280,7 @@ impl Account {
self.id = id;
self.update(db)?;
} else {
let sql = format!("INSERT INTO accounts (pid, indx, lang, pass, name, lock, mnemonic, secret, encrypt, avatar, wallet, cloud, cloud_key, pub_height, own_height, event, datetime) VALUES ('{}', {}, {}, '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', {}, {}, '{}', {})",
let sql = format!("INSERT INTO accounts (pid, indx, lang, pass, name, lock, mnemonic, secret, encrypt, avatar, cloud, cloud_key, pub_height, own_height, event, datetime) VALUES ('{}', {}, {}, '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', {}, {}, '{}', {})",
id_to_str(&self.pid),
self.index,
self.lang,
@ -293,7 +291,6 @@ impl Account { @@ -293,7 +291,6 @@ impl Account {
base64::encode(&self.secret),
base64::encode(&self.encrypt),
base64::encode(&self.avatar),
self.wallet,
self.cloud.to_hex(),
hex::encode(&self.cloud_key),
self.pub_height,
@ -308,12 +305,11 @@ impl Account { @@ -308,12 +305,11 @@ impl Account {
}
pub fn update(&self, db: &DStorage) -> Result<usize> {
let sql = format!("UPDATE accounts SET name='{}', lock='{}', encrypt='{}', avatar='{}', wallet='{}', cloud='{}', cloud_key='{}', pub_height={}, own_height={}, event='{}', datetime={} WHERE id = {}",
let sql = format!("UPDATE accounts SET name='{}', lock='{}', encrypt='{}', avatar='{}', cloud='{}', cloud_key='{}', pub_height={}, own_height={}, event='{}', datetime={} WHERE id = {}",
self.name,
self.lock,
base64::encode(&self.encrypt),
base64::encode(&self.avatar),
self.wallet,
self.cloud.to_hex(),
hex::encode(&self.cloud_key),
self.pub_height,
@ -327,10 +323,9 @@ impl Account { @@ -327,10 +323,9 @@ impl Account {
pub fn update_info(&self, db: &DStorage) -> Result<usize> {
let sql = format!(
"UPDATE accounts SET name='{}', avatar='{}', wallet='{}', cloud='{}', cloud_key='{}', pub_height={} WHERE id = {}",
"UPDATE accounts SET name='{}', avatar='{}', cloud='{}', cloud_key='{}', pub_height={} WHERE id = {}",
self.name,
base64::encode(&self.avatar),
self.wallet,
self.cloud.to_hex(),
hex::encode(&self.cloud_key),
self.pub_height,
@ -361,7 +356,6 @@ impl Account { @@ -361,7 +356,6 @@ impl Account {
pub(crate) struct User {
pub height: u64,
pub name: String,
pub wallet: String,
pub cloud: PeerId,
pub cloud_key: [u8; 32],
pub avatar: Vec<u8>,
@ -371,7 +365,6 @@ impl User { @@ -371,7 +365,6 @@ impl User {
pub fn info(
height: u64,
name: String,
wallet: String,
cloud: PeerId,
cloud_key: [u8; 32],
avatar: Vec<u8>,
@ -379,7 +372,6 @@ impl User { @@ -379,7 +372,6 @@ impl User {
Self {
height,
name,
wallet,
cloud,
cloud_key,
avatar,

4
src/apps/wallet/rpc.rs

@ -375,7 +375,6 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<Global>) { @@ -375,7 +375,6 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<Global>) {
let a_db = account_db(&state.base, &state.secret)?;
let mut own_lock = state.own.write().await;
let account = own_lock.account_mut(&pid)?;
account.wallet = address.chain.update_main(&address.address, &account.wallet);
account.pub_height = account.pub_height + 1;
account.update_info(&a_db)?;
let user = own_lock.clone_user(&pid)?;
@ -615,14 +614,13 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<Global>) { @@ -615,14 +614,13 @@ pub(crate) fn new_rpc_handler(handler: &mut RpcHandler<Global>) {
let db = wallet_db(&state.base, &pid, &db_key)?;
let a_db = account_db(&state.base, &state.secret)?;
let address = Address::get(&db, &id)?;
let _address = Address::get(&db, &id)?;
Address::main(&db, &id)?;
let mut results = HandleResult::new();
let mut own_lock = state.own.write().await;
let account = own_lock.account_mut(&pid)?;
account.wallet = address.chain.update_main(&address.address, &account.wallet);
account.pub_height = account.pub_height + 1;
account.update_info(&a_db)?;
let user = own_lock.clone_user(&pid)?;

12
src/group/handle.rs

@ -202,14 +202,8 @@ impl GroupEvent { @@ -202,14 +202,8 @@ impl GroupEvent {
r.is_over = true;
r.is_ok = true;
r.update(&db)?;
let friend = Friend::from_remote(
&db,
fpid,
r.name,
"".to_owned(),
PeerId::default(),
[0u8; 32],
)?;
let friend =
Friend::from_remote(&db, fpid, r.name, PeerId::default(), [0u8; 32])?;
results.rpcs.push(rpc::request_agree(r.id, &friend));
// ADD NEW SESSION.
@ -265,7 +259,6 @@ impl GroupEvent { @@ -265,7 +259,6 @@ impl GroupEvent {
let info = GroupEvent::InfoRes(User::info(
account.pub_height,
account.name,
account.wallet,
account.cloud,
account.cloud_key,
account.avatar,
@ -283,7 +276,6 @@ impl GroupEvent { @@ -283,7 +276,6 @@ impl GroupEvent {
let mut f = Friend::get(&db, &fid)?;
let name = remote.name.clone();
f.name = remote.name;
f.wallet = remote.wallet;
f.height = remote.height as i64;
f.cloud = remote.cloud;
f.cloud_key = remote.cloud_key;

25
src/group/models/friend.rs

@ -14,7 +14,6 @@ pub(crate) struct Friend { @@ -14,7 +14,6 @@ pub(crate) struct Friend {
pub id: i64,
pub pid: PeerId,
pub name: String,
pub wallet: String,
pub cloud: PeerId,
pub cloud_key: [u8; 32],
pub height: i64,
@ -27,7 +26,6 @@ impl Friend { @@ -27,7 +26,6 @@ impl Friend {
pub fn new(
pid: PeerId,
name: String,
wallet: String,
cloud: PeerId,
cloud_key: [u8; 32],
remark: String,
@ -43,7 +41,6 @@ impl Friend { @@ -43,7 +41,6 @@ impl Friend {
id: 0,
pid,
name,
wallet,
cloud,
cloud_key,
height,
@ -68,7 +65,6 @@ impl Friend { @@ -68,7 +65,6 @@ impl Friend {
})
.unwrap_or([0u8; 32]),
cloud: PeerId::from_hex(v.pop().unwrap().as_str()).unwrap_or(PeerId::default()),
wallet: v.pop().unwrap().as_string(),
name: v.pop().unwrap().as_string(),
pid: id_from_str(v.pop().unwrap().as_str()).unwrap_or(PeerId::default()),
id: v.pop().unwrap().as_i64(),
@ -79,20 +75,18 @@ impl Friend { @@ -79,20 +75,18 @@ impl Friend {
db: &DStorage,
pid: PeerId,
name: String,
wallet: String,
cloud: PeerId,
cloud_key: [u8; 32],
) -> Result<Friend> {
if let Ok(mut friend) = Friend::get_id(&db, &pid) {
friend.name = name;
friend.wallet = wallet;
friend.cloud = cloud;
friend.cloud_key = cloud_key;
friend.is_closed = false;
friend.remote_update(&db)?;
Ok(friend)
} else {
let mut friend = Friend::new(pid, name, wallet, cloud, cloud_key, "".to_owned(), 0);
let mut friend = Friend::new(pid, name, cloud, cloud_key, "".to_owned(), 0);
friend.insert(&db)?;
Ok(friend)
}
@ -114,7 +108,6 @@ impl Friend { @@ -114,7 +108,6 @@ impl Friend {
self.id,
id_to_str(&self.pid),
self.name,
self.wallet,
self.cloud.to_hex(),
self.remark,
self.is_closed,
@ -127,7 +120,6 @@ impl Friend { @@ -127,7 +120,6 @@ impl Friend {
self.id,
id_to_str(&self.pid),
self.name,
self.wallet,
self.cloud.to_hex(),
self.remark,
self.is_closed,
@ -137,7 +129,7 @@ impl Friend { @@ -137,7 +129,7 @@ impl Friend {
}
pub fn get_id(db: &DStorage, pid: &PeerId) -> Result<Friend> {
let sql = format!("SELECT id, pid, name, wallet, cloud, cloud_key, height, remark, is_closed, datetime FROM friends WHERE pid = '{}'", id_to_str(pid));
let sql = format!("SELECT id, pid, name, cloud, cloud_key, height, remark, is_closed, datetime FROM friends WHERE pid = '{}'", id_to_str(pid));
let mut matrix = db.query(&sql)?;
if matrix.len() > 0 {
Ok(Friend::from_values(matrix.pop().unwrap())) // safe unwrap()
@ -147,7 +139,7 @@ impl Friend { @@ -147,7 +139,7 @@ impl Friend {
}
pub fn get(db: &DStorage, id: &i64) -> Result<Friend> {
let sql = format!("SELECT id, pid, name, wallet, cloud, cloud_key, height, remark, is_closed, datetime FROM friends WHERE id = {}", id);
let sql = format!("SELECT id, pid, name, cloud, cloud_key, height, remark, is_closed, datetime FROM friends WHERE id = {}", id);
let mut matrix = db.query(&sql)?;
if matrix.len() > 0 {
Ok(Friend::from_values(matrix.pop().unwrap())) // safe unwrap()
@ -159,7 +151,7 @@ impl Friend { @@ -159,7 +151,7 @@ impl Friend {
/// use in rpc when load account friends.
pub fn list(db: &DStorage) -> Result<Vec<Friend>> {
let matrix = db.query(
"SELECT id, pid, name, wallet, cloud, cloud_key, height, remark, is_closed, datetime FROM friends",
"SELECT id, pid, name, cloud, cloud_key, height, remark, is_closed, datetime FROM friends",
)?;
let mut friends = vec![];
for values in matrix {
@ -169,10 +161,9 @@ impl Friend { @@ -169,10 +161,9 @@ impl Friend {
}
pub fn insert(&mut self, db: &DStorage) -> Result<()> {
let sql = format!("INSERT INTO friends (pid, name, wallet, cloud, cloud_key, height, remark, is_closed, datetime) VALUES ('{}', '{}', '{}', '{}', '{}', {}, '{}', {}, {})",
let sql = format!("INSERT INTO friends (pid, name, cloud, cloud_key, height, remark, is_closed, datetime) VALUES ('{}', '{}', '{}', '{}', {}, '{}', {}, {})",
id_to_str(&self.pid),
self.name,
self.wallet,
self.cloud.to_hex(),
hex::encode(&self.cloud_key),
self.height,
@ -186,9 +177,8 @@ impl Friend { @@ -186,9 +177,8 @@ impl Friend {
}
pub fn update(&self, db: &DStorage) -> Result<usize> {
let sql = format!("UPDATE friends SET name='{}', wallet='{}', cloud='{}', cloud_key='{}', height={}, remark='{}', is_closed={} WHERE id={}",
let sql = format!("UPDATE friends SET name='{}', cloud='{}', cloud_key='{}', height={}, remark='{}', is_closed={} WHERE id={}",
self.name,
self.wallet,
self.cloud.to_hex(),
hex::encode(&self.cloud_key),
self.height,
@ -209,9 +199,8 @@ impl Friend { @@ -209,9 +199,8 @@ impl Friend {
pub fn remote_update(&self, db: &DStorage) -> Result<usize> {
let sql = format!(
"UPDATE friends SET name='{}', wallet='{}', cloud='{}', cloud_key='{}', height={}, is_closed = false WHERE id = {}",
"UPDATE friends SET name='{}', cloud='{}', cloud_key='{}', height={}, is_closed = false WHERE id = {}",
self.name,
self.wallet,
self.cloud.to_hex(),
hex::encode(&self.cloud_key),
self.height,

10
src/group/rpc.rs

@ -302,14 +302,8 @@ pub(crate) fn group_rpc(handler: &mut RpcHandler<Global>) { @@ -302,14 +302,8 @@ pub(crate) fn group_rpc(handler: &mut RpcHandler<Global>) {
request.is_over = true;
request.update(&db)?;
let friend = Friend::from_remote(
&db,
request.pid,
request.name,
"".to_owned(),
PeerId::default(),
[0u8; 32],
)?;
let friend =
Friend::from_remote(&db, request.pid, request.name, PeerId::default(), [0u8; 32])?;
results.rpcs.push(json!([id, friend.to_rpc()]));
// ADD NEW SESSION.

1
src/migrate/account.rs

@ -12,7 +12,6 @@ pub(super) const ACCOUNT_VERSIONS: [&str; 13] = [ @@ -12,7 +12,6 @@ pub(super) const ACCOUNT_VERSIONS: [&str; 13] = [
encrypt TEXT NOT NULL,
mnemonic TEXT NOT NULL,
avatar TEXT NOT NULL,
wallet TEXT NOT NULL,
cloud TEXT NOT NULL,
cloud_key TEXT NOT NULL,
pub_height INTEGER NOT NULL,

1
src/migrate/chat.rs

@ -4,7 +4,6 @@ pub(super) const CHAT_VERSIONS: [&str; 3] = [ @@ -4,7 +4,6 @@ pub(super) const CHAT_VERSIONS: [&str; 3] = [
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
pid TEXT NOT NULL,
name TEXT NOT NULL,
wallet TEXT NOT NULL,
cloud TEXT NOT NULL,
cloud_key TEXT NOT NULL,
height INTEGER NOT NULL,

1
src/own/mod.rs

@ -226,7 +226,6 @@ impl Own { @@ -226,7 +226,6 @@ impl Own {
Ok(User::info(
u.pub_height,
u.name.clone(),
u.wallet.clone(),
u.cloud.clone(),
u.cloud_key.clone(),
u.avatar.clone(),

23
src/rpc.rs

@ -12,7 +12,7 @@ use tdn::{ @@ -12,7 +12,7 @@ use tdn::{
rpc::{json, rpc_response, RpcError, RpcHandler, RpcParam},
},
};
use tdn_did::{generate_mnemonic, Count};
use tdn_did::{generate_eth_account, generate_mnemonic, Count};
use crate::account::lang_from_i64;
use crate::apps::app_rpc_inject;
@ -198,7 +198,9 @@ fn new_rpc_handler(global: Arc<Global>) -> RpcHandler<Global> { @@ -198,7 +198,9 @@ fn new_rpc_handler(global: Arc<Global>) -> RpcHandler<Global> {
let lang = params[0].as_i64().ok_or(RpcError::ParseError)?;
let language = lang_from_i64(lang);
let words = generate_mnemonic(language, Count::Words12);
Ok(HandleResult::rpc(json!([words])))
let key = generate_eth_account(language, &words, 0, 0, None)?;
let pid = key.peer_id().to_hex();
Ok(HandleResult::rpc(json!([words, pid])))
},
);
@ -234,6 +236,23 @@ fn new_rpc_handler(global: Arc<Global>) -> RpcHandler<Global> { @@ -234,6 +236,23 @@ fn new_rpc_handler(global: Arc<Global>) -> RpcHandler<Global> {
},
);
handler.add_method(
"account-check",
|params: Vec<RpcParam>, state: Arc<Global>| async move {
let lang = params[0].as_i64().ok_or(RpcError::ParseError)?;
let seed = params[1].as_str().ok_or(RpcError::ParseError)?;
let pass = params[2].as_str().ok_or(RpcError::ParseError)?;
let np = if pass.is_empty() { Some(pass) } else { None };
let language = lang_from_i64(lang);
println!("Lang: {:?}, seed :{}", language, seed);
let key = generate_eth_account(language, seed, 0, 0, np)?;
let pid = key.peer_id().to_hex();
Ok(HandleResult::rpc(json!(vec![pid])))
},
);
handler.add_method(
"account-restore",
|params: Vec<RpcParam>, state: Arc<Global>| async move {

Loading…
Cancel
Save