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
|
// Sort. Prioritizing first by signer, then by writable
|
||||||
uniqueMetas.sort(function (x, y) {
|
uniqueMetas.sort(function (x, y) {
|
||||||
const pubkeySorting = x.pubkey
|
if (x.isSigner !== y.isSigner) {
|
||||||
.toBase58()
|
// Signers always come before non-signers
|
||||||
.localeCompare(y.pubkey.toBase58());
|
return x.isSigner ? -1 : 1;
|
||||||
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
}
|
||||||
const checkWritable =
|
if (x.isWritable !== y.isWritable) {
|
||||||
x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
|
// Writable accounts always come before read-only accounts
|
||||||
return checkSigner || checkWritable;
|
return x.isWritable ? -1 : 1;
|
||||||
|
}
|
||||||
|
// Otherwise, sort by pubkey.
|
||||||
|
return x.pubkey._bn.cmp(y.pubkey._bn);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Move fee payer to the front
|
// Move fee payer to the front
|
||||||
|
|
Loading…
Reference in New Issue