github.com/gagliardetto/solana-go@v1.11.0/generic_instruction.go (about) 1 // Copyright 2021 github.com/gagliardetto 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package solana 16 17 // NewInstruction creates a generic instruction with the provided 18 // programID, accounts, and data bytes. 19 func NewInstruction( 20 programID PublicKey, 21 accounts AccountMetaSlice, 22 data []byte, 23 ) *GenericInstruction { 24 return &GenericInstruction{ 25 AccountValues: accounts, 26 ProgID: programID, 27 DataBytes: data, 28 } 29 } 30 31 var _ Instruction = &GenericInstruction{} 32 33 type GenericInstruction struct { 34 AccountValues AccountMetaSlice 35 ProgID PublicKey 36 DataBytes []byte 37 } 38 39 func (in *GenericInstruction) ProgramID() PublicKey { 40 return in.ProgID 41 } 42 43 func (in *GenericInstruction) Accounts() []*AccountMeta { 44 return in.AccountValues 45 } 46 47 func (in *GenericInstruction) Data() ([]byte, error) { 48 return in.DataBytes, nil 49 }