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> {
sid: session.id, sid: session.id,
online: this._friend.online, online: this._friend.online,
callback: _send, callback: _send,
transferTo: this._friend.wallet, transferTo: this._friend.pid,
waiting: session.online == OnlineType.Waiting waiting: session.online == OnlineType.Waiting
), ),
] ]

14
lib/apps/chat/models.dart

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

37
lib/pages/account_restore.dart

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

48
src/account.rs

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

4
src/apps/wallet/rpc.rs

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

12
src/group/handle.rs

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

25
src/group/models/friend.rs

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

10
src/group/rpc.rs

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

1
src/migrate/account.rs

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

1
src/migrate/chat.rs

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

1
src/own/mod.rs

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

23
src/rpc.rs

@ -12,7 +12,7 @@ use tdn::{
rpc::{json, rpc_response, RpcError, RpcHandler, RpcParam}, 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::account::lang_from_i64;
use crate::apps::app_rpc_inject; use crate::apps::app_rpc_inject;
@ -198,7 +198,9 @@ fn new_rpc_handler(global: Arc<Global>) -> RpcHandler<Global> {
let lang = params[0].as_i64().ok_or(RpcError::ParseError)?; let lang = params[0].as_i64().ok_or(RpcError::ParseError)?;
let language = lang_from_i64(lang); let language = lang_from_i64(lang);
let words = generate_mnemonic(language, Count::Words12); 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> {
}, },
); );
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( handler.add_method(
"account-restore", "account-restore",
|params: Vec<RpcParam>, state: Arc<Global>| async move { |params: Vec<RpcParam>, state: Arc<Global>| async move {

Loading…
Cancel
Save