-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add deprecated MasterEditionV1 to clients (#86)
- Loading branch information
Showing
6 changed files
with
313 additions
and
2 deletions.
There are no files selected for viewing
214 changes: 214 additions & 0 deletions
214
clients/js/src/generated/accounts/deprecatedMasterEditionV1.ts
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,214 @@ | ||
/** | ||
* This code was AUTOGENERATED using the kinobi library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun kinobi to update it. | ||
* | ||
* @see https://github.com/metaplex-foundation/kinobi | ||
*/ | ||
|
||
import { | ||
Account, | ||
Context, | ||
Option, | ||
OptionOrNullable, | ||
Pda, | ||
PublicKey, | ||
RpcAccount, | ||
RpcGetAccountOptions, | ||
RpcGetAccountsOptions, | ||
assertAccountExists, | ||
deserializeAccount, | ||
gpaBuilder, | ||
publicKey as toPublicKey, | ||
} from '@metaplex-foundation/umi'; | ||
import { | ||
Serializer, | ||
mapSerializer, | ||
option, | ||
publicKey as publicKeySerializer, | ||
string, | ||
struct, | ||
u64, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
import { Key, KeyArgs, getKeySerializer } from '../types'; | ||
|
||
export type DeprecatedMasterEditionV1 = | ||
Account<DeprecatedMasterEditionV1AccountData>; | ||
|
||
export type DeprecatedMasterEditionV1AccountData = { | ||
key: Key; | ||
supply: bigint; | ||
maxSupply: Option<bigint>; | ||
printingMint: PublicKey; | ||
oneTimePrintingAuthorizationMint: PublicKey; | ||
}; | ||
|
||
export type DeprecatedMasterEditionV1AccountDataArgs = { | ||
supply: number | bigint; | ||
maxSupply: OptionOrNullable<number | bigint>; | ||
printingMint: PublicKey; | ||
oneTimePrintingAuthorizationMint: PublicKey; | ||
}; | ||
|
||
export function getDeprecatedMasterEditionV1AccountDataSerializer(): Serializer< | ||
DeprecatedMasterEditionV1AccountDataArgs, | ||
DeprecatedMasterEditionV1AccountData | ||
> { | ||
return mapSerializer< | ||
DeprecatedMasterEditionV1AccountDataArgs, | ||
any, | ||
DeprecatedMasterEditionV1AccountData | ||
>( | ||
struct<DeprecatedMasterEditionV1AccountData>( | ||
[ | ||
['key', getKeySerializer()], | ||
['supply', u64()], | ||
['maxSupply', option(u64())], | ||
['printingMint', publicKeySerializer()], | ||
['oneTimePrintingAuthorizationMint', publicKeySerializer()], | ||
], | ||
{ description: 'DeprecatedMasterEditionV1AccountData' } | ||
), | ||
(value) => ({ ...value, key: Key.MasterEditionV1 }) | ||
) as Serializer< | ||
DeprecatedMasterEditionV1AccountDataArgs, | ||
DeprecatedMasterEditionV1AccountData | ||
>; | ||
} | ||
|
||
export function deserializeDeprecatedMasterEditionV1( | ||
rawAccount: RpcAccount | ||
): DeprecatedMasterEditionV1 { | ||
return deserializeAccount( | ||
rawAccount, | ||
getDeprecatedMasterEditionV1AccountDataSerializer() | ||
); | ||
} | ||
|
||
export async function fetchDeprecatedMasterEditionV1( | ||
context: Pick<Context, 'rpc'>, | ||
publicKey: PublicKey | Pda, | ||
options?: RpcGetAccountOptions | ||
): Promise<DeprecatedMasterEditionV1> { | ||
const maybeAccount = await context.rpc.getAccount( | ||
toPublicKey(publicKey, false), | ||
options | ||
); | ||
assertAccountExists(maybeAccount, 'DeprecatedMasterEditionV1'); | ||
return deserializeDeprecatedMasterEditionV1(maybeAccount); | ||
} | ||
|
||
export async function safeFetchDeprecatedMasterEditionV1( | ||
context: Pick<Context, 'rpc'>, | ||
publicKey: PublicKey | Pda, | ||
options?: RpcGetAccountOptions | ||
): Promise<DeprecatedMasterEditionV1 | null> { | ||
const maybeAccount = await context.rpc.getAccount( | ||
toPublicKey(publicKey, false), | ||
options | ||
); | ||
return maybeAccount.exists | ||
? deserializeDeprecatedMasterEditionV1(maybeAccount) | ||
: null; | ||
} | ||
|
||
export async function fetchAllDeprecatedMasterEditionV1( | ||
context: Pick<Context, 'rpc'>, | ||
publicKeys: Array<PublicKey | Pda>, | ||
options?: RpcGetAccountsOptions | ||
): Promise<DeprecatedMasterEditionV1[]> { | ||
const maybeAccounts = await context.rpc.getAccounts( | ||
publicKeys.map((key) => toPublicKey(key, false)), | ||
options | ||
); | ||
return maybeAccounts.map((maybeAccount) => { | ||
assertAccountExists(maybeAccount, 'DeprecatedMasterEditionV1'); | ||
return deserializeDeprecatedMasterEditionV1(maybeAccount); | ||
}); | ||
} | ||
|
||
export async function safeFetchAllDeprecatedMasterEditionV1( | ||
context: Pick<Context, 'rpc'>, | ||
publicKeys: Array<PublicKey | Pda>, | ||
options?: RpcGetAccountsOptions | ||
): Promise<DeprecatedMasterEditionV1[]> { | ||
const maybeAccounts = await context.rpc.getAccounts( | ||
publicKeys.map((key) => toPublicKey(key, false)), | ||
options | ||
); | ||
return maybeAccounts | ||
.filter((maybeAccount) => maybeAccount.exists) | ||
.map((maybeAccount) => | ||
deserializeDeprecatedMasterEditionV1(maybeAccount as RpcAccount) | ||
); | ||
} | ||
|
||
export function getDeprecatedMasterEditionV1GpaBuilder( | ||
context: Pick<Context, 'rpc' | 'programs'> | ||
) { | ||
const programId = context.programs.getPublicKey( | ||
'mplTokenMetadata', | ||
'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' | ||
); | ||
return gpaBuilder(context, programId) | ||
.registerFields<{ | ||
key: KeyArgs; | ||
supply: number | bigint; | ||
maxSupply: OptionOrNullable<number | bigint>; | ||
printingMint: PublicKey; | ||
oneTimePrintingAuthorizationMint: PublicKey; | ||
}>({ | ||
key: [0, getKeySerializer()], | ||
supply: [1, u64()], | ||
maxSupply: [9, option(u64())], | ||
printingMint: [null, publicKeySerializer()], | ||
oneTimePrintingAuthorizationMint: [null, publicKeySerializer()], | ||
}) | ||
.deserializeUsing<DeprecatedMasterEditionV1>((account) => | ||
deserializeDeprecatedMasterEditionV1(account) | ||
) | ||
.whereField('key', Key.MasterEditionV1); | ||
} | ||
|
||
export function findDeprecatedMasterEditionV1Pda( | ||
context: Pick<Context, 'eddsa' | 'programs'>, | ||
seeds: { | ||
/** The address of the mint account */ | ||
mint: PublicKey; | ||
} | ||
): Pda { | ||
const programId = context.programs.getPublicKey( | ||
'mplTokenMetadata', | ||
'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s' | ||
); | ||
return context.eddsa.findPda(programId, [ | ||
string({ size: 'variable' }).serialize('metadata'), | ||
publicKeySerializer().serialize(programId), | ||
publicKeySerializer().serialize(seeds.mint), | ||
string({ size: 'variable' }).serialize('edition'), | ||
]); | ||
} | ||
|
||
export async function fetchDeprecatedMasterEditionV1FromSeeds( | ||
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>, | ||
seeds: Parameters<typeof findDeprecatedMasterEditionV1Pda>[1], | ||
options?: RpcGetAccountOptions | ||
): Promise<DeprecatedMasterEditionV1> { | ||
return fetchDeprecatedMasterEditionV1( | ||
context, | ||
findDeprecatedMasterEditionV1Pda(context, seeds), | ||
options | ||
); | ||
} | ||
|
||
export async function safeFetchDeprecatedMasterEditionV1FromSeeds( | ||
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>, | ||
seeds: Parameters<typeof findDeprecatedMasterEditionV1Pda>[1], | ||
options?: RpcGetAccountOptions | ||
): Promise<DeprecatedMasterEditionV1 | null> { | ||
return safeFetchDeprecatedMasterEditionV1( | ||
context, | ||
findDeprecatedMasterEditionV1Pda(context, seeds), | ||
options | ||
); | ||
} |
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
87 changes: 87 additions & 0 deletions
87
clients/rust/src/generated/accounts/deprecated_master_edition_v1.rs
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,87 @@ | ||
//! This code was AUTOGENERATED using the kinobi library. | ||
//! Please DO NOT EDIT THIS FILE, instead use visitors | ||
//! to add features, then rerun kinobi to update it. | ||
//! | ||
//! [https://github.com/metaplex-foundation/kinobi] | ||
//! | ||
use crate::generated::types::Key; | ||
use borsh::BorshDeserialize; | ||
use borsh::BorshSerialize; | ||
use solana_program::pubkey::Pubkey; | ||
|
||
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct DeprecatedMasterEditionV1 { | ||
pub key: Key, | ||
pub supply: u64, | ||
pub max_supply: Option<u64>, | ||
#[cfg_attr( | ||
feature = "serde", | ||
serde(with = "serde_with::As::<serde_with::DisplayFromStr>") | ||
)] | ||
pub printing_mint: Pubkey, | ||
#[cfg_attr( | ||
feature = "serde", | ||
serde(with = "serde_with::As::<serde_with::DisplayFromStr>") | ||
)] | ||
pub one_time_printing_authorization_mint: Pubkey, | ||
} | ||
|
||
impl DeprecatedMasterEditionV1 { | ||
/// Prefix values used to generate a PDA for this account. | ||
/// | ||
/// Values are positional and appear in the following order: | ||
/// | ||
/// 0. `DeprecatedMasterEditionV1::PREFIX.0` | ||
/// 1. `crate::MPL_TOKEN_METADATA_ID` | ||
/// 2. mint (`Pubkey`) | ||
/// 3. `DeprecatedMasterEditionV1::PREFIX.1` | ||
pub const PREFIX: (&'static [u8], &'static [u8]) = | ||
("metadata".as_bytes(), "edition".as_bytes()); | ||
|
||
pub fn create_pda( | ||
mint: Pubkey, | ||
bump: u8, | ||
) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> { | ||
solana_program::pubkey::Pubkey::create_program_address( | ||
&[ | ||
"metadata".as_bytes(), | ||
crate::MPL_TOKEN_METADATA_ID.as_ref(), | ||
mint.as_ref(), | ||
"edition".as_bytes(), | ||
&[bump], | ||
], | ||
&crate::MPL_TOKEN_METADATA_ID, | ||
) | ||
} | ||
|
||
pub fn find_pda(mint: &Pubkey) -> (solana_program::pubkey::Pubkey, u8) { | ||
solana_program::pubkey::Pubkey::find_program_address( | ||
&[ | ||
"metadata".as_bytes(), | ||
crate::MPL_TOKEN_METADATA_ID.as_ref(), | ||
mint.as_ref(), | ||
"edition".as_bytes(), | ||
], | ||
&crate::MPL_TOKEN_METADATA_ID, | ||
) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> { | ||
let mut data = data; | ||
Self::deserialize(&mut data) | ||
} | ||
} | ||
|
||
impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for DeprecatedMasterEditionV1 { | ||
type Error = std::io::Error; | ||
|
||
fn try_from( | ||
account_info: &solana_program::account_info::AccountInfo<'a>, | ||
) -> Result<Self, Self::Error> { | ||
let mut data: &[u8] = &(*account_info.data).borrow(); | ||
Self::deserialize(&mut data) | ||
} | ||
} |
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