Skip to content

Commit

Permalink
Renaming to plugins and minor tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Feb 15, 2024
1 parent adbb43b commit 4040e7e
Show file tree
Hide file tree
Showing 25 changed files with 371 additions and 108 deletions.
14 changes: 7 additions & 7 deletions clients/js/src/generated/accounts/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import {
string,
struct,
} from '@metaplex-foundation/umi/serializers';
import { Interface, InterfaceArgs, getInterfaceSerializer } from '../types';
import { Key, KeyArgs, getKeySerializer } from '../types';

export type Asset = Account<AssetAccountData>;

export type AssetAccountData = {
interface: Interface;
key: Key;
updateAuthority: PublicKey;
owner: PublicKey;
name: string;
Expand All @@ -52,15 +52,15 @@ export function getAssetAccountDataSerializer(): Serializer<
return mapSerializer<AssetAccountDataArgs, any, AssetAccountData>(
struct<AssetAccountData>(
[
['interface', getInterfaceSerializer()],
['key', getKeySerializer()],
['updateAuthority', publicKeySerializer()],
['owner', publicKeySerializer()],
['name', string()],
['uri', string()],
],
{ description: 'AssetAccountData' }
),
(value) => ({ ...value, interface: Interface.Asset })
(value) => ({ ...value, key: Key.Asset })
) as Serializer<AssetAccountDataArgs, AssetAccountData>;
}

Expand Down Expand Up @@ -129,18 +129,18 @@ export function getAssetGpaBuilder(context: Pick<Context, 'rpc' | 'programs'>) {
);
return gpaBuilder(context, programId)
.registerFields<{
interface: InterfaceArgs;
key: KeyArgs;
updateAuthority: PublicKey;
owner: PublicKey;
name: string;
uri: string;
}>({
interface: [0, getInterfaceSerializer()],
key: [0, getKeySerializer()],
updateAuthority: [1, publicKeySerializer()],
owner: [33, publicKeySerializer()],
name: [65, string()],
uri: [null, string()],
})
.deserializeUsing<Asset>((account) => deserializeAsset(account))
.whereField('interface', Interface.Asset);
.whereField('key', Key.Asset);
}
12 changes: 6 additions & 6 deletions clients/js/src/generated/accounts/hashedAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ import {
struct,
u64,
} from '@metaplex-foundation/umi/serializers';
import { Interface, InterfaceArgs, getInterfaceSerializer } from '../types';
import { Key, KeyArgs, getKeySerializer } from '../types';

export type HashedAsset = Account<HashedAssetAccountData>;

export type HashedAssetAccountData = {
interface: Interface;
key: Key;
hash: Uint8Array;
watermarkSlot: Option<bigint>;
};

export type HashedAssetAccountDataArgs = {
interface: InterfaceArgs;
key: KeyArgs;
hash: Uint8Array;
watermarkSlot: OptionOrNullable<number | bigint>;
};
Expand All @@ -50,7 +50,7 @@ export function getHashedAssetAccountDataSerializer(): Serializer<
> {
return struct<HashedAssetAccountData>(
[
['interface', getInterfaceSerializer()],
['key', getKeySerializer()],
['hash', bytes({ size: 32 })],
['watermarkSlot', option(u64())],
],
Expand Down Expand Up @@ -125,11 +125,11 @@ export function getHashedAssetGpaBuilder(
);
return gpaBuilder(context, programId)
.registerFields<{
interface: InterfaceArgs;
key: KeyArgs;
hash: Uint8Array;
watermarkSlot: OptionOrNullable<number | bigint>;
}>({
interface: [0, getInterfaceSerializer()],
key: [0, getKeySerializer()],
hash: [1, bytes({ size: 32 })],
watermarkSlot: [33, option(u64())],
})
Expand Down
6 changes: 3 additions & 3 deletions clients/js/src/generated/types/assetHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
u8,
} from '@metaplex-foundation/umi/serializers';

export type AssetHeader = { version: number; interfaceMapOffset: bigint };
export type AssetHeader = { version: number; pluginMapOffset: bigint };

export type AssetHeaderArgs = {
version: number;
interfaceMapOffset: number | bigint;
pluginMapOffset: number | bigint;
};

export function getAssetHeaderSerializer(): Serializer<
Expand All @@ -27,7 +27,7 @@ export function getAssetHeaderSerializer(): Serializer<
return struct<AssetHeader>(
[
['version', u8()],
['interfaceMapOffset', u64()],
['pluginMapOffset', u64()],
],
{ description: 'AssetHeader' }
) as Serializer<AssetHeaderArgs, AssetHeader>;
Expand Down
77 changes: 77 additions & 0 deletions clients/js/src/generated/types/authority.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* 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 { PublicKey } from '@metaplex-foundation/umi';
import {
GetDataEnumKind,
GetDataEnumKindContent,
Serializer,
dataEnum,
publicKey as publicKeySerializer,
struct,
unit,
} from '@metaplex-foundation/umi/serializers';
import { Plugin, PluginArgs, getPluginSerializer } from '.';

export type Authority =
| { __kind: 'Owner' }
| { __kind: 'Permanent'; address: PublicKey }
| { __kind: 'SameAs'; plugin: Plugin };

export type AuthorityArgs =
| { __kind: 'Owner' }
| { __kind: 'Permanent'; address: PublicKey }
| { __kind: 'SameAs'; plugin: PluginArgs };

export function getAuthoritySerializer(): Serializer<AuthorityArgs, Authority> {
return dataEnum<Authority>(
[
['Owner', unit()],
[
'Permanent',
struct<GetDataEnumKindContent<Authority, 'Permanent'>>([
['address', publicKeySerializer()],
]),
],
[
'SameAs',
struct<GetDataEnumKindContent<Authority, 'SameAs'>>([
['plugin', getPluginSerializer()],
]),
],
],
{ description: 'Authority' }
) as Serializer<AuthorityArgs, Authority>;
}

// Data Enum Helpers.
export function authority(
kind: 'Owner'
): GetDataEnumKind<AuthorityArgs, 'Owner'>;
export function authority(
kind: 'Permanent',
data: GetDataEnumKindContent<AuthorityArgs, 'Permanent'>
): GetDataEnumKind<AuthorityArgs, 'Permanent'>;
export function authority(
kind: 'SameAs',
data: GetDataEnumKindContent<AuthorityArgs, 'SameAs'>
): GetDataEnumKind<AuthorityArgs, 'SameAs'>;
export function authority<K extends AuthorityArgs['__kind']>(
kind: K,
data?: any
): Extract<AuthorityArgs, { __kind: K }> {
return Array.isArray(data)
? { __kind: kind, fields: data }
: { __kind: kind, ...(data ?? {}) };
}
export function isAuthority<K extends Authority['__kind']>(
kind: K,
value: Authority
): value is Authority & { __kind: K } {
return value.__kind === kind;
}
4 changes: 3 additions & 1 deletion clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

export * from './assetHeader';
export * from './authority';
export * from './creator';
export * from './dataState';
export * from './interface';
export * from './key';
export * from './plugin';
export * from './royalties';
26 changes: 26 additions & 0 deletions clients/js/src/generated/types/key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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, scalarEnum } from '@metaplex-foundation/umi/serializers';

