Merge 3ddef1e13f0af10dea337e839650f5828b32e164 into 8bd293ccd50db6520966717114a8c72015b8146b

This commit is contained in:
cwd.systems | 0KN 2024-12-03 15:16:45 +05:45 committed by GitHub
commit ccd8292fdd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -24,28 +24,23 @@ public class SellNameTransaction extends Transaction {
private SellNameTransactionData sellNameTransactionData;
// Constructors
public SellNameTransaction(Repository repository, TransactionData transactionData) {
super(repository, transactionData);
this.sellNameTransactionData = (SellNameTransactionData) this.transactionData;
}
// More information
@Override
public List<String> getRecipientAddresses() throws DataException {
return Collections.emptyList();
return Collections.emptyList(); // No direct recipient address for this transaction
}
// Navigation
public Account getOwner() {
return this.getCreator();
return this.getCreator(); // Owner is the creator of the transaction
}
// Processing
@Override
public ValidationResult isValid() throws DataException {
String name = this.sellNameTransactionData.getName();
@ -59,59 +54,54 @@ public class SellNameTransaction extends Transaction {
if (!name.equals(Unicode.normalize(name)))
return ValidationResult.NAME_NOT_NORMALIZED;
// Retrieve name data from repository
NameData nameData = this.repository.getNameRepository().fromName(name);
// Check name exists
// Check if name exists
if (nameData == null)
return ValidationResult.NAME_DOES_NOT_EXIST;
// Check name isn't currently for sale
// Check name is not already for sale
if (nameData.isForSale())
return ValidationResult.NAME_ALREADY_FOR_SALE;
// Check transaction's public key matches name's current owner
// Validate transaction's public key matches name's current owner
Account owner = getOwner();
if (!owner.getAddress().equals(nameData.getOwner()))
return ValidationResult.INVALID_NAME_OWNER;
// Check amount is positive
if (this.sellNameTransactionData.getAmount() <= 0)
// Check amount is positive and within valid range
long amount = this.sellNameTransactionData.getAmount();
if (amount <= 0)
return ValidationResult.NEGATIVE_AMOUNT;
// Check amount within bounds
if (this.sellNameTransactionData.getAmount() >= MAX_AMOUNT)
if (amount >= MAX_AMOUNT)
return ValidationResult.INVALID_AMOUNT;
// Check issuer has enough funds
// Check if owner has enough balance for the transaction fee
if (owner.getConfirmedBalance(Asset.QORT) < this.sellNameTransactionData.getFee())
return ValidationResult.NO_BALANCE;
return ValidationResult.OK;
return ValidationResult.OK; // All validation checks passed
}
@Override
public void preProcess() throws DataException {
SellNameTransactionData sellNameTransactionData = (SellNameTransactionData) transactionData;
// Rebuild this name in the Names table from the transaction history
// This is necessary because in some rare cases names can be missing from the Names table after registration
// but we have been unable to reproduce the issue and track down the root cause
// Directly access class field rather than local variable for clarity
NamesDatabaseIntegrityCheck namesDatabaseIntegrityCheck = new NamesDatabaseIntegrityCheck();
namesDatabaseIntegrityCheck.rebuildName(sellNameTransactionData.getName(), this.repository);
namesDatabaseIntegrityCheck.rebuildName(this.sellNameTransactionData.getName(), this.repository);
}
@Override
public void process() throws DataException {
// Sell Name
// Sell the name
Name name = new Name(this.repository, this.sellNameTransactionData.getName());
name.sell(this.sellNameTransactionData);
}
@Override
public void orphan() throws DataException {
// Revert name
// Revert the name sale in case of orphaning
Name name = new Name(this.repository, this.sellNameTransactionData.getName());
name.unsell(this.sellNameTransactionData);
}
}