Skip to content

Commit

Permalink
Changing UA scheme to be an enum of None, Address, or Collection.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Feb 28, 2024
1 parent 401743a commit f938968
Show file tree
Hide file tree
Showing 44 changed files with 462 additions and 410 deletions.
23 changes: 15 additions & 8 deletions clients/js/src/generated/accounts/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,28 @@ import {
string,
struct,
} from '@metaplex-foundation/umi/serializers';
import { Key, KeyArgs, getKeySerializer } from '../types';
import {
Key,
KeyArgs,
UpdateAuthority,
UpdateAuthorityArgs,
getKeySerializer,
getUpdateAuthoritySerializer,
} from '../types';

export type Asset = Account<AssetAccountData>;

export type AssetAccountData = {
key: Key;
updateAuthority: PublicKey;
owner: PublicKey;
updateAuthority: UpdateAuthority;
name: string;
uri: string;
};

export type AssetAccountDataArgs = {
updateAuthority: PublicKey;
owner: PublicKey;
updateAuthority: UpdateAuthorityArgs;
name: string;
uri: string;
};
Expand All @@ -53,8 +60,8 @@ export function getAssetAccountDataSerializer(): Serializer<
struct<AssetAccountData>(
[
['key', getKeySerializer()],
['updateAuthority', publicKeySerializer()],
['owner', publicKeySerializer()],
['updateAuthority', getUpdateAuthoritySerializer()],
['name', string()],
['uri', string()],
],
Expand Down Expand Up @@ -130,15 +137,15 @@ export function getAssetGpaBuilder(context: Pick<Context, 'rpc' | 'programs'>) {
return gpaBuilder(context, programId)
.registerFields<{
key: KeyArgs;
updateAuthority: PublicKey;
owner: PublicKey;
updateAuthority: UpdateAuthorityArgs;
name: string;
uri: string;
}>({
key: [0, getKeySerializer()],
updateAuthority: [1, publicKeySerializer()],
owner: [33, publicKeySerializer()],
name: [65, string()],
owner: [1, publicKeySerializer()],
updateAuthority: [33, getUpdateAuthoritySerializer()],
name: [null, string()],
uri: [null, string()],
})
.deserializeUsing<Asset>((account) => deserializeAsset(account))
Expand Down
13 changes: 13 additions & 0 deletions clients/js/src/generated/errors/mplCoreProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,19 @@ export class AlreadyDecompressedError extends ProgramError {
codeToErrorMap.set(0x12, AlreadyDecompressedError);
nameToErrorMap.set('AlreadyDecompressed', AlreadyDecompressedError);

/** InvalidCollection: Invalid Collection passed in */
export class InvalidCollectionError extends ProgramError {
readonly name: string = 'InvalidCollection';

readonly code: number = 0x13; // 19

constructor(program: Program, cause?: Error) {
super('Invalid Collection passed in', program, cause);
}
}
codeToErrorMap.set(0x13, InvalidCollectionError);
nameToErrorMap.set('InvalidCollection', InvalidCollectionError);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
32 changes: 0 additions & 32 deletions clients/js/src/generated/types/collection.ts

This file was deleted.

15 changes: 11 additions & 4 deletions clients/js/src/generated/types/compressionProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@ import {
string,
struct,
} from '@metaplex-foundation/umi/serializers';
import { Key, KeyArgs, getKeySerializer } from '.';
import {
Key,
KeyArgs,
UpdateAuthority,
UpdateAuthorityArgs,
getKeySerializer,
getUpdateAuthoritySerializer,
} from '.';

export type CompressionProof = {
key: Key;
updateAuthority: PublicKey;
owner: PublicKey;
updateAuthority: UpdateAuthority;
name: string;
uri: string;
};

export type CompressionProofArgs = {
key: KeyArgs;
updateAuthority: PublicKey;
owner: PublicKey;
updateAuthority: UpdateAuthorityArgs;
name: string;
uri: string;
};
Expand All @@ -38,8 +45,8 @@ export function getCompressionProofSerializer(): Serializer<
return struct<CompressionProof>(
[
['key', getKeySerializer()],
['updateAuthority', publicKeySerializer()],
['owner', publicKeySerializer()],
['updateAuthority', getUpdateAuthoritySerializer()],
['name', string()],
['uri', string()],
],
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

export * from './authority';
export * from './burn';
export * from './collection';
export * from './compressionProof';
export * from './creator';
export * from './dataState';
Expand All @@ -24,4 +23,5 @@ export * from './registryRecord';
export * from './royalties';
export * from './ruleSet';
export * from './transfer';
export * from './updateAuthority';
export * from './updateDelegate';
15 changes: 0 additions & 15 deletions clients/js/src/generated/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {
import {
Burn,
BurnArgs,
Collection,
CollectionArgs,
Freeze,
FreezeArgs,
Royalties,
Expand All @@ -29,7 +27,6 @@ import {
UpdateDelegate,
UpdateDelegateArgs,
getBurnSerializer,
getCollectionSerializer,
getFreezeSerializer,
getRoyaltiesSerializer,
getTransferSerializer,
Expand All @@ -42,7 +39,6 @@ export type Plugin =
| { __kind: 'Freeze'; fields: [Freeze] }
| { __kind: 'Burn'; fields: [Burn] }
| { __kind: 'Transfer'; fields: [Transfer] }
| { __kind: 'Collection'; fields: [Collection] }
| { __kind: 'UpdateDelegate'; fields: [UpdateDelegate] };

export type PluginArgs =
Expand All @@ -51,7 +47,6 @@ export type PluginArgs =
| { __kind: 'Freeze'; fields: [FreezeArgs] }
| { __kind: 'Burn'; fields: [BurnArgs] }
| { __kind: 'Transfer'; fields: [TransferArgs] }
| { __kind: 'Collection'; fields: [CollectionArgs] }
| { __kind: 'UpdateDelegate'; fields: [UpdateDelegateArgs] };

export function getPluginSerializer(): Serializer<PluginArgs, Plugin> {
Expand Down Expand Up @@ -82,12 +77,6 @@ export function getPluginSerializer(): Serializer<PluginArgs, Plugin> {
['fields', tuple([getTransferSerializer()])],
]),
],
[
'Collection',
struct<GetDataEnumKindContent<Plugin, 'Collection'>>([
['fields', tuple([getCollectionSerializer()])],
]),
],
[
'UpdateDelegate',
struct<GetDataEnumKindContent<Plugin, 'UpdateDelegate'>>([
Expand Down Expand Up @@ -119,10 +108,6 @@ export function plugin(
kind: 'Transfer',
data: GetDataEnumKindContent<PluginArgs, 'Transfer'>['fields']
): GetDataEnumKind<PluginArgs, 'Transfer'>;
export function plugin(
kind: 'Collection',
data: GetDataEnumKindContent<PluginArgs, 'Collection'>['fields']
): GetDataEnumKind<PluginArgs, 'Collection'>;
export function plugin(
kind: 'UpdateDelegate',
data: GetDataEnumKindContent<PluginArgs, 'UpdateDelegate'>['fields']
Expand Down
1 change: 0 additions & 1 deletion clients/js/src/generated/types/pluginType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export enum PluginType {
Freeze,
Burn,
Transfer,
Collection,
UpdateDelegate,
}

Expand Down
77 changes: 77 additions & 0 deletions clients/js/src/generated/types/updateAuthority.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,
tuple,
unit,
} from '@metaplex-foundation/umi/serializers';

export type UpdateAuthority =
| { __kind: 'None' }
| { __kind: 'Address'; fields: [PublicKey] }
| { __kind: 'Collection'; fields: [PublicKey] };

export type UpdateAuthorityArgs = UpdateAuthority;

export function getUpdateAuthoritySerializer(): Serializer<
UpdateAuthorityArgs,
UpdateAuthority
> {
return dataEnum<UpdateAuthority>(
[
['None', unit()],
[
'Address',
struct<GetDataEnumKindContent<UpdateAuthority, 'Address'>>([
['fields', tuple([publicKeySerializer()])],
]),
],
[
'Collection',
struct<GetDataEnumKindContent<UpdateAuthority, 'Collection'>>([
['fields', tuple([publicKeySerializer()])],
]),
],
],
{ description: 'UpdateAuthority' }
) as Serializer<UpdateAuthorityArgs, UpdateAuthority>;
}

// Data Enum Helpers.
export function updateAuthority(
kind: 'None'
): GetDataEnumKind<UpdateAuthorityArgs, 'None'>;
export function updateAuthority(
kind: 'Address',
data: GetDataEnumKindContent<UpdateAuthorityArgs, 'Address'>['fields']
): GetDataEnumKind<UpdateAuthorityArgs, 'Address'>;
export function updateAuthority(
kind: 'Collection',
data: GetDataEnumKindContent<UpdateAuthorityArgs, 'Collection'>['fields']
): GetDataEnumKind<UpdateAuthorityArgs, 'Collection'>;
export function updateAuthority<K extends UpdateAuthorityArgs['__kind']>(
kind: K,
data?: any
): Extract<UpdateAuthorityArgs, { __kind: K }> {
return Array.isArray(data)
? { __kind: kind, fields: data }
: { __kind: kind, ...(data ?? {}) };
}
export function isUpdateAuthority<K extends UpdateAuthority['__kind']>(
kind: K,
value: UpdateAuthority
): value is UpdateAuthority & { __kind: K } {
return value.__kind === kind;
}
14 changes: 13 additions & 1 deletion clients/js/src/hooked/fetchAssetWithPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,29 @@ import {
} from '@metaplex-foundation/umi';
import {
Asset,
Authority,
Plugin,
PluginHeader,
PluginHeaderAccountData,
PluginRegistry,
PluginRegistryAccountData,
deserializeAsset,
getAssetAccountDataSerializer,
getPluginHeaderAccountDataSerializer,
getPluginRegistryAccountDataSerializer,
getPluginSerializer,
} from '../generated';
import { PluginList, PluginWithAuthorities } from '.';

export type PluginWithAuthorities = {
plugin: Plugin;
authorities: Authority[];
};

export type PluginList = {
pluginHeader?: Omit<PluginHeader, 'publicKey' | 'header'>;
plugins?: PluginWithAuthorities[];
pluginRegistry?: Omit<PluginRegistry, 'publicKey' | 'header'>;
};
export type AssetWithPlugins = Asset & PluginList;

export async function fetchAssetWithPlugins(
Expand Down
9 changes: 5 additions & 4 deletions clients/js/test/addAuthority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
create,
fetchAsset,
fetchAssetWithPlugins,
updateAuthority,
} from '../src';
import { createUmi } from './_setup';

Expand All @@ -34,7 +35,7 @@ test('it can add an authority to a plugin', async (t) => {
// console.log("Account State:", asset);
t.like(asset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: umi.identity.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down Expand Up @@ -63,20 +64,20 @@ test('it can add an authority to a plugin', async (t) => {
// console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
t.like(asset1, <AssetWithPlugins>{
publicKey: assetAddress.publicKey,
updateAuthority: umi.identity.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
pluginHeader: {
key: 3,
pluginRegistryOffset: BigInt(119),
pluginRegistryOffset: BigInt(120),
},
pluginRegistry: {
key: 4,
registry: [
{
pluginType: 2,
offset: BigInt(117),
offset: BigInt(118),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
Expand Down
Loading

0 comments on commit f938968

Please sign in to comment.