Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use iota constants for TypeID
Browse files Browse the repository at this point in the history
iamnotaturtle committed Oct 23, 2023
1 parent cf3cdd7 commit c1c8d06
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion programs/associated-token-account/Create.go
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ func (inst Create) Build() *Instruction {

return &Instruction{BaseVariant: bin.BaseVariant{
Impl: inst,
TypeID: bin.NoTypeIDDefaultID,
TypeID: bin.TypeIDFromUint8(Instruction_Create),
}}
}

2 changes: 1 addition & 1 deletion programs/associated-token-account/CreateIdempotent.go
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ func (inst CreateIdempotent) Build() *Instruction {

return &Instruction{BaseVariant: bin.BaseVariant{
Impl: inst,
TypeID: bin.TypeIDFromUint8(1),
TypeID: bin.TypeIDFromUint8(Instruction_CreateIdempotent),
}}
}

23 changes: 23 additions & 0 deletions programs/associated-token-account/instructions.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,29 @@ func init() {
solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
}

const (
// Creates an associated token account for the given wallet address and token mint
// Returns an error if the account exists.
Instruction_Create uint8 = iota

// Creates an associated token account for the given wallet address and token mint,
// if it doesn't already exist. Returns an error if the account exists,
// but with a different owner.
Instruction_CreateIdempotent
)

// InstructionIDToName returns the name of the instruction given its ID.
func InstructionIDToName(id uint8) string {
switch id {
case Instruction_Create:
return "Create"
case Instruction_CreateIdempotent:
return "CreateIdempotent"
default:
return ""
}
}

type Instruction struct {
bin.BaseVariant
}

0 comments on commit c1c8d06

Please sign in to comment.