3
0
mirror of https://github.com/Qortal/qortal.git synced 2025-02-11 17:55:50 +00:00

get admin query fix and hardfork

This commit is contained in:
kennycud 2025-01-17 19:31:13 -08:00
parent b2dbcbb603
commit 72f0194487
7 changed files with 57 additions and 6 deletions

View File

@ -91,7 +91,8 @@ public class BlockChain {
fixBatchRewardHeight, fixBatchRewardHeight,
adminsReplaceFoundersHeight, adminsReplaceFoundersHeight,
nullGroupMembershipHeight, nullGroupMembershipHeight,
ignoreLevelForRewardShareHeight ignoreLevelForRewardShareHeight,
adminQueryFixHeight
} }
// Custom transaction fees // Custom transaction fees
@ -677,6 +678,10 @@ public class BlockChain {
return this.featureTriggers.get(FeatureTrigger.ignoreLevelForRewardShareHeight.name()).intValue(); return this.featureTriggers.get(FeatureTrigger.ignoreLevelForRewardShareHeight.name()).intValue();
} }
public int getAdminQueryFixHeight() {
return this.featureTriggers.get(FeatureTrigger.adminQueryFixHeight.name()).intValue();
}
// More complex getters for aspects that change by height or timestamp // More complex getters for aspects that change by height or timestamp
public long getRewardAtHeight(int ourHeight) { public long getRewardAtHeight(int ourHeight) {

View File

@ -2,6 +2,7 @@ package org.qortal.group;
import org.qortal.account.Account; import org.qortal.account.Account;
import org.qortal.account.PublicKeyAccount; import org.qortal.account.PublicKeyAccount;
import org.qortal.block.BlockChain;
import org.qortal.controller.Controller; import org.qortal.controller.Controller;
import org.qortal.crypto.Crypto; import org.qortal.crypto.Crypto;
import org.qortal.data.group.*; import org.qortal.data.group.*;
@ -150,7 +151,12 @@ public class Group {
// Adminship // Adminship
private GroupAdminData getAdmin(String admin) throws DataException { private GroupAdminData getAdmin(String admin) throws DataException {
return groupRepository.getAdmin(this.groupData.getGroupId(), admin); if( repository.getBlockRepository().getBlockchainHeight() < BlockChain.getInstance().getAdminQueryFixHeight()) {
return groupRepository.getAdminFaulty(this.groupData.getGroupId(), admin);
}
else {
return groupRepository.getAdmin(this.groupData.getGroupId(), admin);
}
} }
private boolean adminExists(String admin) throws DataException { private boolean adminExists(String admin) throws DataException {

View File

@ -48,6 +48,8 @@ public interface GroupRepository {
// Group Admins // Group Admins
public GroupAdminData getAdminFaulty(int groupId, String address) throws DataException;
public GroupAdminData getAdmin(int groupId, String address) throws DataException; public GroupAdminData getAdmin(int groupId, String address) throws DataException;
public boolean adminExists(int groupId, String address) throws DataException; public boolean adminExists(int groupId, String address) throws DataException;

View File

@ -351,7 +351,7 @@ public class HSQLDBGroupRepository implements GroupRepository {
// Group Admins // Group Admins
@Override @Override
public GroupAdminData getAdmin(int groupId, String address) throws DataException { public GroupAdminData getAdminFaulty(int groupId, String address) throws DataException {
try (ResultSet resultSet = this.repository.checkedExecute("SELECT admin, reference FROM GroupAdmins WHERE group_id = ?", groupId)) { try (ResultSet resultSet = this.repository.checkedExecute("SELECT admin, reference FROM GroupAdmins WHERE group_id = ?", groupId)) {
if (resultSet == null) if (resultSet == null)
return null; return null;
@ -365,6 +365,21 @@ public class HSQLDBGroupRepository implements GroupRepository {
} }
} }
@Override
public GroupAdminData getAdmin(int groupId, String address) throws DataException {
try (ResultSet resultSet = this.repository.checkedExecute("SELECT admin, reference FROM GroupAdmins WHERE group_id = ? AND admin = ?", groupId, address)) {
if (resultSet == null)
return null;
String admin = resultSet.getString(1);
byte[] reference = resultSet.getBytes(2);
return new GroupAdminData(groupId, admin, reference);
} catch (SQLException e) {
throw new DataException("Unable to fetch group admin from repository", e);
}
}
@Override @Override
public boolean adminExists(int groupId, String address) throws DataException { public boolean adminExists(int groupId, String address) throws DataException {
try { try {

View File

@ -116,7 +116,8 @@
"fixBatchRewardHeight": 1945900, "fixBatchRewardHeight": 1945900,
"adminsReplaceFoundersHeight": 9999999, "adminsReplaceFoundersHeight": 9999999,
"nullGroupMembershipHeight": 9999999, "nullGroupMembershipHeight": 9999999,
"ignoreLevelForRewardShareHeight": 9999999 "ignoreLevelForRewardShareHeight": 9999999,
"adminQueryFixHeight": 9999999
}, },
"checkpoints": [ "checkpoints": [
{ "height": 1136300, "signature": "3BbwawEF2uN8Ni5ofpJXkukoU8ctAPxYoFB7whq9pKfBnjfZcpfEJT4R95NvBDoTP8WDyWvsUvbfHbcr9qSZuYpSKZjUQTvdFf6eqznHGEwhZApWfvXu6zjGCxYCp65F4jsVYYJjkzbjmkCg5WAwN5voudngA23kMK6PpTNygapCzXt" } { "height": 1136300, "signature": "3BbwawEF2uN8Ni5ofpJXkukoU8ctAPxYoFB7whq9pKfBnjfZcpfEJT4R95NvBDoTP8WDyWvsUvbfHbcr9qSZuYpSKZjUQTvdFf6eqznHGEwhZApWfvXu6zjGCxYCp65F4jsVYYJjkzbjmkCg5WAwN5voudngA23kMK6PpTNygapCzXt" }

View File

@ -6,6 +6,7 @@ import org.junit.Test;
import org.qortal.account.PrivateKeyAccount; import org.qortal.account.PrivateKeyAccount;
import org.qortal.block.Block; import org.qortal.block.Block;
import org.qortal.block.BlockChain; import org.qortal.block.BlockChain;
import org.qortal.data.group.GroupAdminData;
import org.qortal.data.transaction.*; import org.qortal.data.transaction.*;
import org.qortal.group.Group; import org.qortal.group.Group;
import org.qortal.repository.DataException; import org.qortal.repository.DataException;
@ -567,6 +568,26 @@ public class DevGroupAdminTests extends Common {
} }
} }
@Test
public void testGetAdmin() throws DataException{
try (final Repository repository = RepositoryManager.getRepository()) {
// establish accounts
PrivateKeyAccount alice = Common.getTestAccount(repository, ALICE);
PrivateKeyAccount bob = Common.getTestAccount(repository, BOB);
GroupAdminData aliceAdminData = repository.getGroupRepository().getAdmin(DEV_GROUP_ID, alice.getAddress());
assertNotNull(aliceAdminData);
assertEquals( alice.getAddress(), aliceAdminData.getAdmin() );
assertEquals( DEV_GROUP_ID, aliceAdminData.getGroupId());
GroupAdminData bobAdminData = repository.getGroupRepository().getAdmin(DEV_GROUP_ID, bob.getAddress());
assertNull(bobAdminData);
}
}
private Transaction.ApprovalStatus signForGroupApproval(Repository repository, TransactionData data, List<PrivateKeyAccount> signers) throws DataException { private Transaction.ApprovalStatus signForGroupApproval(Repository repository, TransactionData data, List<PrivateKeyAccount> signers) throws DataException {
for (PrivateKeyAccount signer : signers) { for (PrivateKeyAccount signer : signers) {

View File

@ -106,8 +106,9 @@
"removeOnlyMintWithNameHeight": 9999999999999, "removeOnlyMintWithNameHeight": 9999999999999,
"fixBatchRewardHeight": 9999999999999, "fixBatchRewardHeight": 9999999999999,
"adminsReplaceFoundersHeight": 9999999999999, "adminsReplaceFoundersHeight": 9999999999999,
"onlineValidationFailSafeHeight": 9999999999999, "ignoreLevelForRewardShareHeight": 9999999999999,
"nullGroupMembershipHeight": 20 "nullGroupMembershipHeight": 20,
"adminQueryFixHeight": 9999999999999
}, },
"genesisInfo": { "genesisInfo": {
"version": 4, "version": 4,