-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wip]: Add flexible PDA to IDL and link to both accounts
- Loading branch information
1 parent
4d2d12d
commit 0df9ca0
Showing
7 changed files
with
137 additions
and
23 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
import { Account, Address, GetAccountInfoApi, Rpc } from '@solana/web3.js'; | ||
import { | ||
fetchMetadata, | ||
findCanonicalPda, | ||
findNonCanonicalPda, | ||
Metadata, | ||
SeedArgs, | ||
} from './generated'; | ||
import { fetchMetadataFromSeeds, Metadata, SeedArgs } from './generated'; | ||
import { unpackAndFetchData } from './packData'; | ||
|
||
export async function fetchMetadataWithContent( | ||
rpc: Rpc<GetAccountInfoApi>, | ||
program: Address, | ||
seed: SeedArgs, | ||
authority?: Address | ||
authority: Address | null = null | ||
): Promise<Account<Metadata> & { content: string }> { | ||
const [metadata] = authority | ||
? await findNonCanonicalPda({ program, authority, seed }) | ||
: await findCanonicalPda({ program, seed }); | ||
const account = await fetchMetadata(rpc, metadata); | ||
const account = await fetchMetadataFromSeeds(rpc, { | ||
program, | ||
authority, | ||
seed, | ||
}); | ||
const content = await unpackAndFetchData({ rpc, ...account.data }); | ||
return Object.freeze({ ...account, content }); | ||
} |
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
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
*/ | ||
|
||
export * from './canonical'; | ||
export * from './metadata'; | ||
export * from './nonCanonical'; |
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,45 @@ | ||
/** | ||
* This code was AUTOGENERATED using the codama library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun codama to update it. | ||
* | ||
* @see https://github.com/codama-idl/codama | ||
*/ | ||
|
||
import { | ||
getAddressEncoder, | ||
getOptionEncoder, | ||
getProgramDerivedAddress, | ||
type Address, | ||
type OptionOrNullable, | ||
type ProgramDerivedAddress, | ||
} from '@solana/web3.js'; | ||
import { getSeedEncoder, type SeedArgs } from '../types'; | ||
|
||
export type MetadataSeeds = { | ||
/** The program to which the metadata belongs. */ | ||
program: Address; | ||
/** The third-party authority managing this metadata account, if non-canonical. */ | ||
authority: OptionOrNullable<Address>; | ||
/** The seed deriving the metadata account. */ | ||
seed: SeedArgs; | ||
}; | ||
|
||
export async function findMetadataPda( | ||
seeds: MetadataSeeds, | ||
config: { programAddress?: Address | undefined } = {} | ||
): Promise<ProgramDerivedAddress> { | ||
const { | ||
programAddress = '4FX3oHhpAkJcb2tFFrq9JBY8gc4RhCRM5g75VG9QHnj1' as Address<'4FX3oHhpAkJcb2tFFrq9JBY8gc4RhCRM5g75VG9QHnj1'>, | ||
} = config; | ||
return await getProgramDerivedAddress({ | ||
programAddress, | ||
seeds: [ | ||
getAddressEncoder().encode(seeds.program), | ||
getOptionEncoder(getAddressEncoder(), { prefix: null }).encode( | ||
seeds.authority | ||
), | ||
getSeedEncoder().encode(seeds.seed), | ||
], | ||
}); | ||
} |
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