Skip to content

Commit

Permalink
Merge pull request #1 from metaplex-foundation/danenbm/collapse-regis…
Browse files Browse the repository at this point in the history
…try-record-struct

Danenbm/collapse registry record struct
  • Loading branch information
blockiosaurus authored Feb 27, 2024
2 parents 211f0bb + 908007f commit c98251c
Show file tree
Hide file tree
Showing 25 changed files with 184 additions and 335 deletions.
17 changes: 5 additions & 12 deletions clients/js/src/generated/types/externalPluginRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@
* @see https://github.com/metaplex-foundation/kinobi
*/

import { Serializer, struct } from '@metaplex-foundation/umi/serializers';
import {
Authority,
AuthorityArgs,
RegistryData,
RegistryDataArgs,
getAuthoritySerializer,
getRegistryDataSerializer,
} from '.';
import { Serializer, struct, u64 } from '@metaplex-foundation/umi/serializers';
import { Authority, AuthorityArgs, getAuthoritySerializer } from '.';

export type ExternalPluginRecord = { authority: Authority; data: RegistryData };
export type ExternalPluginRecord = { authority: Authority; offset: bigint };

export type ExternalPluginRecordArgs = {
authority: AuthorityArgs;
data: RegistryDataArgs;
offset: number | bigint;
};

export function getExternalPluginRecordSerializer(): Serializer<
Expand All @@ -30,7 +23,7 @@ export function getExternalPluginRecordSerializer(): Serializer<
return struct<ExternalPluginRecord>(
[
['authority', getAuthoritySerializer()],
['data', getRegistryDataSerializer()],
['offset', u64()],
],
{ description: 'ExternalPluginRecord' }
) as Serializer<ExternalPluginRecordArgs, ExternalPluginRecord>;
Expand Down
1 change: 0 additions & 1 deletion clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export * from './key';
export * from './plugin';
export * from './pluginHash';
export * from './pluginType';
export * from './registryData';
export * from './registryRecord';
export * from './royalties';
export * from './ruleSet';
Expand Down
35 changes: 0 additions & 35 deletions clients/js/src/generated/types/registryData.ts

This file was deleted.

25 changes: 18 additions & 7 deletions clients/js/src/generated/types/registryRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@
* @see https://github.com/metaplex-foundation/kinobi
*/

import { Serializer, struct } from '@metaplex-foundation/umi/serializers';
import {
Serializer,
array,
struct,
u64,
} from '@metaplex-foundation/umi/serializers';
import {
Authority,
AuthorityArgs,
PluginType,
PluginTypeArgs,
RegistryData,
RegistryDataArgs,
getAuthoritySerializer,
getPluginTypeSerializer,
getRegistryDataSerializer,
} from '.';

export type RegistryRecord = { pluginType: PluginType; data: RegistryData };
export type RegistryRecord = {
pluginType: PluginType;
authorities: Array<Authority>;
offset: bigint;
};

export type RegistryRecordArgs = {
pluginType: PluginTypeArgs;
data: RegistryDataArgs;
authorities: Array<AuthorityArgs>;
offset: number | bigint;
};

export function getRegistryRecordSerializer(): Serializer<
Expand All @@ -30,7 +40,8 @@ export function getRegistryRecordSerializer(): Serializer<
return struct<RegistryRecord>(
[
['pluginType', getPluginTypeSerializer()],
['data', getRegistryDataSerializer()],
['authorities', array(getAuthoritySerializer())],
['offset', u64()],
],
{ description: 'RegistryRecord' }
) as Serializer<RegistryRecordArgs, RegistryRecord>;
Expand Down
4 changes: 2 additions & 2 deletions clients/js/src/hooked/fetchAssetWithPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export async function fetchAssetWithPlugins(
plugins = pluginRegistry.registry.map((record) => ({
plugin: getPluginSerializer().deserialize(
maybeAccount.data,
Number(record.data.offset)
Number(record.offset)
)[0],
authorities: record.data.authorities,
authorities: record.authorities,
}));
}

Expand Down
12 changes: 5 additions & 7 deletions clients/js/test/addAuthority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ test('it can add an authority to a plugin', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
],
},
Expand Down
6 changes: 2 additions & 4 deletions clients/js/test/addPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ test('it can add a plugin to an asset', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(117),
authorities: [{ __kind: 'Owner' }],
},
offset: BigInt(117),
authorities: [{ __kind: 'Owner' }],
},
],
},
Expand Down
14 changes: 6 additions & 8 deletions clients/js/test/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('it can create a new asset in account state', async (t) => {
assetAddress,
name: 'Test Bread',
uri: 'https://example.com/bread',
plugins: []
plugins: [],
}).sendAndConfirm(umi);

