mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-26 23:44:34 +00:00
Increase asset "data" size and make description/data optional in UPDATE_ASSET
Bumped Asset data size from 4K to 400K
This commit is contained in:
parent
1b3fa5c806
commit
76277ae9c3
@ -74,8 +74,12 @@ public class Asset {
|
|||||||
|
|
||||||
// Update asset's owner, description and data
|
// Update asset's owner, description and data
|
||||||
this.assetData.setOwner(updateAssetTransactionData.getNewOwner());
|
this.assetData.setOwner(updateAssetTransactionData.getNewOwner());
|
||||||
this.assetData.setDescription(updateAssetTransactionData.getNewDescription());
|
|
||||||
this.assetData.setData(updateAssetTransactionData.getNewData());
|
if (!updateAssetTransactionData.getNewDescription().isEmpty())
|
||||||
|
this.assetData.setDescription(updateAssetTransactionData.getNewDescription());
|
||||||
|
|
||||||
|
if (!updateAssetTransactionData.getNewData().isEmpty())
|
||||||
|
this.assetData.setData(updateAssetTransactionData.getNewData());
|
||||||
|
|
||||||
// Save updated asset
|
// Save updated asset
|
||||||
this.repository.getAssetRepository().save(this.assetData);
|
this.repository.getAssetRepository().save(this.assetData);
|
||||||
@ -85,33 +89,70 @@ public class Asset {
|
|||||||
// Previous asset reference is taken from this transaction's cached copy
|
// Previous asset reference is taken from this transaction's cached copy
|
||||||
this.assetData.setReference(updateAssetTransactionData.getOrphanReference());
|
this.assetData.setReference(updateAssetTransactionData.getOrphanReference());
|
||||||
|
|
||||||
// Previous owner, description and/or data taken from referenced transaction
|
/*
|
||||||
TransactionData previousTransactionData = this.repository.getTransactionRepository()
|
* It's possible the previous transaction might be an UPDATE_ASSET that didn't change
|
||||||
.fromSignature(this.assetData.getReference());
|
* description/data fields and so we have to keep going back until we find an actual value,
|
||||||
|
* even to the original ISSUE_ASSET transaction if necessary.
|
||||||
|
*
|
||||||
|
* So we need to keep track of whether we still need
|
||||||
|
* a previous description and/or data so we can stop looking.
|
||||||
|
*/
|
||||||
|
boolean needDescription = updateAssetTransactionData.getNewDescription() != null;
|
||||||
|
boolean needData = updateAssetTransactionData.getNewData() != null;
|
||||||
|
|
||||||
if (previousTransactionData == null)
|
byte[] previousTransactionSignature = this.assetData.getReference();
|
||||||
throw new IllegalStateException("Missing referenced transaction when orphaning UPDATE_ASSET");
|
|
||||||
|
|
||||||
switch (previousTransactionData.getType()) {
|
// There's always at least one round to potentially revert owner
|
||||||
case ISSUE_ASSET:
|
do {
|
||||||
IssueAssetTransactionData previousIssueAssetTransactionData = (IssueAssetTransactionData) previousTransactionData;
|
// Previous owner, description and/or data taken from referenced transaction
|
||||||
|
TransactionData previousTransactionData = this.repository.getTransactionRepository()
|
||||||
|
.fromSignature(previousTransactionSignature);
|
||||||
|
|
||||||
this.assetData.setOwner(previousIssueAssetTransactionData.getOwner());
|
if (previousTransactionData == null)
|
||||||
this.assetData.setDescription(previousIssueAssetTransactionData.getDescription());
|
throw new IllegalStateException("Missing referenced transaction when orphaning UPDATE_ASSET");
|
||||||
this.assetData.setData(previousIssueAssetTransactionData.getData());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UPDATE_ASSET:
|
switch (previousTransactionData.getType()) {
|
||||||
UpdateAssetTransactionData previousUpdateAssetTransactionData = (UpdateAssetTransactionData) previousTransactionData;
|
case ISSUE_ASSET:
|
||||||
|
IssueAssetTransactionData previousIssueAssetTransactionData = (IssueAssetTransactionData) previousTransactionData;
|
||||||
|
|
||||||
this.assetData.setOwner(previousUpdateAssetTransactionData.getNewOwner());
|
this.assetData.setOwner(previousIssueAssetTransactionData.getOwner());
|
||||||
this.assetData.setDescription(previousUpdateAssetTransactionData.getNewDescription());
|
|
||||||
this.assetData.setData(previousUpdateAssetTransactionData.getNewData());
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
if (needDescription) {
|
||||||
throw new IllegalStateException("Invalid referenced transaction when orphaning UPDATE_ASSET");
|
this.assetData.setDescription(previousIssueAssetTransactionData.getDescription());
|
||||||
}
|
needDescription = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needData) {
|
||||||
|
this.assetData.setData(previousIssueAssetTransactionData.getData());
|
||||||
|
needData = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UPDATE_ASSET:
|
||||||
|
UpdateAssetTransactionData previousUpdateAssetTransactionData = (UpdateAssetTransactionData) previousTransactionData;
|
||||||
|
|
||||||
|
this.assetData.setOwner(previousUpdateAssetTransactionData.getNewOwner());
|
||||||
|
|
||||||
|
if (needDescription && !previousUpdateAssetTransactionData.getNewDescription().isEmpty()) {
|
||||||
|
this.assetData.setDescription(previousUpdateAssetTransactionData.getNewDescription());
|
||||||
|
needDescription = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needData && !previousUpdateAssetTransactionData.getNewData().isEmpty()) {
|
||||||
|
this.assetData.setData(previousUpdateAssetTransactionData.getNewData());
|
||||||
|
needData = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get signature for previous transaction in chain, just in case we need it
|
||||||
|
if (needDescription || needData)
|
||||||
|
previousTransactionSignature = previousUpdateAssetTransactionData.getOrphanReference();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Invalid referenced transaction when orphaning UPDATE_ASSET");
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (needDescription || needData);
|
||||||
|
|
||||||
// Save reverted asset
|
// Save reverted asset
|
||||||
this.repository.getAssetRepository().save(this.assetData);
|
this.repository.getAssetRepository().save(this.assetData);
|
||||||
|
@ -622,6 +622,14 @@ public class HSQLDBDatabaseUpdates {
|
|||||||
stmt.execute("ALTER TABLE GroupBanTransactions ADD previous_group_id INTEGER");
|
stmt.execute("ALTER TABLE GroupBanTransactions ADD previous_group_id INTEGER");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 40:
|
||||||
|
// Increase asset "data" size from 4K to 400K
|
||||||
|
stmt.execute("CREATE TYPE AssetDataLob AS CLOB(400K)");
|
||||||
|
stmt.execute("ALTER TABLE Assets ALTER COLUMN data AssetDataLob");
|
||||||
|
stmt.execute("ALTER TABLE IssueAssetTransactions ALTER COLUMN data AssetDataLob");
|
||||||
|
stmt.execute("ALTER TABLE UpdateAssetTransactions ALTER COLUMN new_data AssetDataLob");
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// nothing to do
|
// nothing to do
|
||||||
return false;
|
return false;
|
||||||
|
@ -94,14 +94,14 @@ public class UpdateAssetTransaction extends Transaction {
|
|||||||
if (!Crypto.isValidAddress(updateAssetTransactionData.getNewOwner()))
|
if (!Crypto.isValidAddress(updateAssetTransactionData.getNewOwner()))
|
||||||
return ValidationResult.INVALID_ADDRESS;
|
return ValidationResult.INVALID_ADDRESS;
|
||||||
|
|
||||||
// Check new description size bounds
|
// Check new description size bounds. Note: zero length means DO NOT CHANGE description
|
||||||
int newDescriptionLength = Utf8.encodedLength(updateAssetTransactionData.getNewDescription());
|
int newDescriptionLength = Utf8.encodedLength(updateAssetTransactionData.getNewDescription());
|
||||||
if (newDescriptionLength < 1 || newDescriptionLength > Asset.MAX_DESCRIPTION_SIZE)
|
if (newDescriptionLength > Asset.MAX_DESCRIPTION_SIZE)
|
||||||
return ValidationResult.INVALID_DATA_LENGTH;
|
return ValidationResult.INVALID_DATA_LENGTH;
|
||||||
|
|
||||||
// Check new data size bounds
|
// Check new data size bounds. Note: zero length means DO NOT CHANGE data
|
||||||
int newDataLength = Utf8.encodedLength(updateAssetTransactionData.getNewData());
|
int newDataLength = Utf8.encodedLength(updateAssetTransactionData.getNewData());
|
||||||
if (newDataLength < 1 || newDataLength > Asset.MAX_DATA_SIZE)
|
if (newDataLength > Asset.MAX_DATA_SIZE)
|
||||||
return ValidationResult.INVALID_DATA_LENGTH;
|
return ValidationResult.INVALID_DATA_LENGTH;
|
||||||
|
|
||||||
// As this transaction type could require approval, check txGroupId
|
// As this transaction type could require approval, check txGroupId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user