-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NetworkAddress implementation on boosted baln
- Loading branch information
Showing
13 changed files
with
308 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
score-lib/src/main/java/network/balanced/score/lib/utils/AddressEnumerableSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package network.balanced.score.lib.utils; | ||
|
||
import com.iconloop.score.util.EnumerableSet; | ||
|
||
import foundation.icon.xcall.NetworkAddress; | ||
import score.Address; | ||
|
||
public class AddressEnumerableSet { | ||
|
||
protected final EnumerableSet<Address> legacyEnumerableSet; | ||
protected final EnumerableSet<String> enumerableSet; | ||
|
||
public AddressEnumerableSet(String id){ | ||
legacyEnumerableSet = new EnumerableSet<>(id, Address.class); | ||
enumerableSet = new EnumerableSet<>(id+"_migrated", String.class); | ||
} | ||
|
||
public int length() { | ||
return legacyEnumerableSet.length()+enumerableSet.length(); | ||
} | ||
|
||
public String at(int index) { | ||
if(index< legacyEnumerableSet.length()){ | ||
return legacyEnumerableSet.at(index).toString(); | ||
}else{ | ||
index = index - enumerableSet.length(); | ||
return enumerableSet.at(index); | ||
} | ||
} | ||
|
||
public boolean contains(String value) { | ||
return enumerableSet.contains(value) || legacyEnumerableSet.contains(Address.fromString(NetworkAddress.valueOf(value).account())); | ||
} | ||
|
||
//remove if not needed | ||
public Integer indexOf(String value) { | ||
Integer index = enumerableSet.indexOf(value); | ||
Integer legacyIndex = legacyEnumerableSet.indexOf(Address.fromString(value)); //todo: check if throws error | ||
if(index!=null){ | ||
return index + legacyEnumerableSet.length(); | ||
}else return legacyIndex; | ||
} | ||
|
||
public void add(String value) { | ||
if (!contains(value)) { | ||
// add new value | ||
enumerableSet.add(value); | ||
} | ||
} | ||
|
||
public void remove(String value) { | ||
Integer index = enumerableSet.indexOf(value); | ||
if(index!=null){ | ||
enumerableSet.remove(value); | ||
}else{ | ||
Integer legacyIndex = legacyEnumerableSet.indexOf(Address.fromString(NetworkAddress.valueOf(value).account())); //todo: check if throws error | ||
if(legacyIndex!=null){ | ||
legacyEnumerableSet.remove(Address.fromString(value)); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.