fix: serializing transactions; sort that takes less time and memory
This commit is contained in:
parent
1727ca4371
commit
58092f746c
|
@ -395,13 +395,16 @@ export class Transaction {
|
|||
|
||||
// Sort. Prioritizing first by signer, then by writable
|
||||
uniqueMetas.sort(function (x, y) {
|
||||
const pubkeySorting = x.pubkey
|
||||
.toBase58()
|
||||
.localeCompare(y.pubkey.toBase58());
|
||||
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
||||
const checkWritable =
|
||||
x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
|
||||
return checkSigner || checkWritable;
|
||||
if (x.isSigner !== y.isSigner) {
|
||||
// Signers always come before non-signers
|
||||
return x.isSigner ? -1 : 1;
|
||||
}
|
||||
if (x.isWritable !== y.isWritable) {
|
||||
// Writable accounts always come before read-only accounts
|
||||
return x.isWritable ? -1 : 1;
|
||||
}
|
||||
// Otherwise, sort by pubkey.
|
||||
return x.pubkey._bn.cmp(y.pubkey._bn);
|
||||
});
|
||||
|
||||
// Move fee payer to the front
|
||||
|
|
Loading…
Reference in New Issue