forked from Qortal/qortal
Updare canMint and HSQLDB
This commit is contained in:
parent
8319193453
commit
46395bf4dc
2
pom.xml
2
pom.xml
@ -26,7 +26,7 @@
|
|||||||
<guava.version>33.3.1-jre</guava.version>
|
<guava.version>33.3.1-jre</guava.version>
|
||||||
<hamcrest-library.version>2.2</hamcrest-library.version>
|
<hamcrest-library.version>2.2</hamcrest-library.version>
|
||||||
<homoglyph.version>1.2.1</homoglyph.version>
|
<homoglyph.version>1.2.1</homoglyph.version>
|
||||||
<hsqldb.version>2.5.1</hsqldb.version>
|
<hsqldb.version>2.7.4</hsqldb.version>
|
||||||
<icu4j.version>76.1</icu4j.version>
|
<icu4j.version>76.1</icu4j.version>
|
||||||
<java-diff-utils.version>4.12</java-diff-utils.version>
|
<java-diff-utils.version>4.12</java-diff-utils.version>
|
||||||
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
|
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
|
||||||
|
@ -198,11 +198,11 @@ public class Account {
|
|||||||
|
|
||||||
/** Returns whether account can be considered a "minting account".
|
/** Returns whether account can be considered a "minting account".
|
||||||
* <p>
|
* <p>
|
||||||
* To be considered a "minting account", the account needs to pass all of these tests:<br>
|
* To be considered a "minting account", the account needs to pass some of these tests:<br>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>account's level is at least <tt>minAccountLevelToMint</tt> from blockchain config</li>
|
* <li>account's level is at least <tt>minAccountLevelToMint</tt> from blockchain config</li>
|
||||||
* <li>account's address have registered a name</li>
|
* <li>account's address has registered a name</li>
|
||||||
* <li>account's address is member of minter group</li>
|
* <li>account's address is a member of the minter group</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @return true if account can be considered "minting account"
|
* @return true if account can be considered "minting account"
|
||||||
@ -212,64 +212,61 @@ public class Account {
|
|||||||
AccountData accountData = this.repository.getAccountRepository().getAccount(this.address);
|
AccountData accountData = this.repository.getAccountRepository().getAccount(this.address);
|
||||||
NameRepository nameRepository = this.repository.getNameRepository();
|
NameRepository nameRepository = this.repository.getNameRepository();
|
||||||
GroupRepository groupRepository = this.repository.getGroupRepository();
|
GroupRepository groupRepository = this.repository.getGroupRepository();
|
||||||
|
String myAddress = accountData.getAddress();
|
||||||
|
|
||||||
int blockchainHeight = this.repository.getBlockRepository().getBlockchainHeight();
|
int blockchainHeight = this.repository.getBlockRepository().getBlockchainHeight();
|
||||||
int nameCheckHeight = BlockChain.getInstance().getOnlyMintWithNameHeight();
|
|
||||||
int levelToMint = BlockChain.getInstance().getMinAccountLevelToMint();
|
int levelToMint = BlockChain.getInstance().getMinAccountLevelToMint();
|
||||||
int level = accountData.getLevel();
|
int level = accountData.getLevel();
|
||||||
int groupIdToMint = BlockChain.getInstance().getMintingGroupId();
|
int groupIdToMint = BlockChain.getInstance().getMintingGroupId();
|
||||||
|
int nameCheckHeight = BlockChain.getInstance().getOnlyMintWithNameHeight();
|
||||||
int groupCheckHeight = BlockChain.getInstance().getGroupMemberCheckHeight();
|
int groupCheckHeight = BlockChain.getInstance().getGroupMemberCheckHeight();
|
||||||
int removeNameCheckHeight = BlockChain.getInstance().getRemoveOnlyMintWithNameHeight();
|
int removeNameCheckHeight = BlockChain.getInstance().getRemoveOnlyMintWithNameHeight();
|
||||||
|
|
||||||
String myAddress = accountData.getAddress();
|
// Can only mint if:
|
||||||
|
// Account's level is at least minAccountLevelToMint from blockchain config
|
||||||
|
if (blockchainHeight < nameCheckHeight) {
|
||||||
|
if (Account.isFounder(accountData.getFlags())) {
|
||||||
|
return accountData.getBlocksMintedPenalty() == 0;
|
||||||
|
} else {
|
||||||
|
return level >= levelToMint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Can only mint on onlyMintWithNameHeight from blockchain config if:
|
||||||
|
// Account's level is at least minAccountLevelToMint from blockchain config
|
||||||
|
// Account's address has registered a name
|
||||||
|
if (blockchainHeight >= nameCheckHeight && blockchainHeight < groupCheckHeight) {
|
||||||
List<NameData> myName = nameRepository.getNamesByOwner(myAddress);
|
List<NameData> myName = nameRepository.getNamesByOwner(myAddress);
|
||||||
boolean isMember = groupRepository.memberExists(groupIdToMint, myAddress);
|
if (Account.isFounder(accountData.getFlags())) {
|
||||||
|
return accountData.getBlocksMintedPenalty() == 0 && !myName.isEmpty();
|
||||||
|
} else {
|
||||||
|
return level >= levelToMint && !myName.isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (accountData == null)
|
// Can only mint on groupMemberCheckHeight from blockchain config if:
|
||||||
return false;
|
// Account's level is at least minAccountLevelToMint from blockchain config
|
||||||
|
// Account's address has registered a name
|
||||||
|
// Account's address is a member of the minter group
|
||||||
|
if (blockchainHeight >= groupCheckHeight && blockchainHeight < removeNameCheckHeight) {
|
||||||
|
List<NameData> myName = nameRepository.getNamesByOwner(myAddress);
|
||||||
|
if (Account.isFounder(accountData.getFlags())) {
|
||||||
|
return accountData.getBlocksMintedPenalty() == 0 && !myName.isEmpty() && groupRepository.memberExists(groupIdToMint, myAddress);
|
||||||
|
} else {
|
||||||
|
return level >= levelToMint && !myName.isEmpty() && groupRepository.memberExists(groupIdToMint, myAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Can only mint if level is at least minAccountLevelToMint< from blockchain config
|
// Can only mint on removeOnlyMintWithNameHeight from blockchain config if:
|
||||||
if (blockchainHeight < nameCheckHeight && level >= levelToMint)
|
// Account's level is at least minAccountLevelToMint from blockchain config
|
||||||
return true;
|
// Account's address is a member of the minter group
|
||||||
|
if (blockchainHeight >= removeNameCheckHeight) {
|
||||||
// Can only mint if have registered a name
|
if (Account.isFounder(accountData.getFlags())) {
|
||||||
if (blockchainHeight >= nameCheckHeight && blockchainHeight < groupCheckHeight && level >= levelToMint && !myName.isEmpty())
|
return accountData.getBlocksMintedPenalty() == 0 && groupRepository.memberExists(groupIdToMint, myAddress);
|
||||||
return true;
|
} else {
|
||||||
|
return level >= levelToMint && groupRepository.memberExists(groupIdToMint, myAddress);
|
||||||
// Can only mint if have registered a name and is member of minter group id
|
}
|
||||||
if (blockchainHeight >= groupCheckHeight && blockchainHeight < removeNameCheckHeight && level >= levelToMint && !myName.isEmpty() && isMember)
|
}
|
||||||
return true;
|
|
||||||
|
|
||||||
// Can only mint if is member of minter group id
|
|
||||||
if (blockchainHeight >= removeNameCheckHeight && level >= levelToMint && isMember)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Founders needs to pass same tests like minters
|
|
||||||
if (blockchainHeight < nameCheckHeight &&
|
|
||||||
Account.isFounder(accountData.getFlags()) &&
|
|
||||||
accountData.getBlocksMintedPenalty() == 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (blockchainHeight >= nameCheckHeight &&
|
|
||||||
blockchainHeight < groupCheckHeight &&
|
|
||||||
Account.isFounder(accountData.getFlags()) &&
|
|
||||||
accountData.getBlocksMintedPenalty() == 0 &&
|
|
||||||
!myName.isEmpty())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (blockchainHeight >= groupCheckHeight &&
|
|
||||||
blockchainHeight < removeNameCheckHeight &&
|
|
||||||
Account.isFounder(accountData.getFlags()) &&
|
|
||||||
accountData.getBlocksMintedPenalty() == 0 &&
|
|
||||||
!myName.isEmpty() &&
|
|
||||||
isMember)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (blockchainHeight >= removeNameCheckHeight &&
|
|
||||||
Account.isFounder(accountData.getFlags()) &&
|
|
||||||
accountData.getBlocksMintedPenalty() == 0 &&
|
|
||||||
isMember)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -284,7 +281,6 @@ public class Account {
|
|||||||
return this.repository.getAccountRepository().getBlocksMintedPenaltyCount(this.address);
|
return this.repository.getAccountRepository().getBlocksMintedPenaltyCount(this.address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Returns whether account can build reward-shares.
|
/** Returns whether account can build reward-shares.
|
||||||
* <p>
|
* <p>
|
||||||
* To be able to create reward-shares, the account needs to pass at least one of these tests:<br>
|
* To be able to create reward-shares, the account needs to pass at least one of these tests:<br>
|
||||||
@ -298,6 +294,7 @@ public class Account {
|
|||||||
*/
|
*/
|
||||||
public boolean canRewardShare() throws DataException {
|
public boolean canRewardShare() throws DataException {
|
||||||
AccountData accountData = this.repository.getAccountRepository().getAccount(this.address);
|
AccountData accountData = this.repository.getAccountRepository().getAccount(this.address);
|
||||||
|
|
||||||
if (accountData == null)
|
if (accountData == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -367,6 +364,7 @@ public class Account {
|
|||||||
Account rewardShareMinter = new Account(repository, rewardShareData.getMinter());
|
Account rewardShareMinter = new Account(repository, rewardShareData.getMinter());
|
||||||
return rewardShareMinter.getEffectiveMintingLevel();
|
return rewardShareMinter.getEffectiveMintingLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns 'effective' minting level, with a fix for the zero level.
|
* Returns 'effective' minting level, with a fix for the zero level.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -454,40 +454,41 @@ public class HSQLDBDatabaseUpdates {
|
|||||||
|
|
||||||
case 12:
|
case 12:
|
||||||
// Groups
|
// Groups
|
||||||
stmt.execute("CREATE TABLE Groups (group_id GroupID, owner QortalAddress NOT NULL, group_name GroupName NOT NULL, "
|
// NOTE: We need to set Groups to `Groups` here to avoid SQL Standard Keywords in HSQLDB v2.7.4
|
||||||
|
stmt.execute("CREATE TABLE `Groups` (group_id GroupID, owner QortalAddress NOT NULL, group_name GroupName NOT NULL, "
|
||||||
+ "created_when EpochMillis NOT NULL, updated_when EpochMillis, is_open BOOLEAN NOT NULL, "
|
+ "created_when EpochMillis NOT NULL, updated_when EpochMillis, is_open BOOLEAN NOT NULL, "
|
||||||
+ "approval_threshold TINYINT NOT NULL, min_block_delay INTEGER NOT NULL, max_block_delay INTEGER NOT NULL, "
|
+ "approval_threshold TINYINT NOT NULL, min_block_delay INTEGER NOT NULL, max_block_delay INTEGER NOT NULL, "
|
||||||
+ "reference Signature, creation_group_id GroupID, reduced_group_name GroupName NOT NULL, "
|
+ "reference Signature, creation_group_id GroupID, reduced_group_name GroupName NOT NULL, "
|
||||||
+ "description GenericDescription NOT NULL, PRIMARY KEY (group_id))");
|
+ "description GenericDescription NOT NULL, PRIMARY KEY (group_id))");
|
||||||
// For finding groups by name
|
// For finding groups by name
|
||||||
stmt.execute("CREATE INDEX GroupNameIndex on Groups (group_name)");
|
stmt.execute("CREATE INDEX GroupNameIndex on `Groups` (group_name)");
|
||||||
// For finding groups by reduced name
|
// For finding groups by reduced name
|
||||||
stmt.execute("CREATE INDEX GroupReducedNameIndex on Groups (reduced_group_name)");
|
stmt.execute("CREATE INDEX GroupReducedNameIndex on `Groups` (reduced_group_name)");
|
||||||
// For finding groups by owner
|
// For finding groups by owner
|
||||||
stmt.execute("CREATE INDEX GroupOwnerIndex ON Groups (owner)");
|
stmt.execute("CREATE INDEX GroupOwnerIndex ON `Groups` (owner)");
|
||||||
|
|
||||||
// We need a corresponding trigger to make sure new group_id values are assigned sequentially starting from 1
|
// We need a corresponding trigger to make sure new group_id values are assigned sequentially starting from 1
|
||||||
stmt.execute("CREATE TRIGGER Group_ID_Trigger BEFORE INSERT ON Groups "
|
stmt.execute("CREATE TRIGGER Group_ID_Trigger BEFORE INSERT ON `Groups` "
|
||||||
+ "REFERENCING NEW ROW AS new_row FOR EACH ROW WHEN (new_row.group_id IS NULL) "
|
+ "REFERENCING NEW ROW AS new_row FOR EACH ROW WHEN (new_row.group_id IS NULL) "
|
||||||
+ "SET new_row.group_id = (SELECT IFNULL(MAX(group_id) + 1, 1) FROM Groups)");
|
+ "SET new_row.group_id = (SELECT IFNULL(MAX(group_id) + 1, 1) FROM `Groups`)");
|
||||||
|
|
||||||
// Admins
|
// Admins
|
||||||
stmt.execute("CREATE TABLE GroupAdmins (group_id GroupID, admin QortalAddress, reference Signature NOT NULL, "
|
stmt.execute("CREATE TABLE GroupAdmins (group_id GroupID, admin QortalAddress, reference Signature NOT NULL, "
|
||||||
+ "PRIMARY KEY (group_id, admin), FOREIGN KEY (group_id) REFERENCES Groups (group_id) ON DELETE CASCADE)");
|
+ "PRIMARY KEY (group_id, admin), FOREIGN KEY (group_id) REFERENCES `Groups` (group_id) ON DELETE CASCADE)");
|
||||||
// For finding groups by admin address
|
// For finding groups by admin address
|
||||||
stmt.execute("CREATE INDEX GroupAdminIndex ON GroupAdmins (admin)");
|
stmt.execute("CREATE INDEX GroupAdminIndex ON GroupAdmins (admin)");
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
stmt.execute("CREATE TABLE GroupMembers (group_id GroupID, address QortalAddress, "
|
stmt.execute("CREATE TABLE GroupMembers (group_id GroupID, address QortalAddress, "
|
||||||
+ "joined_when EpochMillis NOT NULL, reference Signature NOT NULL, "
|
+ "joined_when EpochMillis NOT NULL, reference Signature NOT NULL, "
|
||||||
+ "PRIMARY KEY (group_id, address), FOREIGN KEY (group_id) REFERENCES Groups (group_id) ON DELETE CASCADE)");
|
+ "PRIMARY KEY (group_id, address), FOREIGN KEY (group_id) REFERENCES `Groups` (group_id) ON DELETE CASCADE)");
|
||||||
// For finding groups by member address
|
// For finding groups by member address
|
||||||
stmt.execute("CREATE INDEX GroupMemberIndex ON GroupMembers (address)");
|
stmt.execute("CREATE INDEX GroupMemberIndex ON GroupMembers (address)");
|
||||||
|
|
||||||
// Invites
|
// Invites
|
||||||
stmt.execute("CREATE TABLE GroupInvites (group_id GroupID, inviter QortalAddress, invitee QortalAddress, "
|
stmt.execute("CREATE TABLE GroupInvites (group_id GroupID, inviter QortalAddress, invitee QortalAddress, "
|
||||||
+ "expires_when EpochMillis, reference Signature, "
|
+ "expires_when EpochMillis, reference Signature, "
|
||||||
+ "PRIMARY KEY (group_id, invitee), FOREIGN KEY (group_id) REFERENCES Groups (group_id) ON DELETE CASCADE)");
|
+ "PRIMARY KEY (group_id, invitee), FOREIGN KEY (group_id) REFERENCES `Groups` (group_id) ON DELETE CASCADE)");
|
||||||
// For finding invites sent by inviter
|
// For finding invites sent by inviter
|
||||||
stmt.execute("CREATE INDEX GroupInviteInviterIndex ON GroupInvites (inviter)");
|
stmt.execute("CREATE INDEX GroupInviteInviterIndex ON GroupInvites (inviter)");
|
||||||
// For finding invites by group
|
// For finding invites by group
|
||||||
@ -503,7 +504,7 @@ public class HSQLDBDatabaseUpdates {
|
|||||||
// NULL expires_when means does not expire!
|
// NULL expires_when means does not expire!
|
||||||
stmt.execute("CREATE TABLE GroupBans (group_id GroupID, offender QortalAddress, admin QortalAddress NOT NULL, "
|
stmt.execute("CREATE TABLE GroupBans (group_id GroupID, offender QortalAddress, admin QortalAddress NOT NULL, "
|
||||||
+ "banned_when EpochMillis NOT NULL, reason GenericDescription NOT NULL, expires_when EpochMillis, reference Signature NOT NULL, "
|
+ "banned_when EpochMillis NOT NULL, reason GenericDescription NOT NULL, expires_when EpochMillis, reference Signature NOT NULL, "
|
||||||
+ "PRIMARY KEY (group_id, offender), FOREIGN KEY (group_id) REFERENCES Groups (group_id) ON DELETE CASCADE)");
|
+ "PRIMARY KEY (group_id, offender), FOREIGN KEY (group_id) REFERENCES `Groups` (group_id) ON DELETE CASCADE)");
|
||||||
// For expiry maintenance
|
// For expiry maintenance
|
||||||
stmt.execute("CREATE INDEX GroupBanExpiryIndex ON GroupBans (expires_when)");
|
stmt.execute("CREATE INDEX GroupBanExpiryIndex ON GroupBans (expires_when)");
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user