* The same label may not be assigned to more than one key, this method will * fail if a key with the same label already exists. * * @return true if the label was set */
| 333 | * @return true if the label was set |
| 334 | */ |
| 335 | bool Wallet::setKeyLabel(QString pubkey, QString label) |
| 336 | { |
| 337 | if( label == QString() ) // clear the label |
| 338 | { |
| 339 | auto pub = fc::variant(pubkey.toStdString()).as<public_key_type>(); |
| 340 | auto old_label = _data.encrypted_private_keys[pub].label; |
| 341 | _data.encrypted_private_keys[pub].label = string(); |
| 342 | if( old_label.size() ) |
| 343 | _label_to_key.erase(QString::fromStdString(old_label)); |
| 344 | |
| 345 | return true; |
| 346 | } |
| 347 | |
| 348 | auto itr = _label_to_key.find(label); |
| 349 | if( itr != _label_to_key.end() ) |
| 350 | return false; |
| 351 | |
| 352 | _label_to_key[label] = pubkey; |
| 353 | |
| 354 | auto pub = fc::variant(pubkey.toStdString()).as<public_key_type>(); |
| 355 | _data.encrypted_private_keys[pub].label = label.toStdString(); |
| 356 | |
| 357 | return true; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | QList<QPair<QString,QString>> Wallet::getAllPublicKeys(bool only_if_private)const |