Skip to content

Commit

Permalink
Add verify collection instruction (#167)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Trisato and Trisato authored May 15, 2024
1 parent dd8ae18 commit b0b5702
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
57 changes: 57 additions & 0 deletions program/metaplex/token_metadata/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
41 changes: 41 additions & 0 deletions program/metaplex/token_metadata/instruction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}

0 comments on commit b0b5702

Please sign in to comment.