-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed merged conflict and changed naming for legacy transaction and l…
…egacy message
- Loading branch information
Showing
52 changed files
with
4,258 additions
and
746 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,38 @@ | ||
package org.p2p.solanaj.core; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.*; | ||
|
||
public class AccountKeysList { | ||
private final HashMap<String, AccountMeta> accounts; | ||
private final Map<String, AccountMeta> accounts; | ||
|
||
public AccountKeysList() { | ||
accounts = new HashMap<>(); | ||
} | ||
|
||
public void add(AccountMeta accountMeta) { | ||
String key = accountMeta.getPublicKey().toString(); | ||
|
||
if (accounts.containsKey(key)) { | ||
if (!accounts.get(key).isWritable() && accountMeta.isWritable()) { | ||
accounts.put(key, accountMeta); | ||
} | ||
} else { | ||
accounts.put(key, accountMeta); | ||
} | ||
accounts.merge(key, accountMeta, (existing, newMeta) -> | ||
!existing.isWritable() && newMeta.isWritable() ? newMeta : existing); | ||
} | ||
|
||
public void addAll(Collection<AccountMeta> metas) { | ||
for (AccountMeta meta : metas) { | ||
add(meta); | ||
} | ||
metas.forEach(this::add); | ||
} | ||
|
||
public ArrayList<AccountMeta> getList() { | ||
ArrayList<AccountMeta> accountKeysList = new ArrayList<>(accounts.values()); | ||
accountKeysList.sort(metaComparator); | ||
|
||
return accountKeysList; | ||
} | ||
|
||
private static final Comparator<AccountMeta> metaComparator = (am1, am2) -> { | ||
|
||
int cmpSigner = am1.isSigner() == am2.isSigner() ? 0 : am1.isSigner() ? -1 : 1; | ||
if (cmpSigner != 0) { | ||
return cmpSigner; | ||
} | ||
|
||
int cmpkWritable = am1.isWritable() == am2.isWritable() ? 0 : am1.isWritable() ? -1 : 1; | ||
if (cmpkWritable != 0) { | ||
return cmpkWritable; | ||
} | ||
|
||
return Integer.compare(cmpSigner, cmpkWritable); | ||
}; | ||
|
||
@Override | ||
public String toString() { | ||
return "AccountKeysList{" + | ||
"accounts=" + accounts + | ||
'}'; | ||
} | ||
|
||
private static final Comparator<AccountMeta> metaComparator = Comparator | ||
.comparing(AccountMeta::isSigner).reversed() | ||
.thenComparing(AccountMeta::isWritable).reversed(); | ||
} |
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.