Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add private name sales to consensus #183

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/main/java/org/qortal/data/naming/NameData.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class NameData {
@XmlJavaTypeAdapter(value = org.qortal.api.AmountTypeAdapter.class)
private Long salePrice;

private boolean isPrivateSale;

private String saleRecipient; // Not always present

// For internal use - no need to expose this via API
@XmlTransient
@Schema(hidden = true)
Expand All @@ -49,6 +53,7 @@ protected NameData() {
// Typically used when fetching from repository
public NameData(String name, String reducedName, String owner, String data, long registered,
Long updated, boolean isForSale, Long salePrice,
boolean isPrivateSale, String saleRecipient,
byte[] reference, int creationGroupId) {
this.name = name;
this.reducedName = reducedName;
Expand All @@ -59,12 +64,14 @@ public NameData(String name, String reducedName, String owner, String data, long
this.reference = reference;
this.isForSale = isForSale;
this.salePrice = salePrice;
this.isPrivateSale = isPrivateSale;
this.saleRecipient = saleRecipient;
this.creationGroupId = creationGroupId;
}

// Typically used when registering a new name
public NameData(String name, String reducedName, String owner, String data, long registered, byte[] reference, int creationGroupId) {
this(name, reducedName, owner, data, registered, null, false, null, reference, creationGroupId);
this(name, reducedName, owner, data, registered, null, false, null, false, null, reference, creationGroupId);
}

// Getters / setters
Expand Down Expand Up @@ -129,6 +136,22 @@ public void setSalePrice(Long salePrice) {
this.salePrice = salePrice;
}

public boolean getIsPrivateSale() {
return this.isPrivateSale;
}

public void setIsPrivateSale(boolean isPrivateSale) {
this.isPrivateSale = isPrivateSale;
}

public String getSaleRecipient() {
return this.saleRecipient;
}

public void setSaleRecipient(String saleRecipient) {
this.saleRecipient = saleRecipient;
}

public byte[] getReference() {
return this.reference;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class BuyNameTransactionData extends TransactionData {
// For internal use when orphaning
@XmlTransient
@Schema(hidden = true)
private boolean isPrivateSale;
@XmlTransient
@Schema(hidden = true)
private byte[] nameReference;

// Constructors
Expand All @@ -47,19 +50,23 @@ public void afterUnmarshal(Unmarshaller u, Object parent) {

/** From repository */
public BuyNameTransactionData(BaseTransactionData baseTransactionData,
String name, long amount, String seller, byte[] nameReference) {
String name, long amount, String seller, boolean isPrivateSale, byte[] nameReference) {
super(TransactionType.BUY_NAME, baseTransactionData);

this.buyerPublicKey = baseTransactionData.creatorPublicKey;
this.name = name;
this.amount = amount;
this.seller = seller;
this.isPrivateSale = isPrivateSale;
this.nameReference = nameReference;
}

/** From network/API */
public BuyNameTransactionData(BaseTransactionData baseTransactionData, String name, long amount, String seller, boolean isPrivateSale) {
this(baseTransactionData, name, amount, seller, isPrivateSale, null);
}
public BuyNameTransactionData(BaseTransactionData baseTransactionData, String name, long amount, String seller) {
this(baseTransactionData, name, amount, seller, null);
this(baseTransactionData, name, amount, seller, false, null);
}

// Getters / setters
Expand All @@ -80,6 +87,14 @@ public String getSeller() {
return this.seller;
}

public boolean getIsPrivateSale() {
return this.isPrivateSale;
}

public void setIsPrivateSale(boolean isPrivateSale) {
this.isPrivateSale = isPrivateSale;
}

public byte[] getNameReference() {
return this.nameReference;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class CancelSellNameTransactionData extends TransactionData {
@XmlTransient
@Schema(hidden = true)
private Long salePrice;
@XmlTransient
@Schema(hidden = true)
private boolean isPrivateSale;
@XmlTransient
@Schema(hidden = true)
private String saleRecipient;

// Constructors

Expand All @@ -35,17 +41,19 @@ public void afterUnmarshal(Unmarshaller u, Object parent) {
this.creatorPublicKey = this.ownerPublicKey;
}

public CancelSellNameTransactionData(BaseTransactionData baseTransactionData, String name, Long salePrice) {
public CancelSellNameTransactionData(BaseTransactionData baseTransactionData, String name, Long salePrice, boolean isPrivateSale, String saleRecipient) {
super(TransactionType.CANCEL_SELL_NAME, baseTransactionData);

this.ownerPublicKey = baseTransactionData.creatorPublicKey;
this.name = name;
this.salePrice = salePrice;
this.isPrivateSale = isPrivateSale;
this.saleRecipient = saleRecipient;
}

/** From network/API */
public CancelSellNameTransactionData(BaseTransactionData baseTransactionData, String name) {
this(baseTransactionData, name, null);
this(baseTransactionData, name, null, false, null);
}

// Getters / setters
Expand All @@ -66,4 +74,20 @@ public void setSalePrice(Long salePrice) {
this.salePrice = salePrice;
}

public boolean getIsPrivateSale() {
return this.isPrivateSale;
}

public void setIsPrivateSale(boolean isPrivateSale) {
this.isPrivateSale = isPrivateSale;
}

public String getSaleRecipient() {
return this.saleRecipient;
}

public void setSaleRecipient(String saleRecipient) {
this.saleRecipient = saleRecipient;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public class SellNameTransactionData extends TransactionData {
@XmlJavaTypeAdapter(value = org.qortal.api.AmountTypeAdapter.class)
private long amount;

@Schema(description = "if sale is for a specific buyer", example = "true")
private boolean isPrivateSale;

@Schema(description = "intended buyer's address", example = "QgV4s3xnzLhVBEJxcYui4u4q11yhUHsd9v")
private String saleRecipient;

// Constructors

// For JAXB
Expand All @@ -42,6 +48,18 @@ public SellNameTransactionData(BaseTransactionData baseTransactionData, String n
this.ownerPublicKey = baseTransactionData.creatorPublicKey;
this.name = name;
this.amount = amount;
this.isPrivateSale = false;
this.saleRecipient = null;
}

public SellNameTransactionData(BaseTransactionData baseTransactionData, String name, long amount, boolean isPrivateSale, String saleRecipient) {
super(TransactionType.SELL_NAME, baseTransactionData);

this.ownerPublicKey = baseTransactionData.creatorPublicKey;
this.name = name;
this.amount = amount;
this.isPrivateSale = isPrivateSale;
this.saleRecipient = saleRecipient;
}

// Getters / setters
Expand All @@ -58,4 +76,12 @@ public long getAmount() {
return this.amount;
}

public boolean getIsPrivateSale() {
return this.isPrivateSale;
}

public String getSaleRecipient() {
return this.isPrivateSale ? this.saleRecipient : null;
}

}
13 changes: 13 additions & 0 deletions src/main/java/org/qortal/naming/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public void sell(SellNameTransactionData sellNameTransactionData) throws DataExc
// Mark as for-sale and set price
this.nameData.setIsForSale(true);
this.nameData.setSalePrice(sellNameTransactionData.getAmount());
this.nameData.setIsPrivateSale(sellNameTransactionData.getIsPrivateSale());
if (sellNameTransactionData.getIsPrivateSale())
this.nameData.setSaleRecipient(sellNameTransactionData.getSaleRecipient());

// Save sale info into repository
this.repository.getNameRepository().save(this.nameData);
Expand All @@ -171,6 +174,8 @@ public void unsell(SellNameTransactionData sellNameTransactionData) throws DataE
// Mark not for-sale and unset price
this.nameData.setIsForSale(false);
this.nameData.setSalePrice(null);
this.nameData.setIsPrivateSale(false);
this.nameData.setSaleRecipient(null);

// Save no-sale info into repository
this.repository.getNameRepository().save(this.nameData);
Expand All @@ -183,6 +188,8 @@ public void cancelSell(CancelSellNameTransactionData cancelSellNameTransactionDa
// Mark not for-sale
this.nameData.setIsForSale(false);
this.nameData.setSalePrice(null);
this.nameData.setIsPrivateSale(false);
this.nameData.setSaleRecipient(null);

// Save sale info into repository
this.repository.getNameRepository().save(this.nameData);
Expand All @@ -192,6 +199,9 @@ public void uncancelSell(CancelSellNameTransactionData cancelSellNameTransaction
// Mark as for-sale using existing price
this.nameData.setIsForSale(true);
this.nameData.setSalePrice(cancelSellNameTransactionData.getSalePrice());
this.nameData.setIsPrivateSale(cancelSellNameTransactionData.getIsPrivateSale());
if (cancelSellNameTransactionData.getIsPrivateSale())
this.nameData.setSaleRecipient(cancelSellNameTransactionData.getSaleRecipient());

// Save no-sale info into repository
this.repository.getNameRepository().save(this.nameData);
Expand Down Expand Up @@ -234,6 +244,9 @@ public void unbuy(BuyNameTransactionData buyNameTransactionData) throws DataExce
// Mark as for-sale using existing price
this.nameData.setIsForSale(true);
this.nameData.setSalePrice(buyNameTransactionData.getAmount());
this.nameData.setIsPrivateSale(buyNameTransactionData.getIsPrivateSale());
if (buyNameTransactionData.getIsPrivateSale())
this.nameData.setSaleRecipient(Crypto.toAddress(buyNameTransactionData.getCreatorPublicKey()));

// Previous name-changing reference is taken from this transaction's cached copy
this.nameData.setReference(buyNameTransactionData.getNameReference());
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/qortal/network/message/NamesMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public NamesMessage(List<NameData> nameDataList) {
bytes.write(Longs.toByteArray(nameData.getSalePrice()));
}

int isPrivateSale = nameData.getIsPrivateSale() ? 1 : 0;
bytes.write(Ints.toByteArray(isPrivateSale));

if (nameData.getIsPrivateSale()) {
Serialization.serializeAddress(bytes, nameData.getSaleRecipient());
}

bytes.write(nameData.getReference());

bytes.write(Ints.toByteArray(nameData.getCreationGroupId()));
Expand Down Expand Up @@ -112,13 +119,20 @@ public static Message fromByteBuffer(int id, ByteBuffer bytes) throws MessageExc
salePrice = bytes.getLong();
}

boolean isPrivateSale = (bytes.getInt() == 1);

String saleRecipient = null;
if (isPrivateSale) {
saleRecipient = Serialization.deserializeAddress(bytes);
}

byte[] reference = new byte[SIGNATURE_LENGTH];
bytes.get(reference);

int creationGroupId = bytes.getInt();

NameData nameData = new NameData(name, reducedName, owner, data, registered, updated,
isForSale, salePrice, reference, creationGroupId);
isForSale, salePrice, isPrivateSale, saleRecipient, reference, creationGroupId);
nameDataList.add(nameData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,20 @@ private static boolean databaseUpdating(Connection connection, boolean wasPristi
stmt.execute("UPDATE Accounts SET blocks_minted_penalty = -5000000 WHERE blocks_minted_penalty < 0");
break;

case 50:
// For private name sales
stmt.execute("ALTER TABLE Names ADD is_private_sale BOOLEAN NOT NULL DEFAULT FALSE");
stmt.execute("ALTER TABLE Names ADD sale_recipient QortalAddress");

stmt.execute("ALTER TABLE SellNameTransactions ADD is_private_sale BOOLEAN NOT NULL DEFAULT FALSE");
stmt.execute("ALTER TABLE SellNameTransactions ADD sale_recipient QortalAddress");

stmt.execute("ALTER TABLE CancelSellNameTransactions ADD is_private_sale BOOLEAN NOT NULL DEFAULT FALSE");
stmt.execute("ALTER TABLE CancelSellNameTransactions ADD sale_recipient QortalAddress");

stmt.execute("ALTER TABLE BuyNameTransactions ADD is_private_sale BOOLEAN NOT NULL DEFAULT FALSE");
break;

default:
// nothing to do
return false;
Expand Down
Loading
Loading