-
Notifications
You must be signed in to change notification settings - Fork 11
Auto-detect Core asset vs collection for plugin add/update #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MarkSackerberg
merged 4 commits into
main
from
cursor/auto-detect-plugin-collection-e1e4
Jul 24, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
485de17
Auto-detect Core asset vs collection for plugin commands
cursoragent f72cb60
Raise default compute unit limit to avoid Genesis CU flakes
cursoragent 87288dd
Limit Genesis create CU budget without growing other txs
cursoragent 16c2837
Harden Core account resolution and share Genesis CU constant
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,76 @@ | ||
| import { | ||
| collectionAddress, | ||
| deserializeAssetV1, | ||
| deserializeCollectionV1, | ||
| Key, | ||
| } from '@metaplex-foundation/mpl-core' | ||
| import { publicKey, Umi } from '@metaplex-foundation/umi' | ||
|
|
||
| export type ResolvedCoreAccount = { | ||
| id: string | ||
| isCollection: boolean | ||
| /** Parent collection address when the account is an asset belonging to a collection */ | ||
| collectionId?: string | ||
|
MarkSackerberg marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export type ResolveCoreAccountOptions = { | ||
| /** | ||
| * When true, only accept a Core Collection at this address. | ||
| * Mirrors an explicit `--collection` flag override. | ||
| */ | ||
| forceCollection?: boolean | ||
| } | ||
|
|
||
| /** | ||
| * Resolve whether an address is a Core Asset or Collection. | ||
| * | ||
| * Fetches the account once so RPC/transport failures propagate. Distinguishes | ||
| * Asset vs Collection via the on-chain account key instead of catching | ||
| * deserialize errors (which would also hide network failures). | ||
| * | ||
| * When `forceCollection` is set, only Collection is accepted. | ||
| */ | ||
| export async function resolveCoreAccount( | ||
| umi: Umi, | ||
| id: string, | ||
| options: ResolveCoreAccountOptions = {}, | ||
| ): Promise<ResolvedCoreAccount> { | ||
| const address = publicKey(id) | ||
| const account = await umi.rpc.getAccount(address) | ||
|
|
||
| if (!account.exists) { | ||
| if (options.forceCollection) { | ||
| throw new Error(`Unable to fetch collection at address: ${id}`) | ||
| } | ||
| throw new Error(`Address ${id} is neither a Core Asset nor a Core Collection`) | ||
| } | ||
|
|
||
| const accountKey = account.data[0] | ||
|
|
||
| if (options.forceCollection) { | ||
| if (accountKey !== Key.CollectionV1) { | ||
| throw new Error(`Unable to fetch collection at address: ${id}`) | ||
| } | ||
| deserializeCollectionV1(account) | ||
| return { id, isCollection: true } | ||
| } | ||
|
|
||
| if (accountKey === Key.AssetV1) { | ||
| const asset = deserializeAssetV1(account) | ||
| const parentCollection = collectionAddress(asset) | ||
| return { | ||
| id, | ||
| isCollection: false, | ||
| collectionId: parentCollection ? parentCollection.toString() : undefined, | ||
| } | ||
| } | ||
|
|
||
| if (accountKey === Key.CollectionV1) { | ||
| deserializeCollectionV1(account) | ||
| return { id, isCollection: true } | ||
| } | ||
|
|
||
| throw new Error(`Address ${id} is neither a Core Asset nor a Core Collection`) | ||
| } | ||
|
|
||
| export default resolveCoreAccount | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.