| 340 | } |
| 341 | |
| 342 | QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type) |
| 343 | { |
| 344 | std::string strLabel = label.toStdString(); |
| 345 | std::string strAddress = address.toStdString(); |
| 346 | |
| 347 | editStatus = OK; |
| 348 | |
| 349 | if(type == Send) |
| 350 | { |
| 351 | if(!walletModel->validateAddress(address)) |
| 352 | { |
| 353 | editStatus = INVALID_ADDRESS; |
| 354 | return QString(); |
| 355 | } |
| 356 | // Check for duplicate addresses |
| 357 | { |
| 358 | if (walletModel->wallet().getAddress( |
| 359 | DecodeDestination(strAddress), /*name=*/nullptr, /*purpose=*/nullptr)) |
| 360 | { |
| 361 | editStatus = DUPLICATE_ADDRESS; |
| 362 | return QString(); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | // Add entry |
| 367 | walletModel->wallet().setAddressBook(DecodeDestination(strAddress), strLabel, wallet::AddressPurpose::SEND); |
| 368 | } |
| 369 | else if(type == Receive) |
| 370 | { |
| 371 | // Generate a new address to associate with given label |
| 372 | if (auto dest{walletModel->wallet().getNewDestination(address_type, strLabel)}) { |
| 373 | strAddress = EncodeDestination(*dest); |
| 374 | } else { |
| 375 | WalletModel::UnlockContext ctx(walletModel->requestUnlock()); |
| 376 | if (!ctx.isValid()) { |
| 377 | // Unlock wallet failed or was cancelled |
| 378 | editStatus = WALLET_UNLOCK_FAILURE; |
| 379 | return QString(); |
| 380 | } |
| 381 | if (auto dest_retry{walletModel->wallet().getNewDestination(address_type, strLabel)}) { |
| 382 | strAddress = EncodeDestination(*dest_retry); |
| 383 | } else { |
| 384 | editStatus = KEY_GENERATION_FAILURE; |
| 385 | return QString(); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | else |
| 390 | { |
| 391 | return QString(); |
| 392 | } |
| 393 | return QString::fromStdString(strAddress); |
| 394 | } |
| 395 | |
| 396 | bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent) |
| 397 | { |
no test coverage detected