skynetcap / solanaj

Solana RPC client written in Java
MIT License
94 stars 50 forks source link

Bug in AccountKeysList Comparator #65

Open defi-movie opened 1 month ago

defi-movie commented 1 month ago

Hi,

Could be something changed in underlying JVM implementation but the Comparator in AccountKeysList isn't sorting accounts as expected. It seemed to have been working fine up till 1.17.2.

This code:

    AccountKeysList keysList = new AccountKeysList();
    keysList.add( new AccountMeta(new PublicKey("G75kGJiizyFNdnvvHxkrBrcwLomGJT2CigdXnsYzrFHv"), true, true) );
    keysList.add( new AccountMeta(new PublicKey("BQWWFhzBdw2vKKBUX17NHeFbCoFQHfRARpdztPE2tDJ"), true, false) );
    keysList.add( new AccountMeta(new PublicKey("11111111111111111111111111111111"), false, false) );
    List<AccountMeta> keys = keysList.getList();
    keys.forEach( k -> System.out.println(k.getPublicKey() + "   isSigner? " + k.isSigner() + "    isWritable? " + k.isWritable()) );

Returns:

11111111111111111111111111111111 isSigner? false isWritable? false G75kGJiizyFNdnvvHxkrBrcwLomGJT2CigdXnsYzrFHv isSigner? true isWritable? true BQWWFhzBdw2vKKBUX17NHeFbCoFQHfRARpdztPE2tDJ isSigner? true isWritable? false

The signers and writables should appear first.