From bb8d137e8534482e4c635fc8318c18adb173486b Mon Sep 17 00:00:00 2001 From: febo Date: Thu, 28 Dec 2023 00:03:25 +0200 Subject: [PATCH 1/2] Sync token auth rules types --- .../program/src/state/token_auth_payload.rs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/programs/token-metadata/program/src/state/token_auth_payload.rs b/programs/token-metadata/program/src/state/token_auth_payload.rs index 11a5e065..3fe53c51 100644 --- a/programs/token-metadata/program/src/state/token_auth_payload.rs +++ b/programs/token-metadata/program/src/state/token_auth_payload.rs @@ -1,7 +1,8 @@ -/// These types exist to give Shank a way to create the Payload type as it -/// cannnot create it from the remote type from mpl-token-auth-rules. -/// Care will need to be taken to ensure they stay synced with any changes in -/// mpl-token-auth-rules. +//! These types exist to give Shank a way to create the Payload type as it +//! cannnot create it from the remote type from mpl-token-auth-rules. +//! Care will need to be taken to ensure they stay synced with any changes in +//! mpl-token-auth-rules. + use std::collections::HashMap; use borsh::{BorshDeserialize, BorshSerialize}; @@ -12,31 +13,41 @@ use solana_program::pubkey::Pubkey; #[repr(C)] #[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))] #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)] +/// A seed path type used by the `DerivedKeyMatch` rule. struct SeedsVec { + /// The vector of derivation seeds. seeds: Vec>, } #[repr(C)] #[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))] #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)] -struct LeafInfo { - leaf: [u8; 32], +/// A proof type used by the `PubkeyTreeMatch` rule. +struct ProofInfo { + /// The merkle proof. proof: Vec<[u8; 32]>, } #[repr(C)] #[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))] #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)] +/// Variants representing the different types represented in a payload. enum PayloadType { + /// A plain `Pubkey`. Pubkey(Pubkey), + /// PDA derivation seeds. Seeds(SeedsVec), - MerkleProof(LeafInfo), + /// A merkle proof. + MerkleProof(ProofInfo), + /// A plain `u64` used for `Amount`. Number(u64), } #[repr(C)] #[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))] #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone, Default)] +/// A wrapper type for the payload hashmap. struct Payload { + /// The payload hashmap. map: HashMap, } From 6b311a198ae376acbca9a3d82f1b7ad438909c2c Mon Sep 17 00:00:00 2001 From: febo Date: Thu, 28 Dec 2023 00:03:45 +0200 Subject: [PATCH 2/2] Update autogenerated code --- clients/js/src/generated/types/index.ts | 2 +- clients/js/src/generated/types/leafInfo.ts | 28 ------------------- clients/js/src/generated/types/payloadType.ts | 12 ++++---- clients/js/src/generated/types/proofInfo.ts | 24 ++++++++++++++++ clients/rust/src/generated/types/mod.rs | 4 +-- .../rust/src/generated/types/payload_type.rs | 4 +-- .../types/{leaf_info.rs => proof_info.rs} | 3 +- idls/token_metadata.json | 13 ++------- 8 files changed, 38 insertions(+), 52 deletions(-) delete mode 100644 clients/js/src/generated/types/leafInfo.ts create mode 100644 clients/js/src/generated/types/proofInfo.ts rename clients/rust/src/generated/types/{leaf_info.rs => proof_info.rs} (91%) diff --git a/clients/js/src/generated/types/index.ts b/clients/js/src/generated/types/index.ts index df0315a8..db742ef2 100644 --- a/clients/js/src/generated/types/index.ts +++ b/clients/js/src/generated/types/index.ts @@ -20,7 +20,6 @@ export * from './dataV2'; export * from './delegateArgs'; export * from './escrowAuthority'; export * from './key'; -export * from './leafInfo'; export * from './lockArgs'; export * from './metadataDelegateRole'; export * from './migrationType'; @@ -32,6 +31,7 @@ export * from './payloadType'; export * from './printArgs'; export * from './printSupply'; export * from './programmableConfig'; +export * from './proofInfo'; export * from './reservation'; export * from './reservationV1'; export * from './revokeArgs'; diff --git a/clients/js/src/generated/types/leafInfo.ts b/clients/js/src/generated/types/leafInfo.ts deleted file mode 100644 index 95227074..00000000 --- a/clients/js/src/generated/types/leafInfo.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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, - array, - bytes, - struct, -} from '@metaplex-foundation/umi/serializers'; - -export type LeafInfo = { leaf: Uint8Array; proof: Array }; - -export type LeafInfoArgs = LeafInfo; - -export function getLeafInfoSerializer(): Serializer { - return struct( - [ - ['leaf', bytes({ size: 32 })], - ['proof', array(bytes({ size: 32 }))], - ], - { description: 'LeafInfo' } - ) as Serializer; -} diff --git a/clients/js/src/generated/types/payloadType.ts b/clients/js/src/generated/types/payloadType.ts index b66604c7..9f375f29 100644 --- a/clients/js/src/generated/types/payloadType.ts +++ b/clients/js/src/generated/types/payloadType.ts @@ -18,24 +18,24 @@ import { u64, } from '@metaplex-foundation/umi/serializers'; import { - LeafInfo, - LeafInfoArgs, + ProofInfo, + ProofInfoArgs, SeedsVec, SeedsVecArgs, - getLeafInfoSerializer, + getProofInfoSerializer, getSeedsVecSerializer, } from '.'; export type PayloadType = | { __kind: 'Pubkey'; fields: [PublicKey] } | { __kind: 'Seeds'; fields: [SeedsVec] } - | { __kind: 'MerkleProof'; fields: [LeafInfo] } + | { __kind: 'MerkleProof'; fields: [ProofInfo] } | { __kind: 'Number'; fields: [bigint] }; export type PayloadTypeArgs = | { __kind: 'Pubkey'; fields: [PublicKey] } | { __kind: 'Seeds'; fields: [SeedsVecArgs] } - | { __kind: 'MerkleProof'; fields: [LeafInfoArgs] } + | { __kind: 'MerkleProof'; fields: [ProofInfoArgs] } | { __kind: 'Number'; fields: [number | bigint] }; export function getPayloadTypeSerializer(): Serializer< @@ -59,7 +59,7 @@ export function getPayloadTypeSerializer(): Serializer< [ 'MerkleProof', struct>([ - ['fields', tuple([getLeafInfoSerializer()])], + ['fields', tuple([getProofInfoSerializer()])], ]), ], [ diff --git a/clients/js/src/generated/types/proofInfo.ts b/clients/js/src/generated/types/proofInfo.ts new file mode 100644 index 00000000..5083e03d --- /dev/null +++ b/clients/js/src/generated/types/proofInfo.ts @@ -0,0 +1,24 @@ +/** + * 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, + array, + bytes, + struct, +} from '@metaplex-foundation/umi/serializers'; + +export type ProofInfo = { proof: Array }; + +export type ProofInfoArgs = ProofInfo; + +export function getProofInfoSerializer(): Serializer { + return struct([['proof', array(bytes({ size: 32 }))]], { + description: 'ProofInfo', + }) as Serializer; +} diff --git a/clients/rust/src/generated/types/mod.rs b/clients/rust/src/generated/types/mod.rs index 0f03f091..f064c7a2 100644 --- a/clients/rust/src/generated/types/mod.rs +++ b/clients/rust/src/generated/types/mod.rs @@ -19,7 +19,6 @@ pub(crate) mod data_v2; pub(crate) mod delegate_args; pub(crate) mod escrow_authority; pub(crate) mod key; -pub(crate) mod leaf_info; pub(crate) mod lock_args; pub(crate) mod metadata_delegate_role; pub(crate) mod migration_type; @@ -31,6 +30,7 @@ pub(crate) mod payload_type; pub(crate) mod print_args; pub(crate) mod print_supply; pub(crate) mod programmable_config; +pub(crate) mod proof_info; pub(crate) mod reservation; pub(crate) mod reservation_v1; pub(crate) mod revoke_args; @@ -63,7 +63,6 @@ pub use self::data_v2::*; pub use self::delegate_args::*; pub use self::escrow_authority::*; pub use self::key::*; -pub use self::leaf_info::*; pub use self::lock_args::*; pub use self::metadata_delegate_role::*; pub use self::migration_type::*; @@ -75,6 +74,7 @@ pub use self::payload_type::*; pub use self::print_args::*; pub use self::print_supply::*; pub use self::programmable_config::*; +pub use self::proof_info::*; pub use self::reservation::*; pub use self::reservation_v1::*; pub use self::revoke_args::*; diff --git a/clients/rust/src/generated/types/payload_type.rs b/clients/rust/src/generated/types/payload_type.rs index afe93cdf..26ec39de 100644 --- a/clients/rust/src/generated/types/payload_type.rs +++ b/clients/rust/src/generated/types/payload_type.rs @@ -5,7 +5,7 @@ //! [https://github.com/metaplex-foundation/kinobi] //! -use crate::generated::types::LeafInfo; +use crate::generated::types::ProofInfo; use crate::generated::types::SeedsVec; use borsh::BorshDeserialize; use borsh::BorshSerialize; @@ -16,6 +16,6 @@ use solana_program::pubkey::Pubkey; pub enum PayloadType { Pubkey(Pubkey), Seeds(SeedsVec), - MerkleProof(LeafInfo), + MerkleProof(ProofInfo), Number(u64), } diff --git a/clients/rust/src/generated/types/leaf_info.rs b/clients/rust/src/generated/types/proof_info.rs similarity index 91% rename from clients/rust/src/generated/types/leaf_info.rs rename to clients/rust/src/generated/types/proof_info.rs index 14e3cf56..95e033de 100644 --- a/clients/rust/src/generated/types/leaf_info.rs +++ b/clients/rust/src/generated/types/proof_info.rs @@ -10,7 +10,6 @@ use borsh::BorshSerialize; #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct LeafInfo { - pub leaf: [u8; 32], +pub struct ProofInfo { pub proof: Vec<[u8; 32]>, } diff --git a/idls/token_metadata.json b/idls/token_metadata.json index 61623d90..6cd68799 100644 --- a/idls/token_metadata.json +++ b/idls/token_metadata.json @@ -5508,19 +5508,10 @@ } }, { - "name": "LeafInfo", + "name": "ProofInfo", "type": { "kind": "struct", "fields": [ - { - "name": "leaf", - "type": { - "array": [ - "u8", - 32 - ] - } - }, { "name": "proof", "type": { @@ -6727,7 +6718,7 @@ "name": "MerkleProof", "fields": [ { - "defined": "LeafInfo" + "defined": "ProofInfo" } ] },