Skip to content

Commit

Permalink
Adding working delegate.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Feb 19, 2024
1 parent 23ba4c6 commit 747eafb
Show file tree
Hide file tree
Showing 23 changed files with 244 additions and 110 deletions.
15 changes: 5 additions & 10 deletions clients/js/src/generated/types/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@
*/

import { Serializer, bool, struct } from '@metaplex-foundation/umi/serializers';
import { Key, KeyArgs, getKeySerializer } from '.';

export type Delegate = { key: Key; frozen: boolean };
export type Delegate = { frozen: boolean };

export type DelegateArgs = { key: KeyArgs; frozen: boolean };
export type DelegateArgs = Delegate;

export function getDelegateSerializer(): Serializer<DelegateArgs, Delegate> {
return struct<Delegate>(
[
['key', getKeySerializer()],
['frozen', bool()],
],
{ description: 'Delegate' }
) as Serializer<DelegateArgs, Delegate>;
return struct<Delegate>([['frozen', bool()]], {
description: 'Delegate',
}) as Serializer<DelegateArgs, Delegate>;
}
1 change: 1 addition & 0 deletions clients/js/src/generated/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from './extraAccounts';
export * from './key';
export * from './migrationLevel';
export * from './plugin';
export * from './pluginType';
export * from './registryData';
export * from './registryRecord';
export * from './royalties';
3 changes: 0 additions & 3 deletions clients/js/src/generated/types/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ export enum Key {
Uninitialized,
Asset,
HashedAsset,
Collection,
HashedCollection,
PluginHeader,
PluginRegistry,
Delegate,
}

export type KeyArgs = Key;
Expand Down
23 changes: 18 additions & 5 deletions clients/js/src/generated/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,35 @@ import {
tuple,
unit,
} from '@metaplex-foundation/umi/serializers';
import { Delegate, DelegateArgs, getDelegateSerializer } from '.';
import {
Delegate,
DelegateArgs,
Royalties,
RoyaltiesArgs,
getDelegateSerializer,
getRoyaltiesSerializer,
} from '.';

export type Plugin =
| { __kind: 'Reserved' }
| { __kind: 'Royalties' }
| { __kind: 'Royalties'; fields: [Royalties] }
| { __kind: 'Delegate'; fields: [Delegate] };

export type PluginArgs =
| { __kind: 'Reserved' }
| { __kind: 'Royalties' }
| { __kind: 'Royalties'; fields: [RoyaltiesArgs] }
| { __kind: 'Delegate'; fields: [DelegateArgs] };

