generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 28
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
744559b
commit e19d598
Showing
16 changed files
with
403 additions
and
40 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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/** | ||
* 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, | ||
Pda, | ||
PublicKey, | ||
RpcAccount, | ||
RpcGetAccountOptions, | ||
RpcGetAccountsOptions, | ||
assertAccountExists, | ||
deserializeAccount, | ||
gpaBuilder, | ||
publicKey as toPublicKey, | ||
} from '@metaplex-foundation/umi'; | ||
import { | ||
Serializer, | ||
array, | ||
bytes, | ||
struct, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
import { PluginHash, PluginHashArgs, getPluginHashSerializer } from '../types'; | ||
|
||
export type HashedAssetSchema = Account<HashedAssetSchemaAccountData>; | ||
|
||
export type HashedAssetSchemaAccountData = { | ||
assetHash: Uint8Array; | ||
pluginHashes: Array<PluginHash>; | ||
}; | ||
|
||
export type HashedAssetSchemaAccountDataArgs = { | ||
assetHash: Uint8Array; | ||
pluginHashes: Array<PluginHashArgs>; | ||
}; | ||
|
||
export function getHashedAssetSchemaAccountDataSerializer(): Serializer< | ||
HashedAssetSchemaAccountDataArgs, | ||
HashedAssetSchemaAccountData | ||
> { | ||
return struct<HashedAssetSchemaAccountData>( | ||
[ | ||
['assetHash', bytes({ size: 32 })], | ||
['pluginHashes', array(getPluginHashSerializer())], | ||
], | ||
{ description: 'HashedAssetSchemaAccountData' } | ||
) as Serializer< | ||
HashedAssetSchemaAccountDataArgs, | ||
HashedAssetSchemaAccountData | ||
>; | ||
} | ||
|
||
export function deserializeHashedAssetSchema( | ||
rawAccount: RpcAccount | ||
): HashedAssetSchema { | ||
return deserializeAccount( | ||
rawAccount, | ||
getHashedAssetSchemaAccountDataSerializer() | ||
); | ||
} | ||
|
||
export async function fetchHashedAssetSchema( | ||
context: Pick<Context, 'rpc'>, | ||
publicKey: PublicKey | Pda, | ||
options?: RpcGetAccountOptions | ||
): Promise<HashedAssetSchema> { | ||
const maybeAccount = await context.rpc.getAccount( | ||
toPublicKey(publicKey, false), | ||
options | ||
); | ||
assertAccountExists(maybeAccount, 'HashedAssetSchema'); | ||
return deserializeHashedAssetSchema(maybeAccount); | ||
} | ||
|
||
export async function safeFetchHashedAssetSchema( | ||
context: Pick<Context, 'rpc'>, | ||
publicKey: PublicKey | Pda, | ||
options?: RpcGetAccountOptions | ||
): Promise<HashedAssetSchema | null> { | ||
const maybeAccount = await context.rpc.getAccount( | ||
toPublicKey(publicKey, false), | ||
options | ||
); | ||
return maybeAccount.exists | ||
? deserializeHashedAssetSchema(maybeAccount) | ||
: null; | ||
} | ||
|
||
export async function fetchAllHashedAssetSchema( | ||
context: Pick<Context, 'rpc'>, | ||
publicKeys: Array<PublicKey | Pda>, | ||
options?: RpcGetAccountsOptions | ||
): Promise<HashedAssetSchema[]> { | ||
const maybeAccounts = await context.rpc.getAccounts( | ||
publicKeys.map((key) => toPublicKey(key, false)), | ||
options | ||
); | ||
return maybeAccounts.map((maybeAccount) => { | ||
assertAccountExists(maybeAccount, 'HashedAssetSchema'); | ||
return deserializeHashedAssetSchema(maybeAccount); | ||
}); | ||
} | ||
|
||
export async function safeFetchAllHashedAssetSchema( | ||
context: Pick<Context, 'rpc'>, | ||
publicKeys: Array<PublicKey | Pda>, | ||
options?: RpcGetAccountsOptions | ||
): Promise<HashedAssetSchema[]> { | ||
const maybeAccounts = await context.rpc.getAccounts( | ||
publicKeys.map((key) => toPublicKey(key, false)), | ||
options | ||
); | ||
return maybeAccounts | ||
.filter((maybeAccount) => maybeAccount.exists) | ||
.map((maybeAccount) => | ||
deserializeHashedAssetSchema(maybeAccount as RpcAccount) | ||
); | ||
} | ||
|
||
export function getHashedAssetSchemaGpaBuilder( | ||
context: Pick<Context, 'rpc' | 'programs'> | ||
) { | ||
const programId = context.programs.getPublicKey( | ||
'mplAsset', | ||
'ASSETp3DinZKfiAyvdQG16YWWLJ2X3ZKjg9zku7n1sZD' | ||
); | ||
return gpaBuilder(context, programId) | ||
.registerFields<{ | ||
assetHash: Uint8Array; | ||
pluginHashes: Array<PluginHashArgs>; | ||
}>({ | ||
assetHash: [0, bytes({ size: 32 })], | ||
pluginHashes: [32, array(getPluginHashSerializer())], | ||
}) | ||
.deserializeUsing<HashedAssetSchema>((account) => | ||
deserializeHashedAssetSchema(account) | ||
); | ||
} |
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
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,33 @@ | ||
/** | ||
* 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 { | ||
Serializer, | ||
bytes, | ||
struct, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
|
||
export type PluginHash = { | ||
pluginAuthoritiesHash: Uint8Array; | ||
pluginHash: Uint8Array; | ||
}; | ||
|
||
export type PluginHashArgs = PluginHash; | ||
|
||
export function getPluginHashSerializer(): Serializer< | ||
PluginHashArgs, | ||
PluginHash | ||
> { | ||
return struct<PluginHash>( | ||
[ | ||
['pluginAuthoritiesHash', bytes({ size: 32 })], | ||
['pluginHash', bytes({ size: 32 })], | ||
], | ||
{ description: 'PluginHash' } | ||
) as Serializer<PluginHashArgs, PluginHash>; | ||
} |
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
36 changes: 36 additions & 0 deletions
36
clients/rust/src/generated/accounts/hashed_asset_schema.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,36 @@ | ||
//! 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::PluginHash; | ||
use borsh::BorshDeserialize; | ||
use borsh::BorshSerialize; | ||
|
||
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct HashedAssetSchema { | ||
pub asset_hash: [u8; 32], | ||
pub plugin_hashes: Vec<PluginHash>, | ||
} | ||
|
||
impl HashedAssetSchema { | ||
#[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 HashedAssetSchema { | ||
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
Oops, something went wrong.