Skip to content

Commit a154e19

Browse files
committed
index key instead of object
1 parent bfab4b9 commit a154e19

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎src/main/java/org/tron/core/db/api/IndexHelper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private byte[] getKey(Witness w) {
125125
}
126126

127127
private byte[] getKey(Account a) {
128-
return new AccountCapsule(a).getAddress().toByteArray();
128+
return new AccountCapsule(a).createDbKey();
129129
}
130130

131131
private byte[] getKey(AssetIssueContract a) {

‎src/main/java/org/tron/core/db/api/index/AbstractIndex.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public boolean remove(byte[] bytes) {
7070
}
7171

7272
public boolean remove(WrappedByteArray bytes) {
73-
return index.add(bytes);
73+
return index.remove(bytes);
7474
}
7575

7676
public long size() {

‎src/test/java/org/tron/core/db/api/IndexHelperTest.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public void addAndRemoveAccount() {
128128
Account.newBuilder()
129129
.setAddress(ByteString.copyFrom(ByteArray.fromHexString("232323abc")))
130130
.build());
131+
dbManager.getAccountStore().put(accountCapsule.createDbKey(), accountCapsule);
131132
indexHelper.add(accountCapsule.getInstance());
132133
int size = getIndexSizeOfAccount();
133134
Assert.assertEquals("account index add", 2, size);
@@ -152,6 +153,7 @@ public void addAndRemoveBlock() {
152153
.setRawData(raw.newBuilder().setNumber(6).build())
153154
.build())
154155
.build());
156+
dbManager.getBlockStore().put(blockCapsule.getBlockId().getBytes(), blockCapsule);
155157
indexHelper.add(blockCapsule.getInstance());
156158
int size = getIndexSizeOfBlock();
157159
Assert.assertEquals("block index add", 3, size);
@@ -173,6 +175,7 @@ public void addAndRemoveWitness() {
173175
Witness.newBuilder()
174176
.setAddress(ByteString.copyFrom(ByteArray.fromHexString("343434abc")))
175177
.build());
178+
dbManager.getWitnessStore().put(witnessCapsule.createDbKey(), witnessCapsule);
176179
indexHelper.add(witnessCapsule.getInstance());
177180
int size = getIndexSizeOfWitness();
178181
Assert.assertEquals("witness index add", 2, size);
@@ -198,6 +201,7 @@ public void addAndRemoveTransaction() {
198201
.setData(ByteString.copyFrom("i am trans".getBytes()))
199202
.build())
200203
.build());
204+
dbManager.getTransactionStore().put(transactionCapsule.getTransactionId().getBytes(), transactionCapsule);
201205
indexHelper.add(transactionCapsule.getInstance());
202206
int size = getIndexSizeOfTransaction();
203207
Assert.assertEquals("account index add", 1, size);
@@ -220,6 +224,7 @@ public void addAndRemoveAssetIssue() {
220224
.setName(ByteString.copyFrom("assetIssueName".getBytes()))
221225
.setNum(12581)
222226
.build());
227+
dbManager.getAssetIssueStore().put(assetIssueCapsule.getName().toByteArray(), assetIssueCapsule);
223228
indexHelper.add(assetIssueCapsule.getInstance());
224229
int size = getIndexSizeOfAssetIssue();
225230
Assert.assertEquals("account index add", 1, size);
@@ -246,6 +251,7 @@ public void update() {
246251
.setAddress(ByteString.copyFrom("update123".getBytes()))
247252
.setBalance(123)
248253
.build();
254+
dbManager.getAccountStore().put(account1.getAddress().toByteArray(), new AccountCapsule(account1));
249255
indexHelper.update(account1);
250256
ResultSet<Account> resultSet = indexHelper.getAccountIndex()
251257
.retrieve(equal(indexHelper.getAccountIndex().Account_ADDRESS,
@@ -259,6 +265,7 @@ public void update() {
259265
.setAddress(ByteString.copyFrom("update123".getBytes()))
260266
.setBalance(456)
261267
.build();
268+
dbManager.getAccountStore().put(account1.getAddress().toByteArray(), new AccountCapsule(account2));
262269
indexHelper.update(account2);
263270
resultSet = indexHelper.getAccountIndex()
264271
.retrieve(equal(indexHelper.getAccountIndex().Account_ADDRESS,
@@ -272,6 +279,7 @@ public void update() {
272279
.setAddress(ByteString.copyFrom("update123".getBytes()))
273280
.setBalance(789)
274281
.build();
282+
dbManager.getAccountStore().put(account1.getAddress().toByteArray(), new AccountCapsule(account3));
275283
indexHelper.update(account3);
276284
resultSet = indexHelper.getAccountIndex()
277285
.retrieve(equal(indexHelper.getAccountIndex().Account_ADDRESS,

0 commit comments

Comments
 (0)