export enum Key {
Uninitialized,
Asset,
HashedAsset,
Collection,
HashedCollection,
}

export type KeyArgs = Key;

export function getKeySerializer(): Serializer<KeyArgs, Key> {
return scalarEnum<Key>(Key, { description: 'Key' }) as Serializer<
KeyArgs,
Key
>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Serializer, scalarEnum } from '@metaplex-foundation/umi/serializers';

export enum Interface {
export enum Plugin {
Reserved,
Asset,
HashedAsset,
Expand All @@ -19,10 +19,11 @@ export enum Interface {
Inscription,
}

export type InterfaceArgs = Interface;
export type PluginArgs = Plugin;

export function getInterfaceSerializer(): Serializer<InterfaceArgs, Interface> {
return scalarEnum<Interface>(Interface, {
description: 'Interface',
}) as Serializer<InterfaceArgs, Interface>;
export function getPluginSerializer(): Serializer<PluginArgs, Plugin> {
return scalarEnum<Plugin>(Plugin, { description: 'Plugin' }) as Serializer<
PluginArgs,
Plugin
>;
}
17 changes: 12 additions & 5 deletions clients/js/test/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateSigner, publicKey } from '@metaplex-foundation/umi';
import test from 'ava';
import { base58 } from '@metaplex-foundation/umi/serializers';
// import { base58 } from '@metaplex-foundation/umi/serializers';
import { Asset, DataState, create, fetchAsset, fetchHashedAsset, getAssetAccountDataSerializer } from '../src';
import { createUmi } from './_setup';

Expand All @@ -20,7 +20,7 @@ test('it can create a new asset in account state', async (t) => {

// Then an account was created with the correct data.
const asset = await fetchAsset(umi, assetAddress.publicKey);
// console.log(asset);
console.log("Account State:", asset);
t.like(asset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: umi.identity.publicKey,
Expand Down Expand Up @@ -54,10 +54,17 @@ test('it can create a new asset in ledger state', async (t) => {

const tx = await umi.rpc.getTransaction(txResult.signature);
if (tx && tx.meta.innerInstructions) {
console.log(tx.meta.innerInstructions[0].instructions);
// console.log(tx.meta.innerInstructions[0].instructions);
const { data } = tx.meta.innerInstructions[0].instructions[0];
console.log(base58.deserialize(data));
// console.log(base58.deserialize(data));
const parsed = getAssetAccountDataSerializer().deserialize(data)[0];
console.log("Parsed data:", parsed);
console.log("Ledger State:", parsed);
t.like(parsed, <Asset>{
updateAuthority: umi.identity.publicKey,
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
});
}

});
4 changes: 2 additions & 2 deletions clients/rust/src/generated/accounts/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
//! [https://github.com/metaplex-foundation/kinobi]
//!
use crate::generated::types::Interface;
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 Asset {
pub interface: Interface,
pub key: Key,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
Expand Down
4 changes: 2 additions & 2 deletions clients/rust/src/generated/accounts/hashed_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
//! [https://github.com/metaplex-foundation/kinobi]
//!
use crate::generated::types::Interface;
use crate::generated::types::Key;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct HashedAsset {
pub interface: Interface,
pub key: Key,
pub hash: [u8; 32],
pub watermark_slot: Option<u64>,
}
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/src/generated/types/asset_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ use borsh::BorshSerialize;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AssetHeader {
pub version: u8,
pub interface_map_offset: u64,
pub plugin_map_offset: u64,
}
27 changes: 27 additions & 0 deletions clients/rust/src/generated/types/authority.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! 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::Plugin;
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 enum Authority {
Owner,
Permanent {
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
address: Pubkey,
},
SameAs {
plugin: Plugin,
},
}
19 changes: 19 additions & 0 deletions clients/rust/src/generated/types/key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! 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 borsh::BorshDeserialize;
use borsh::BorshSerialize;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Key {
Uninitialized,
Asset,
HashedAsset,
Collection,
HashedCollection,
}
Loading

0 comments on commit 4040e7e

Please sign in to comment.