From 8c6b10706a96b4a63ce7b19ce5e0d1a92bd6fea0 Mon Sep 17 00:00:00 2001 From: blockiosaurus Date: Mon, 26 Feb 2024 07:31:04 -0500 Subject: [PATCH] Prettier fix. --- .../js/src/hooked/fetchAssetWithPlugins.ts | 115 ++++++++++-------- clients/js/test/update.test.ts | 84 +++++++------ 2 files changed, 112 insertions(+), 87 deletions(-) diff --git a/clients/js/src/hooked/fetchAssetWithPlugins.ts b/clients/js/src/hooked/fetchAssetWithPlugins.ts index d311b8a8..7b4a68ed 100644 --- a/clients/js/src/hooked/fetchAssetWithPlugins.ts +++ b/clients/js/src/hooked/fetchAssetWithPlugins.ts @@ -1,69 +1,78 @@ import { - Context, - Pda, - PublicKey, - RpcGetAccountOptions, - assertAccountExists, - publicKey as toPublicKey -} from "@metaplex-foundation/umi"; + Context, + Pda, + PublicKey, + RpcGetAccountOptions, + assertAccountExists, + publicKey as toPublicKey, +} from '@metaplex-foundation/umi'; import { - Asset, - Authority, - Plugin, - PluginHeader, - PluginHeaderAccountData, - PluginRegistry, - PluginRegistryAccountData, - deserializeAsset, - getAssetAccountDataSerializer, - getPluginHeaderAccountDataSerializer, - getPluginRegistryAccountDataSerializer, - getPluginSerializer -} from "../generated"; + Asset, + Authority, + Plugin, + PluginHeader, + PluginHeaderAccountData, + PluginRegistry, + PluginRegistryAccountData, + deserializeAsset, + getAssetAccountDataSerializer, + getPluginHeaderAccountDataSerializer, + getPluginRegistryAccountDataSerializer, + getPluginSerializer, +} from '../generated'; export type PluginWithAuthorities = { - plugin: Plugin; - authorities: Authority[]; + plugin: Plugin; + authorities: Authority[]; }; export type PluginList = { - pluginHeader?: Omit, - plugins?: PluginWithAuthorities[], - pluginRegistry?: Omit, + pluginHeader?: Omit; + plugins?: PluginWithAuthorities[]; + pluginRegistry?: Omit; }; export type AssetWithPlugins = Asset & PluginList; export async function fetchAssetWithPlugins( - context: Pick, - publicKey: PublicKey | Pda, - options?: RpcGetAccountOptions + context: Pick, + publicKey: PublicKey | Pda, + options?: RpcGetAccountOptions ): Promise { - const maybeAccount = await context.rpc.getAccount( - toPublicKey(publicKey, false), - options - ); - assertAccountExists(maybeAccount, 'Asset'); - const asset = deserializeAsset(maybeAccount); - const assetData = getAssetAccountDataSerializer().serialize(asset); + const maybeAccount = await context.rpc.getAccount( + toPublicKey(publicKey, false), + options + ); + assertAccountExists(maybeAccount, 'Asset'); + const asset = deserializeAsset(maybeAccount); + const assetData = getAssetAccountDataSerializer().serialize(asset); - let pluginHeader: PluginHeaderAccountData | undefined; - let pluginRegistry: PluginRegistryAccountData | undefined; - let plugins: PluginWithAuthorities[] | undefined; - if (maybeAccount.data.length !== assetData.length) { - [pluginHeader] = getPluginHeaderAccountDataSerializer().deserialize(maybeAccount.data, assetData.length); - [pluginRegistry] = getPluginRegistryAccountDataSerializer().deserialize(maybeAccount.data, Number(pluginHeader.pluginRegistryOffset)); - plugins = pluginRegistry.registry.map((record) => ({ - plugin: getPluginSerializer().deserialize(maybeAccount.data, Number(record.data.offset))[0], - authorities: record.data.authorities, - })); - } + let pluginHeader: PluginHeaderAccountData | undefined; + let pluginRegistry: PluginRegistryAccountData | undefined; + let plugins: PluginWithAuthorities[] | undefined; + if (maybeAccount.data.length !== assetData.length) { + [pluginHeader] = getPluginHeaderAccountDataSerializer().deserialize( + maybeAccount.data, + assetData.length + ); + [pluginRegistry] = getPluginRegistryAccountDataSerializer().deserialize( + maybeAccount.data, + Number(pluginHeader.pluginRegistryOffset) + ); + plugins = pluginRegistry.registry.map((record) => ({ + plugin: getPluginSerializer().deserialize( + maybeAccount.data, + Number(record.data.offset) + )[0], + authorities: record.data.authorities, + })); + } - const assetWithPlugins: AssetWithPlugins = { - pluginHeader, - plugins, - pluginRegistry, - ...asset, - }; + const assetWithPlugins: AssetWithPlugins = { + pluginHeader, + plugins, + pluginRegistry, + ...asset, + }; - return assetWithPlugins; + return assetWithPlugins; } diff --git a/clients/js/test/update.test.ts b/clients/js/test/update.test.ts index da69061c..b92cb89a 100644 --- a/clients/js/test/update.test.ts +++ b/clients/js/test/update.test.ts @@ -1,7 +1,15 @@ import { generateSigner } from '@metaplex-foundation/umi'; import test from 'ava'; // import { base58 } from '@metaplex-foundation/umi/serializers'; -import { AssetWithPlugins, DataState, Key, addPlugin, create, fetchAssetWithPlugins, update } from '../src'; +import { + AssetWithPlugins, + DataState, + Key, + addPlugin, + create, + fetchAssetWithPlugins, + update, +} from '../src'; import { createUmi } from './_setup'; test('it can update an asset to be larger', async (t) => { @@ -29,8 +37,8 @@ test('it can update an asset to be larger', async (t) => { key: Key.Asset, updateAuthority: umi.identity.publicKey, owner: umi.identity.publicKey, - name: "Test Bread 2", - uri: "https://example.com/bread2" + name: 'Test Bread 2', + uri: 'https://example.com/bread2', }); }); @@ -59,8 +67,8 @@ test('it can update an asset to be smaller', async (t) => { key: Key.Asset, updateAuthority: umi.identity.publicKey, owner: umi.identity.publicKey, - name: "", - uri: "" + name: '', + uri: '', }); }); @@ -82,7 +90,7 @@ test('it can update an asset with plugins to be larger', async (t) => { plugin: { __kind: 'Freeze', fields: [{ frozen: false }], - } + }, }).sendAndConfirm(umi); await update(umi, { @@ -106,21 +114,25 @@ test('it can update an asset with plugins to be larger', async (t) => { }, pluginRegistry: { key: 4, - registry: [{ - pluginType: 2, - data: { - offset: BigInt(120), - authorities: [{ __kind: "Owner" }] - } - }], + registry: [ + { + pluginType: 2, + data: { + offset: BigInt(120), + authorities: [{ __kind: 'Owner' }], + }, + }, + ], }, - plugins: [{ - authorities: [{ __kind: "Owner" }], - plugin: { - __kind: 'Freeze', - fields: [{ frozen: false }], + plugins: [ + { + authorities: [{ __kind: 'Owner' }], + plugin: { + __kind: 'Freeze', + fields: [{ frozen: false }], + }, }, - }], + ], }); }); @@ -142,7 +154,7 @@ test('it can update an asset with plugins to be smaller', async (t) => { plugin: { __kind: 'Freeze', fields: [{ frozen: false }], - } + }, }).sendAndConfirm(umi); await update(umi, { @@ -165,20 +177,24 @@ test('it can update an asset with plugins to be smaller', async (t) => { }, pluginRegistry: { key: 4, - registry: [{ - pluginType: 2, - data: { - offset: BigInt(82), - authorities: [{ __kind: "Owner" }] - } - }], + registry: [ + { + pluginType: 2, + data: { + offset: BigInt(82), + authorities: [{ __kind: 'Owner' }], + }, + }, + ], }, - plugins: [{ - authorities: [{ __kind: "Owner" }], - plugin: { - __kind: 'Freeze', - fields: [{ frozen: false }], + plugins: [ + { + authorities: [{ __kind: 'Owner' }], + plugin: { + __kind: 'Freeze', + fields: [{ frozen: false }], + }, }, - }], + ], }); -}); \ No newline at end of file +});