@ -244,33 +244,34 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
if ( role = = Qt : : EditRole )
if ( role = = Qt : : EditRole )
{
{
switch ( index . column ( ) )
LOCK ( wallet - > cs_wallet ) ; /* For SetAddressBook / DelAddressBook */
CTxDestination curAddress = CBitcoinAddress ( rec - > address . toStdString ( ) ) . Get ( ) ;
if ( index . column ( ) = = Label )
{
{
case Label :
// Do nothing, if old label == new label
// Do nothing, if old label == new label
if ( rec - > label = = value . toString ( ) )
if ( rec - > label = = value . toString ( ) )
{
{
editStatus = NO_CHANGES ;
editStatus = NO_CHANGES ;
return false ;
return false ;
}
}
wallet - > SetAddressBook ( CBitcoinAddress ( rec - > address . toStdString ( ) ) . Get ( ) , value . toString ( ) . toStdString ( ) , strPurpose ) ;
wallet - > SetAddressBook ( curAddress , value . toString ( ) . toStdString ( ) , strPurpose ) ;
break ;
} else if ( index . column ( ) = = Address ) {
case Address :
CTxDestination newAddress = CBitcoinAddress ( value . toString ( ) . toStdString ( ) ) . Get ( ) ;
// Do nothing, if old address == new address
// Refuse to set invalid address, set error status and return false
if ( CBitcoinAddress ( rec - > address . toStdString ( ) ) = = CBitcoinAddress ( value . toString ( ) . toStdString ( ) ) )
if ( boost : : get < CNoDestination > ( & newAddress ) )
{
{
editStatus = NO_CHANGE S;
editStatus = INVALID_ADDRES S;
return false ;
return false ;
}
}
// Refuse to set invalid address, set error status and return false
// Do nothing, if old address == new address
else if ( ! walletModel - > validateAddress ( value . toString ( ) ) )
else if ( newAddress = = curAddress )
{
{
editStatus = INVALID_ADDRES S;
editStatus = NO_CHANGE S;
return false ;
return false ;
}
}
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
// Check for duplicate addresses to prevent accidental deletion of addresses, if you try
// to paste an existing address over another address (with a different label)
// to paste an existing address over another address (with a different label)
else if ( wallet - > mapAddressBook . count ( CBitcoi nAddress( value . toString ( ) . toStdString ( ) ) . Get ( ) ) )
else if ( wallet - > mapAddressBook . count ( new Address ) )
{
{
editStatus = DUPLICATE_ADDRESS ;
editStatus = DUPLICATE_ADDRESS ;
return false ;
return false ;
@ -278,16 +279,12 @@ bool AddressTableModel::setData(const QModelIndex &index, const QVariant &value,
// Double-check that we're not overwriting a receiving address
// Double-check that we're not overwriting a receiving address
else if ( rec - > type = = AddressTableEntry : : Sending )
else if ( rec - > type = = AddressTableEntry : : Sending )
{
{
{
LOCK ( wallet - > cs_wallet ) ;
// Remove old entry
// Remove old entry
wallet - > DelAddressBook ( CBitcoinAddress ( rec - > address . toStdString ( ) ) . Get ( ) ) ;
wallet - > DelAddressBook ( curAddress ) ;
// Add new entry with new address
// Add new entry with new address
wallet - > SetAddressBook ( CBitcoi nAddress( value . toString ( ) . toStdString ( ) ) . Get ( ) , rec - > label . toStdString ( ) , strPurpose ) ;
wallet - > SetAddressBook ( new Address , rec - > label . toStdString ( ) , strPurpose ) ;
}
}
}
}
break ;
}
return true ;
return true ;
}
}
return false ;
return false ;