generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25f3fdf
commit 5f41dbc
Showing
3 changed files
with
69 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Key, getInscriptionMetadataGpaBuilder, mplInscription } from "@metaplex-foundation/mpl-inscription"; | ||
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults"; | ||
import { writeFileSync } from "fs"; | ||
import pMap from "p-map"; | ||
|
||
export async function fetchInscriptionsByRank(rpc: string, ranks: number[], concurrency: number, output: string) { | ||
const umi = createUmi(rpc); | ||
umi.use(mplInscription()); | ||
|
||
const inscriptionMetadataAccounts = await pMap(ranks, async (rank) => { | ||
const inscriptionMetadatas = [ | ||
...(await getInscriptionMetadataGpaBuilder(umi) | ||
.whereField("key", Key.MintInscriptionMetadataAccount) | ||
.whereField("inscriptionRank", rank) | ||
.getDeserialized()), | ||
...(await getInscriptionMetadataGpaBuilder(umi) | ||
.whereField("key", Key.InscriptionMetadataAccount) | ||
.whereField("inscriptionRank", rank) | ||
.getDeserialized()) | ||
] | ||
|
||
// console.log(inscriptionMetadatas); | ||
|
||
if (inscriptionMetadatas.length === 0) { | ||
throw new Error(`No inscription metadata found for rank ${rank}`); | ||
} else if (inscriptionMetadatas.length > 1) { | ||
throw new Error(`Multiple inscription metadata found for rank ${rank}. This should never happen!`); | ||
} | ||
|
||
const inscriptionMetadata = inscriptionMetadatas[0]; | ||
|
||
delete inscriptionMetadata["header"]; | ||
delete inscriptionMetadata["padding"]; | ||
return inscriptionMetadata; | ||
}, { concurrency }); | ||
|
||
inscriptionMetadataAccounts.sort((a, b) => { | ||
if (a.inscriptionRank < b.inscriptionRank) { | ||
return -1; | ||
} | ||
if (a.inscriptionRank > b.inscriptionRank) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
|
||
writeFileSync(output, JSON.stringify([...inscriptionMetadataAccounts], (key, value) => | ||
typeof value === 'bigint' | ||
? value.toString() | ||
: value, | ||
2)); | ||
} |
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