gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
929 stars 264 forks source link

Instruction Impl Type Inconsistency: Builder vs Unmarshal #222

Open lukestoltenberg opened 5 months ago

lukestoltenberg commented 5 months ago

When unmarshalling a transaction from []byte it creates a pointer to the instruction's BaseVariant.Impl but when creating a token.Instruction using a builder like token.NewMintToCheckedInstructionBuilder() the BaseVariant.Impl is a value.

For example, token.NewMintToCheckedInstructionBuilder(), the .Build() sets the BaseVariant.Impl to the receiver value of inst MintToChecked https://github.com/gagliardetto/solana-go/blob/a5e17d6253468337b4851105413f827a8b152f5a/programs/token/MintToChecked.go#L135

When using UnmarshalBin of a []byte, it sets the BaseVariant.Impl to a pointer, https://github.com/gagliardetto/binary/blob/79f49c5de0e11369897085d761a7e27cbd8eab15/variant.go#L320.

To fix this, I propose changing the instructions' .Build() to take a pointer receiver

func (inst *MintToChecked) Build() *Instruction