Skip to content
This repository was archived by the owner on Aug 23, 2020. It is now read-only.

Commit f735e7c

Browse files
Merge pull request #1257 from alon-e/bugfix/firstVM
fix first() calls in view models
2 parents a23d55a + 3ede36a commit f735e7c

12 files changed

Lines changed: 62 additions & 28 deletions

src/main/java/com/iota/iri/controllers/AddressViewModel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.iota.iri.controllers;
22

3+
import com.iota.iri.model.AddressHash;
34
import com.iota.iri.model.Hash;
45
import com.iota.iri.model.persistables.Address;
56
import com.iota.iri.storage.Indexable;
@@ -59,7 +60,7 @@ public static AddressViewModel load(Tangle tangle, Indexable hash) throws Except
5960
* @throws Exception Thrown if the database fails to return a first object
6061
*/
6162
public static AddressViewModel first(Tangle tangle) throws Exception {
62-
Pair<Indexable, Persistable> bundlePair = tangle.getFirst(Address.class, Hash.class);
63+
Pair<Indexable, Persistable> bundlePair = tangle.getFirst(Address.class, AddressHash.class);
6364
if(bundlePair != null && bundlePair.hi != null) {
6465
return new AddressViewModel((Address) bundlePair.hi, (Hash) bundlePair.low);
6566
}

src/main/java/com/iota/iri/controllers/ApproveeViewModel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.iota.iri.controllers;
22

33
import com.iota.iri.model.Hash;
4+
import com.iota.iri.model.TransactionHash;
45
import com.iota.iri.model.persistables.Approvee;
56
import com.iota.iri.storage.Indexable;
67
import com.iota.iri.storage.Persistable;
78
import com.iota.iri.storage.Tangle;
89
import com.iota.iri.utils.Pair;
910

10-
import java.util.HashMap;
11-
import java.util.Map;
1211
import java.util.Set;
1312

1413
/**
@@ -61,7 +60,7 @@ public static ApproveeViewModel load(Tangle tangle, Indexable hash) throws Excep
6160
* @throws Exception Thrown if the database fails to return a first object
6261
*/
6362
public static ApproveeViewModel first(Tangle tangle) throws Exception {
64-
Pair<Indexable, Persistable> bundlePair = tangle.getFirst(Approvee.class, Hash.class);
63+
Pair<Indexable, Persistable> bundlePair = tangle.getFirst(Approvee.class, TransactionHash.class);
6564
if(bundlePair != null && bundlePair.hi != null) {
6665
return new ApproveeViewModel((Approvee) bundlePair.hi, (Hash) bundlePair.low);
6766
}

src/main/java/com/iota/iri/controllers/BundleViewModel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.iota.iri.controllers;
22

3+
import com.iota.iri.model.BundleHash;
34
import com.iota.iri.model.Hash;
45
import com.iota.iri.model.persistables.Bundle;
56
import com.iota.iri.storage.Indexable;
67
import com.iota.iri.storage.Persistable;
78
import com.iota.iri.storage.Tangle;
89
import com.iota.iri.utils.Pair;
910

10-
import java.util.HashMap;
11-
import java.util.Map;
1211
import java.util.Set;
1312

1413
/**
@@ -61,7 +60,7 @@ public static BundleViewModel load(Tangle tangle, Indexable hash) throws Excepti
6160
* @throws Exception Thrown if the database fails to return a first object
6261
*/
6362
public static BundleViewModel first(Tangle tangle) throws Exception {
64-
Pair<Indexable, Persistable> bundlePair = tangle.getFirst(Bundle.class, Hash.class);
63+
Pair<Indexable, Persistable> bundlePair = tangle.getFirst(Bundle.class, BundleHash.class);
6564
if(bundlePair != null && bundlePair.hi != null) {
6665
return new BundleViewModel((Bundle) bundlePair.hi, (Hash) bundlePair.low);
6766
}

src/main/java/com/iota/iri/controllers/TagViewModel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.iota.iri.controllers;
22

33
import com.iota.iri.model.Hash;
4+
import com.iota.iri.model.TagHash;
45
import com.iota.iri.model.persistables.ObsoleteTag;
56
import com.iota.iri.model.persistables.Tag;
67
import com.iota.iri.storage.Indexable;
78
import com.iota.iri.storage.Persistable;
89
import com.iota.iri.storage.Tangle;
910
import com.iota.iri.utils.Pair;
1011

11-
import java.util.HashMap;
12-
import java.util.Map;
1312
import java.util.Set;
1413

1514
/**
@@ -94,7 +93,7 @@ public static TagViewModel loadObsolete(Tangle tangle, Indexable hash) throws Ex
9493
* @throws Exception Thrown if the database fails to return a first object
9594
*/
9695
public static TagViewModel first(Tangle tangle) throws Exception {
97-
Pair<Indexable, Persistable> tagPair = tangle.getFirst(Tag.class, Hash.class);
96+
Pair<Indexable, Persistable> tagPair = tangle.getFirst(Tag.class, TagHash.class);
9897
if(tagPair != null && tagPair.hi != null) {
9998
return new TagViewModel((Tag) tagPair.hi, (Hash) tagPair.low);
10099
}

src/main/java/com/iota/iri/controllers/TransactionViewModel.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package com.iota.iri.controllers;
22

33
import com.iota.iri.model.*;
4+
import com.iota.iri.model.persistables.*;
45
import com.iota.iri.service.snapshot.Snapshot;
5-
import com.iota.iri.model.persistables.Address;
6-
import com.iota.iri.model.persistables.Approvee;
7-
import com.iota.iri.model.persistables.Bundle;
8-
import com.iota.iri.model.persistables.ObsoleteTag;
9-
import com.iota.iri.model.persistables.Tag;
10-
import com.iota.iri.model.persistables.Transaction;
116
import com.iota.iri.storage.Indexable;
127
import com.iota.iri.storage.Persistable;
138
import com.iota.iri.storage.Tangle;
@@ -246,7 +241,7 @@ public static Set<Indexable> getMissingTransactions(Tangle tangle) throws Except
246241
* @throws Exception Thrown if the database fails to return a first object.
247242
*/
248243
public static TransactionViewModel first(Tangle tangle) throws Exception {
249-
Pair<Indexable, Persistable> transactionPair = tangle.getFirst(Transaction.class, Hash.class);
244+
Pair<Indexable, Persistable> transactionPair = tangle.getFirst(Transaction.class, TransactionHash.class);
250245
if (transactionPair != null && transactionPair.hi != null) {
251246
return new TransactionViewModel((Transaction) transactionPair.hi, (Hash) transactionPair.low);
252247
}

src/main/java/com/iota/iri/model/AbstractHash.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
package com.iota.iri.model;
22

3-
import java.io.Serializable;
4-
import java.util.Arrays;
5-
import java.util.Objects;
6-
73
import com.iota.iri.crypto.Curl;
84
import com.iota.iri.model.persistables.Transaction;
95
import com.iota.iri.model.safe.ByteSafe;
106
import com.iota.iri.model.safe.TritSafe;
117
import com.iota.iri.storage.Indexable;
128
import com.iota.iri.utils.Converter;
139

10+
import java.io.Serializable;
11+
import java.util.Arrays;
12+
import java.util.Objects;
13+
1414
public abstract class AbstractHash implements Hash, Serializable {
1515
private final Object lock = new Object();
1616

1717
private ByteSafe byteSafe;
1818
private TritSafe tritSafe;
1919

20+
public AbstractHash() {
21+
}
22+
2023
public AbstractHash(byte[] source, int sourceOffset, int sourceSize) {
2124
if(sourceSize < SIZE_IN_TRITS) {
2225
byte[] dest = new byte[SIZE_IN_BYTES];

src/main/java/com/iota/iri/model/AddressHash.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
public class AddressHash extends AbstractHash {
44

5+
public AddressHash() { }
6+
57
protected AddressHash(byte[] bytes, int offset, int sizeInBytes) {
68
super(bytes, offset, sizeInBytes);
79
}

src/main/java/com/iota/iri/model/BundleHash.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
public class BundleHash extends AbstractHash {
44

5+
public BundleHash() { }
6+
57
protected BundleHash(byte[] bytes, int offset, int sizeInBytes) {
68
super(bytes, offset, sizeInBytes);
79
}

src/main/java/com/iota/iri/model/TagHash.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
public class TagHash extends AbstractHash {
44

5+
public TagHash() { }
6+
57
protected TagHash(byte[] tagBytes, int offset, int tagSizeInBytes) {
68
super(tagBytes, offset, tagSizeInBytes);
79
}

src/main/java/com/iota/iri/model/TransactionHash.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
public class TransactionHash extends AbstractHash {
88

9-
protected TransactionHash(byte[] source, int offset, int sourceSize) {
9+
public TransactionHash() { }
10+
11+
protected TransactionHash(byte[] source, int offset, int sourceSize) {
1012
super(source, offset, sourceSize);
1113
}
1214

0 commit comments

Comments
 (0)