Add GetNewDestination to CWallet to fetch new destinations
Instead of having the same multiple lines of code everywhere that new destinations are fetched, introduce GetNewDestination as a member function of CWallet which does the key fetching, label setting, script generation, and destination generation.
This commit is contained in:
1 parent
0853d8d2fd
commit
172213be5b
9 files changed
+52
-41
No files matched your search
@@ -358,12 +358,15 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
// Add entry
|
||||
walletModel->wallet().setAddressBook(DecodeDestination(strAddress), strLabel, "send");
|
||||
}
|
||||
else if(type == Receive)
|
||||
{
|
||||
// Generate a new address to associate with given label
|
||||
CPubKey newKey;
|
||||
if(!walletModel->wallet().getKeyFromPool(false /* internal */, newKey))
|
||||
CTxDestination dest;
|
||||
if(!walletModel->wallet().getNewDestination(address_type, strLabel, dest))
|
||||
{
|
||||
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
|
||||
if(!ctx.isValid())
|
||||
@@ -372,23 +375,18 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
|
||||
editStatus = WALLET_UNLOCK_FAILURE;
|
||||
return QString();
|
||||
}
|
||||
if(!walletModel->wallet().getKeyFromPool(false /* internal */, newKey))
|
||||
if(!walletModel->wallet().getNewDestination(address_type, strLabel, dest))
|
||||
{
|
||||
editStatus = KEY_GENERATION_FAILURE;
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
walletModel->wallet().learnRelatedScripts(newKey, address_type);
|
||||
strAddress = EncodeDestination(GetDestinationForKey(newKey, address_type));
|
||||
strAddress = EncodeDestination(dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
// Add entry
|
||||
walletModel->wallet().setAddressBook(DecodeDestination(strAddress), strLabel,
|
||||
(type == Send ? "send" : "receive"));
|
||||
return QString::fromStdString(strAddress);
|
||||
}
|
||||
|
||||
|
||||
@@ -666,16 +666,14 @@ void PaymentServer::fetchPaymentACK(WalletModel* walletModel, const SendCoinsRec
|
||||
payment.add_transactions(transaction.data(), transaction.size());
|
||||
|
||||
// Create a new refund address, or re-use:
|
||||
CPubKey newKey;
|
||||
if (walletModel->wallet().getKeyFromPool(false /* internal */, newKey)) {
|
||||
CTxDestination dest;
|
||||
const OutputType change_type = walletModel->wallet().getDefaultChangeType() != OutputType::CHANGE_AUTO ? walletModel->wallet().getDefaultChangeType() : walletModel->wallet().getDefaultAddressType();
|
||||
if (walletModel->wallet().getNewDestination(change_type, "", dest)) {
|
||||
// BIP70 requests encode the scriptPubKey directly, so we are not restricted to address
|
||||
// types supported by the receiver. As a result, we choose the address format we also
|
||||
// use for change. Despite an actual payment and not change, this is a close match:
|
||||
// it's the output type we use subject to privacy issues, but not restricted by what
|
||||
// other software supports.
|
||||
const OutputType change_type = walletModel->wallet().getDefaultChangeType() != OutputType::CHANGE_AUTO ? walletModel->wallet().getDefaultChangeType() : walletModel->wallet().getDefaultAddressType();
|
||||
walletModel->wallet().learnRelatedScripts(newKey, change_type);
|
||||
CTxDestination dest = GetDestinationForKey(newKey, change_type);
|
||||
std::string label = tr("Refund from %1").arg(recipient.authenticatedMerchant).toStdString();
|
||||
walletModel->wallet().setAddressBook(dest, label, "refund");
|
||||
|
||||
|
||||
Reference in new issue
Block a user