// Then an account was created with the correct data.
Expand All @@ -51,7 +51,7 @@ test('it can create a new asset in ledger state', async (t) => {
name: 'Test Bread',
uri: 'https://example.com/bread',
logWrapper: publicKey('noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV'),
plugins: []
plugins: [],
}).sendAndConfirm(umi);

// Then an account was created with the correct data.
Expand Down Expand Up @@ -88,7 +88,7 @@ test('it can create a new asset with plugins', async (t) => {
assetAddress,
name: 'Test Bread',
uri: 'https://example.com/bread',
plugins: [{ __kind: 'Freeze', fields: [{ frozen: false }] }]
plugins: [{ __kind: 'Freeze', fields: [{ frozen: false }] }],
}).sendAndConfirm(umi);

// Then an account was created with the correct data.
Expand All @@ -109,10 +109,8 @@ test('it can create a new asset with plugins', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(117),
authorities: [{ __kind: 'Owner' }],
},
offset: BigInt(117),
authorities: [{ __kind: 'Owner' }],
},
],
},
Expand All @@ -126,4 +124,4 @@ test('it can create a new asset with plugins', async (t) => {
},
],
});
});
});
24 changes: 10 additions & 14 deletions clients/js/test/delegate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ test('it can delegate a new authority', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
],
},
Expand Down Expand Up @@ -144,13 +142,11 @@ test('a delegate can freeze the token', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
],
},
Expand Down
12 changes: 5 additions & 7 deletions clients/js/test/delegateTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ test('a delegate can transfer the asset', async (t) => {
registry: [
{
pluginType: PluginType.Transfer,
data: {
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
],
},
Expand Down
24 changes: 9 additions & 15 deletions clients/js/test/removeAuthority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ test('it can remove an authority from a plugin', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
offset: BigInt(117),
authorities: [
{ __kind: 'Owner' },
{ __kind: 'Pubkey', address: delegateAddress.publicKey },
],
},
],
},
Expand Down Expand Up @@ -127,10 +125,8 @@ test('it can remove an authority from a plugin', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(117),
authorities: [{ __kind: 'Owner' }],
},
offset: BigInt(117),
authorities: [{ __kind: 'Owner' }],
},
],
},
Expand Down Expand Up @@ -204,10 +200,8 @@ test('it can remove the default authority from a plugin to make it immutable', a
registry: [
{
pluginType: 2,
data: {
offset: BigInt(117),
authorities: [{ __kind: 'None' }],
},
offset: BigInt(117),
authorities: [{ __kind: 'None' }],
},
],
},
Expand Down
6 changes: 2 additions & 4 deletions clients/js/test/removePlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ test('it can remove a plugin from an asset', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(117),
authorities: [{ __kind: 'Owner' }],
},
offset: BigInt(117),
authorities: [{ __kind: 'Owner' }],
},
],
},
Expand Down
12 changes: 4 additions & 8 deletions clients/js/test/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ test('it can update an asset with plugins to be larger', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(120),
authorities: [{ __kind: 'Owner' }],
},
offset: BigInt(120),
authorities: [{ __kind: 'Owner' }],
},
],
},
Expand Down Expand Up @@ -184,10 +182,8 @@ test('it can update an asset with plugins to be smaller', async (t) => {
registry: [
{
pluginType: 2,
data: {
offset: BigInt(82),
authorities: [{ __kind: 'Owner' }],
},
offset: BigInt(82),
authorities: [{ __kind: 'Owner' }],
},
],
},
Expand Down
3 changes: 1 addition & 2 deletions clients/rust/src/generated/types/external_plugin_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
//!
use crate::generated::types::Authority;
use crate::generated::types::RegistryData;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ExternalPluginRecord {
pub authority: Authority,
pub data: RegistryData,
pub offset: u64,
}
2 changes: 0 additions & 2 deletions clients/rust/src/generated/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub(crate) mod key;
pub(crate) mod plugin;
pub(crate) mod plugin_hash;
pub(crate) mod plugin_type;
pub(crate) mod registry_data;
pub(crate) mod registry_record;
pub(crate) mod royalties;
pub(crate) mod rule_set;
Expand All @@ -39,7 +38,6 @@ pub use self::key::*;
pub use self::plugin::*;
pub use self::plugin_hash::*;
pub use self::plugin_type::*;
pub use self::registry_data::*;
pub use self::registry_record::*;
pub use self::royalties::*;
pub use self::rule_set::*;
Expand Down
Loading

0 comments on commit c98251c

Please sign in to comment.