From b0b5702b79a9de926756708b7688c2aaabf4792c Mon Sep 17 00:00:00 2001 From: Tristan <162657122+Trisato@users.noreply.github.com> Date: Wed, 15 May 2024 20:20:09 +0800 Subject: [PATCH] Add verify collection instruction (#167) * add set and verify collection * add verify ins * add edition data * remove the method of fetching master edition data * add test case for verify ins --------- Co-authored-by: Tristan --- .../metaplex/token_metadata/instruction.go | 57 +++++++++++++++++++ .../token_metadata/instruction_test.go | 41 +++++++++++++ 2 files changed, 98 insertions(+) diff --git a/program/metaplex/token_metadata/instruction.go b/program/metaplex/token_metadata/instruction.go index 37e96e2d..9d9ca58c 100644 --- a/program/metaplex/token_metadata/instruction.go +++ b/program/metaplex/token_metadata/instruction.go @@ -641,3 +641,60 @@ func CreateMetadataAccountV3(param CreateMetadataAccountV3Param) types.Instructi Data: data, } } + +type VerifyCollectionParams struct { + Metadata common.PublicKey + CollectionUpdateAuthority common.PublicKey + Payer common.PublicKey + CollectionMint common.PublicKey + Collection common.PublicKey + CollectionMasterEditionAccount common.PublicKey +} + +func CreateVerifyCollection(param VerifyCollectionParams) types.Instruction { + data, err := borsh.Serialize(struct { + Instruction Instruction + }{ + Instruction: InstructionVerifyCollection, + }) + if err != nil { + panic(err) + } + accounts := []types.AccountMeta{ + { + PubKey: param.Metadata, + IsWritable: true, + IsSigner: false, + }, + { + PubKey: param.CollectionUpdateAuthority, + IsWritable: true, + IsSigner: true, + }, + { + PubKey: param.Payer, + IsWritable: true, + IsSigner: true, + }, + { + PubKey: param.CollectionMint, + IsWritable: false, + IsSigner: false, + }, + { + PubKey: param.Collection, + IsWritable: false, + IsSigner: false, + }, + { + PubKey: param.CollectionMasterEditionAccount, + IsWritable: false, + IsSigner: false, + }, + } + return types.Instruction{ + ProgramID: common.MetaplexTokenMetaProgramID, + Accounts: accounts, + Data: data, + } +} diff --git a/program/metaplex/token_metadata/instruction_test.go b/program/metaplex/token_metadata/instruction_test.go index 1d696202..f159c89b 100644 --- a/program/metaplex/token_metadata/instruction_test.go +++ b/program/metaplex/token_metadata/instruction_test.go @@ -455,3 +455,44 @@ func TestCreateMetadataAccountV2(t *testing.T) { }) } } + +func TestCreateVerifyCollection(t *testing.T) { + type args struct { + param VerifyCollectionParams + } + tests := []struct { + name string + args args + want types.Instruction + }{ + { + args: args{ + param: VerifyCollectionParams{ + Metadata: common.PublicKeyFromString("MetaData11111111111111111111111111111111111"), + CollectionUpdateAuthority: common.PublicKeyFromString("CollectionUpdateAuthority111111111111111111"), + Payer: common.PublicKeyFromString("payer11111111111111111111111111111111111111"), + CollectionMint: common.PublicKeyFromString("CollectionMint11111111111111111111111111111"), + Collection: common.PublicKeyFromString("Collection111111111111111111111111111111111"), + CollectionMasterEditionAccount: common.PublicKeyFromString("CollectionMasterEditionAccount1111111111111"), + }, + }, + want: types.Instruction{ + ProgramID: common.MetaplexTokenMetaProgramID, + Accounts: []types.AccountMeta{ + {PubKey: common.PublicKeyFromString("MetaData11111111111111111111111111111111111"), IsSigner: false, IsWritable: true}, + {PubKey: common.PublicKeyFromString("CollectionUpdateAuthority111111111111111111"), IsSigner: true, IsWritable: true}, + {PubKey: common.PublicKeyFromString("payer11111111111111111111111111111111111111"), IsSigner: true, IsWritable: true}, + {PubKey: common.PublicKeyFromString("CollectionMint11111111111111111111111111111"), IsSigner: false, IsWritable: false}, + {PubKey: common.PublicKeyFromString("Collection111111111111111111111111111111111"), IsSigner: false, IsWritable: false}, + {PubKey: common.PublicKeyFromString("CollectionMasterEditionAccount1111111111111"), IsSigner: false, IsWritable: false}, + }, + Data: []byte{18}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equalf(t, tt.want, CreateVerifyCollection(tt.args.param), "CreateVerifyCollection(%v)", tt.args.param) + }) + } +}