export function getPluginSerializer(): Serializer<PluginArgs, Plugin> {
return dataEnum<Plugin>(
[
['Reserved', unit()],
['Royalties', unit()],
[
'Royalties',
struct<GetDataEnumKindContent<Plugin, 'Royalties'>>([
['fields', tuple([getRoyaltiesSerializer()])],
]),
],
[
'Delegate',
struct<GetDataEnumKindContent<Plugin, 'Delegate'>>([
Expand All @@ -48,7 +60,8 @@ export function plugin(
kind: 'Reserved'
): GetDataEnumKind<PluginArgs, 'Reserved'>;
export function plugin(
kind: 'Royalties'
kind: 'Royalties',
data: GetDataEnumKindContent<PluginArgs, 'Royalties'>['fields']
): GetDataEnumKind<PluginArgs, 'Royalties'>;
export function plugin(
kind: 'Delegate',
Expand Down
26 changes: 26 additions & 0 deletions clients/js/src/generated/types/pluginType.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 PluginType {
Reserved,
Royalties,
Delegate,
}

export type PluginTypeArgs = PluginType;

export function getPluginTypeSerializer(): Serializer<
PluginTypeArgs,
PluginType
> {
return scalarEnum<PluginType>(PluginType, {
description: 'PluginType',
}) as Serializer<PluginTypeArgs, PluginType>;
}
15 changes: 9 additions & 6 deletions clients/js/src/generated/types/registryRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@

import { Serializer, struct } from '@metaplex-foundation/umi/serializers';
import {
Key,
KeyArgs,
PluginType,
PluginTypeArgs,
RegistryData,
RegistryDataArgs,
getKeySerializer,
getPluginTypeSerializer,
getRegistryDataSerializer,
} from '.';

export type RegistryRecord = { key: Key; data: RegistryData };
export type RegistryRecord = { pluginType: PluginType; data: RegistryData };

export type RegistryRecordArgs = { key: KeyArgs; data: RegistryDataArgs };
export type RegistryRecordArgs = {
pluginType: PluginTypeArgs;
data: RegistryDataArgs;
};

export function getRegistryRecordSerializer(): Serializer<
RegistryRecordArgs,
RegistryRecord
> {
return struct<RegistryRecord>(
[
['key', getKeySerializer()],
['pluginType', getPluginTypeSerializer()],
['data', getRegistryDataSerializer()],
],
{ description: 'RegistryRecord' }
Expand Down
6 changes: 3 additions & 3 deletions clients/js/test/delegate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
getAssetAccountDataSerializer,
getDelegateSerializer,
getPluginHeaderAccountDataSerializer,
getPluginRegistryAccountDataSerializer
getPluginRegistryAccountDataSerializer,
PluginType,
} from '../src';
import { createUmi } from './_setup';

Expand Down Expand Up @@ -58,7 +59,7 @@ test('it can delegate a new authority', async (t) => {
t.like(pluginRegistry, <PluginRegistryAccountData>{
key: Key.PluginRegistry,
registry: [<RegistryRecord>{
key: Key.Delegate,
pluginType: PluginType.Delegate,
data: <RegistryData>{
offset: BigInt(117),
authorities: [<Authority>{ __kind: 'Pubkey', address: delegateAddress.publicKey }],
Expand All @@ -69,7 +70,6 @@ test('it can delegate a new authority', async (t) => {
const delegatePlugin = getDelegateSerializer().deserialize(pluginData.data, Number(pluginRegistry.registry[0].data.offset))[0];
// console.log(delegatePlugin);
t.like(delegatePlugin, <Delegate>{
key: Key.Delegate,
frozen: false,
});
} else {
Expand Down
56 changes: 56 additions & 0 deletions clients/js/test/delegateTransfer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { generateSigner } from '@metaplex-foundation/umi';
import test from 'ava';
// import { base58 } from '@metaplex-foundation/umi/serializers';
import { Asset, DataState, create, delegate, fetchAsset, transfer } from '../src';
import { createUmi } from './_setup';

test('it can transfer an asset as the delegate', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const assetAddress = generateSigner(umi);
const newOwner = generateSigner(umi);
const delegateAddress = generateSigner(umi);

// When we create a new account.
await create(umi, {
dataState: DataState.AccountState,
assetAddress,
name: 'Test Bread',
uri: 'https://example.com/bread',
}).sendAndConfirm(umi);

// Then an account was created with the correct data.
const beforeAsset = await fetchAsset(umi, assetAddress.publicKey);
// console.log("Account State:", beforeAsset);
t.like(beforeAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: umi.identity.publicKey,
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
});

await delegate(umi, {
assetAddress: assetAddress.publicKey,
owner: umi.identity,
delegate: delegateAddress.publicKey
}).sendAndConfirm(umi);

await transfer(umi, {
assetAddress: assetAddress.publicKey,
newOwner: newOwner.publicKey,
authority: delegateAddress,
compressionProof: null
}).sendAndConfirm(umi);

const afterAsset = await fetchAsset(umi, assetAddress.publicKey);
// console.log("Account State:", afterAsset);
t.like(afterAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: umi.identity.publicKey,
owner: newOwner.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
});
});

2 changes: 0 additions & 2 deletions clients/rust/src/generated/types/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
//! [https://github.com/metaplex-foundation/kinobi]
//!
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 Delegate {
pub key: Key,
pub frozen: bool,
}
3 changes: 0 additions & 3 deletions clients/rust/src/generated/types/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ pub enum Key {
Uninitialized,
Asset,
HashedAsset,
Collection,
HashedCollection,
PluginHeader,
PluginRegistry,
Delegate,
}
2 changes: 2 additions & 0 deletions clients/rust/src/generated/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) mod extra_accounts;
pub(crate) mod key;
pub(crate) mod migration_level;
pub(crate) mod plugin;
pub(crate) mod plugin_type;
pub(crate) mod registry_data;
pub(crate) mod registry_record;
pub(crate) mod royalties;
Expand All @@ -31,6 +32,7 @@ pub use self::extra_accounts::*;
pub use self::key::*;
pub use self::migration_level::*;
pub use self::plugin::*;
pub use self::plugin_type::*;
pub use self::registry_data::*;
pub use self::registry_record::*;
pub use self::royalties::*;
3 changes: 2 additions & 1 deletion clients/rust/src/generated/types/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
//!
use crate::generated::types::Delegate;
use crate::generated::types::Royalties;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Plugin {
Reserved,
Royalties,
Royalties(Royalties),
Delegate(Delegate),
}
17 changes: 17 additions & 0 deletions clients/rust/src/generated/types/plugin_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! 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 PluginType {
Reserved,
Royalties,
Delegate,
}
4 changes: 2 additions & 2 deletions clients/rust/src/generated/types/registry_record.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::Key;
use crate::generated::types::PluginType;
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 RegistryRecord {
pub key: Key,
pub plugin_type: PluginType,
pub data: RegistryData,
}
Loading

0 comments on commit 747eafb

Please sign in to comment.