Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verify collection instruction #167

Merged
merged 5 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}
}
Loading