Skip to content

Commit 885328d

Browse files
committed
Working basic delegate.
1 parent 99f16c6 commit 885328d

30 files changed

+721
-198
lines changed

clients/js/src/generated/accounts/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88

99
export * from './asset';
1010
export * from './hashedAsset';
11+
export * from './pluginHeader';
12+
export * from './pluginRegistry';
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* This code was AUTOGENERATED using the kinobi library.
3+
* Please DO NOT EDIT THIS FILE, instead use visitors
4+
* to add features, then rerun kinobi to update it.
5+
*
6+
* @see https://github.com/metaplex-foundation/kinobi
7+
*/
8+
9+
import {
10+
Account,
11+
Context,
12+
Pda,
13+
PublicKey,
14+
RpcAccount,
15+
RpcGetAccountOptions,
16+
RpcGetAccountsOptions,
17+
assertAccountExists,
18+
deserializeAccount,
19+
gpaBuilder,
20+
publicKey as toPublicKey,
21+
} from '@metaplex-foundation/umi';
22+
import { Serializer, struct, u64 } from '@metaplex-foundation/umi/serializers';
23+
import { Key, KeyArgs, getKeySerializer } from '../types';
24+
25+
export type PluginHeader = Account<PluginHeaderAccountData>;
26+
27+
export type PluginHeaderAccountData = {
28+
key: Key;
29+
pluginRegistryOffset: bigint;
30+
};
31+
32+
export type PluginHeaderAccountDataArgs = {
33+
key: KeyArgs;
34+
pluginRegistryOffset: number | bigint;
35+
};
36+
37+
export function getPluginHeaderAccountDataSerializer(): Serializer<
38+
PluginHeaderAccountDataArgs,
39+
PluginHeaderAccountData
40+
> {
41+
return struct<PluginHeaderAccountData>(
42+
[
43+
['key', getKeySerializer()],
44+
['pluginRegistryOffset', u64()],
45+
],
46+
{ description: 'PluginHeaderAccountData' }
47+
) as Serializer<PluginHeaderAccountDataArgs, PluginHeaderAccountData>;
48+
}
49+
50+
export function deserializePluginHeader(rawAccount: RpcAccount): PluginHeader {
51+
return deserializeAccount(rawAccount, getPluginHeaderAccountDataSerializer());
52+
}
53+
54+
export async function fetchPluginHeader(
55+
context: Pick<Context, 'rpc'>,
56+
publicKey: PublicKey | Pda,
57+
options?: RpcGetAccountOptions
58+
): Promise<PluginHeader> {
59+
const maybeAccount = await context.rpc.getAccount(
60+
toPublicKey(publicKey, false),
61+
options
62+
);
63+
assertAccountExists(maybeAccount, 'PluginHeader');
64+
return deserializePluginHeader(maybeAccount);
65+
}
66+
67+
export async function safeFetchPluginHeader(
68+
context: Pick<Context, 'rpc'>,
69+
publicKey: PublicKey | Pda,
70+
options?: RpcGetAccountOptions
71+
): Promise<PluginHeader | null> {
72+
const maybeAccount = await context.rpc.getAccount(
73+
toPublicKey(publicKey, false),
74+
options
75+
);
76+
return maybeAccount.exists ? deserializePluginHeader(maybeAccount) : null;
77+
}
78+
79+
export async function fetchAllPluginHeader(
80+
context: Pick<Context, 'rpc'>,
81+
publicKeys: Array<PublicKey | Pda>,
82+
options?: RpcGetAccountsOptions
83+
): Promise<PluginHeader[]> {
84+
const maybeAccounts = await context.rpc.getAccounts(
85+
publicKeys.map((key) => toPublicKey(key, false)),
86+
options
87+
);
88+
return maybeAccounts.map((maybeAccount) => {
89+
assertAccountExists(maybeAccount, 'PluginHeader');
90+
return deserializePluginHeader(maybeAccount);
91+
});
92+
}
93+
94+
export async function safeFetchAllPluginHeader(
95+
context: Pick<Context, 'rpc'>,
96+
publicKeys: Array<PublicKey | Pda>,
97+
options?: RpcGetAccountsOptions
98+
): Promise<PluginHeader[]> {
99+
const maybeAccounts = await context.rpc.getAccounts(
100+
publicKeys.map((key) => toPublicKey(key, false)),
101+
options
102+
);
103+
return maybeAccounts
104+
.filter((maybeAccount) => maybeAccount.exists)
105+
.map((maybeAccount) => deserializePluginHeader(maybeAccount as RpcAccount));
106+
}
107+
108+
export function getPluginHeaderGpaBuilder(
109+
context: Pick<Context, 'rpc' | 'programs'>
110+
) {
111+
const programId = context.programs.getPublicKey(
112+
'mplAsset',
113+
'ASSETp3DinZKfiAyvdQG16YWWLJ2X3ZKjg9zku7n1sZD'
114+
);
115+
return gpaBuilder(context, programId)
116+
.registerFields<{ key: KeyArgs; pluginRegistryOffset: number | bigint }>({
117+
key: [0, getKeySerializer()],
118+
pluginRegistryOffset: [1, u64()],
119+
})
120+
.deserializeUsing<PluginHeader>((account) =>
121+
deserializePluginHeader(account)
122+
);
123+
}
124+
125+
export function getPluginHeaderSize(): number {
126+
return 9;
127+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/**
2+
* This code was AUTOGENERATED using the kinobi library.
3+
* Please DO NOT EDIT THIS FILE, instead use visitors
4+
* to add features, then rerun kinobi to update it.
5+
*
6+
* @see https://github.com/metaplex-foundation/kinobi
7+
*/
8+
9+
import {
10+
Account,
11+
Context,
12+
Pda,
13+
PublicKey,
14+
RpcAccount,
15+
RpcGetAccountOptions,
16+
RpcGetAccountsOptions,
17+
assertAccountExists,
18+
deserializeAccount,
19+
gpaBuilder,
20+
publicKey as toPublicKey,
21+
} from '@metaplex-foundation/umi';
22+
import {
23+
Serializer,
24+
array,
25+
struct,
26+
} from '@metaplex-foundation/umi/serializers';
27+
import {
28+
ExternalPluginRecord,
29+
ExternalPluginRecordArgs,
30+
Key,
31+
KeyArgs,
32+
RegistryRecord,
33+
RegistryRecordArgs,
34+
getExternalPluginRecordSerializer,
35+
getKeySerializer,
36+
getRegistryRecordSerializer,
37+
} from '../types';
38+
39+
export type PluginRegistry = Account<PluginRegistryAccountData>;
40+
41+
export type PluginRegistryAccountData = {
42+
key: Key;
43+
registry: Array<RegistryRecord>;
44+
externalPlugins: Array<ExternalPluginRecord>;
45+
};
46+
47+
export type PluginRegistryAccountDataArgs = {
48+
key: KeyArgs;
49+
registry: Array<RegistryRecordArgs>;
50+
externalPlugins: Array<ExternalPluginRecordArgs>;
51+
};
52+
53+
export function getPluginRegistryAccountDataSerializer(): Serializer<
54+
PluginRegistryAccountDataArgs,
55+
PluginRegistryAccountData
56+
> {
57+
return struct<PluginRegistryAccountData>(
58+
[
59+
['key', getKeySerializer()],
60+
['registry', array(getRegistryRecordSerializer())],
61+
['externalPlugins', array(getExternalPluginRecordSerializer())],
62+
],
63+
{ description: 'PluginRegistryAccountData' }
64+
) as Serializer<PluginRegistryAccountDataArgs, PluginRegistryAccountData>;
65+
}
66+
67+
export function deserializePluginRegistry(
68+
rawAccount: RpcAccount
69+
): PluginRegistry {
70+
return deserializeAccount(
71+
rawAccount,
72+
getPluginRegistryAccountDataSerializer()
73+
);
74+
}
75+
76+
export async function fetchPluginRegistry(
77+
context: Pick<Context, 'rpc'>,
78+
publicKey: PublicKey | Pda,
79+
options?: RpcGetAccountOptions
80+
): Promise<PluginRegistry> {
81+
const maybeAccount = await context.rpc.getAccount(
82+
toPublicKey(publicKey, false),
83+
options
84+
);
85+
assertAccountExists(maybeAccount, 'PluginRegistry');
86+
return deserializePluginRegistry(maybeAccount);
87+
}
88+
89+
export async function safeFetchPluginRegistry(
90+
context: Pick<Context, 'rpc'>,
91+
publicKey: PublicKey | Pda,
92+
options?: RpcGetAccountOptions
93+
): Promise<PluginRegistry | null> {
94+
const maybeAccount = await context.rpc.getAccount(
95+
toPublicKey(publicKey, false),
96+
options
97+
);
98+
return maybeAccount.exists ? deserializePluginRegistry(maybeAccount) : null;
99+
}
100+
101+
export async function fetchAllPluginRegistry(
102+
context: Pick<Context, 'rpc'>,
103+
publicKeys: Array<PublicKey | Pda>,
104+
options?: RpcGetAccountsOptions
105+
): Promise<PluginRegistry[]> {
106+
const maybeAccounts = await context.rpc.getAccounts(
107+
publicKeys.map((key) => toPublicKey(key, false)),
108+
options
109+
);
110+
return maybeAccounts.map((maybeAccount) => {
111+
assertAccountExists(maybeAccount, 'PluginRegistry');
112+
return deserializePluginRegistry(maybeAccount);
113+
});
114+
}
115+
116+
export async function safeFetchAllPluginRegistry(
117+
context: Pick<Context, 'rpc'>,
118+
publicKeys: Array<PublicKey | Pda>,
119+
options?: RpcGetAccountsOptions
120+
): Promise<PluginRegistry[]> {
121+
const maybeAccounts = await context.rpc.getAccounts(
122+
publicKeys.map((key) => toPublicKey(key, false)),
123+
options
124+
);
125+
return maybeAccounts
126+
.filter((maybeAccount) => maybeAccount.exists)
127+
.map((maybeAccount) =>
128+
deserializePluginRegistry(maybeAccount as RpcAccount)
129+
);
130+
}
131+
132+
export function getPluginRegistryGpaBuilder(
133+
context: Pick<Context, 'rpc' | 'programs'>
134+
) {
135+
const programId = context.programs.getPublicKey(
136+
'mplAsset',
137+
'ASSETp3DinZKfiAyvdQG16YWWLJ2X3ZKjg9zku7n1sZD'
138+
);
139+
return gpaBuilder(context, programId)
140+
.registerFields<{
141+
key: KeyArgs;
142+
registry: Array<RegistryRecordArgs>;
143+
externalPlugins: Array<ExternalPluginRecordArgs>;
144+
}>({
145+
key: [0, getKeySerializer()],
146+
registry: [1, array(getRegistryRecordSerializer())],
147+
externalPlugins: [null, array(getExternalPluginRecordSerializer())],
148+
})
149+
.deserializeUsing<PluginRegistry>((account) =>
150+
deserializePluginRegistry(account)
151+
);
152+
}

clients/js/src/generated/errors/mplAsset.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,43 @@ export class PluginNotFoundError extends ProgramError {
8080
codeToErrorMap.set(0x4, PluginNotFoundError);
8181
nameToErrorMap.set('PluginNotFound', PluginNotFoundError);
8282

83+
/** NumericalOverflow: Numerical Overflow */
84+
export class NumericalOverflowError extends ProgramError {
85+
readonly name: string = 'NumericalOverflow';
86+
87+
readonly code: number = 0x5; // 5
88+
89+
constructor(program: Program, cause?: Error) {
90+
super('Numerical Overflow', program, cause);
91+
}
92+
}
93+
codeToErrorMap.set(0x5, NumericalOverflowError);
94+
nameToErrorMap.set('NumericalOverflow', NumericalOverflowError);
95+
8396
/** IncorrectAccount: Incorrect account */
8497
export class IncorrectAccountError extends ProgramError {
8598
readonly name: string = 'IncorrectAccount';
8699

87-
readonly code: number = 0x5; // 5
100+
readonly code: number = 0x6; // 6
88101

89102
constructor(program: Program, cause?: Error) {
90103
super('Incorrect account', program, cause);
91104
}
92105
}
93-
codeToErrorMap.set(0x5, IncorrectAccountError);
106+
codeToErrorMap.set(0x6, IncorrectAccountError);
94107
nameToErrorMap.set('IncorrectAccount', IncorrectAccountError);
95108

96109
/** IncorrectAssetHash: Incorrect asset hash */
97110
export class IncorrectAssetHashError extends ProgramError {
98111
readonly name: string = 'IncorrectAssetHash';
99112

100-
readonly code: number = 0x6; // 6
113+
readonly code: number = 0x7; // 7
101114

102115
constructor(program: Program, cause?: Error) {
103116
super('Incorrect asset hash', program, cause);
104117
}
105118
}
106-
codeToErrorMap.set(0x6, IncorrectAssetHashError);
119+
codeToErrorMap.set(0x7, IncorrectAssetHashError);
107120
nameToErrorMap.set('IncorrectAssetHash', IncorrectAssetHashError);
108121

109122
/**

clients/js/src/generated/types/authority.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import { Plugin, PluginArgs, getPluginSerializer } from '.';
2020

2121
export type Authority =
2222
| { __kind: 'Owner' }
23+
| { __kind: 'Pubkey'; address: PublicKey }
2324
| { __kind: 'Permanent'; address: PublicKey }
2425
| { __kind: 'SameAs'; plugin: Plugin }
2526
| { __kind: 'Collection' };
2627

2728
export type AuthorityArgs =
2829
| { __kind: 'Owner' }
30+
| { __kind: 'Pubkey'; address: PublicKey }
2931
| { __kind: 'Permanent'; address: PublicKey }
3032
| { __kind: 'SameAs'; plugin: PluginArgs }
3133
| { __kind: 'Collection' };
@@ -34,6 +36,12 @@ export function getAuthoritySerializer(): Serializer<AuthorityArgs, Authority> {
3436
return dataEnum<Authority>(
3537
[
3638
['Owner', unit()],
39+
[
40+
'Pubkey',
41+
struct<GetDataEnumKindContent<Authority, 'Pubkey'>>([
42+
['address', publicKeySerializer()],
43+
]),
44+
],
3745
[
3846
'Permanent',
3947
struct<GetDataEnumKindContent<Authority, 'Permanent'>>([
@@ -56,6 +64,10 @@ export function getAuthoritySerializer(): Serializer<AuthorityArgs, Authority> {
5664
export function authority(
5765
kind: 'Owner'
5866
): GetDataEnumKind<AuthorityArgs, 'Owner'>;
67+
export function authority(
68+
kind: 'Pubkey',
69+
data: GetDataEnumKindContent<AuthorityArgs, 'Pubkey'>
70+
): GetDataEnumKind<AuthorityArgs, 'Pubkey'>;
5971
export function authority(
6072
kind: 'Permanent',
6173
data: GetDataEnumKindContent<AuthorityArgs, 'Permanent'>

clients/js/src/generated/types/delegate.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
*/
88

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

11-
export type Delegate = { frozen: boolean };
12+
export type Delegate = { key: Key; frozen: boolean };
1213

13-
export type DelegateArgs = Delegate;
14+
export type DelegateArgs = { key: KeyArgs; frozen: boolean };
1415

1516
export function getDelegateSerializer(): Serializer<DelegateArgs, Delegate> {
16-
return struct<Delegate>([['frozen', bool()]], {
17-
description: 'Delegate',
18-
}) as Serializer<DelegateArgs, Delegate>;
17+
return struct<Delegate>(
18+
[
19+
['key', getKeySerializer()],
20+
['frozen', bool()],
21+
],
22+
{ description: 'Delegate' }
23+
) as Serializer<DelegateArgs, Delegate>;
1924
}

0 commit comments

Comments
 (0)