Skip to content

Commit

Permalink
Update sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrp13 committed Apr 26, 2022
1 parent 553eebc commit 73269d1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions coordinators/MovieCoordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const MOVIE_REVIEW_PROGRAM_ID = 'CenYq6bDRB7p73EjsPEpiYN7uveyPUTdXkDkgUduboaN'
export class MovieCoordinator {
static accounts: web3.PublicKey[] = []


static async prefetchAccounts(connection: web3.Connection, search: string) {
const accounts = await connection.getProgramAccounts(
new web3.PublicKey(MOVIE_REVIEW_PROGRAM_ID),
Expand All @@ -26,7 +25,11 @@ export class MovieCoordinator {
)

accounts.sort( (a, b) => {
return a.account.data.slice(4, 4 + a.account.data[0]).compare(b.account.data.slice(4, 4 + b.account.data[0]))
const lengthA = a.account.data.readUInt32LE(0)
const lengthB = b.account.data.readUInt32LE(0)
const dataA = a.account.data.slice(4, 4 + lengthA)
const dataB = b.account.data.slice(4, 4 + lengthB)
return dataA.compare(dataB)
})

this.accounts = accounts.map(account => account.pubkey)
Expand Down

0 comments on commit 73269d1

Please sign in to comment.