|
| 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 computebudget |
| 16 | + |
| 17 | +import ( |
| 18 | + "errors" |
| 19 | + |
| 20 | + ag_binary "github.com/gagliardetto/binary" |
| 21 | + ag_solanago "github.com/gagliardetto/solana-go" |
| 22 | + ag_format "github.com/gagliardetto/solana-go/text/format" |
| 23 | + ag_treeout "github.com/gagliardetto/treeout" |
| 24 | +) |
| 25 | + |
| 26 | +type SetLoadedAccountsDataSizeLimit struct { |
| 27 | + Bytes uint32 |
| 28 | +} |
| 29 | + |
| 30 | +func (obj *SetLoadedAccountsDataSizeLimit) SetAccounts(accounts []*ag_solanago.AccountMeta) error { |
| 31 | + return nil |
| 32 | +} |
| 33 | + |
| 34 | +func (slice SetLoadedAccountsDataSizeLimit) GetAccounts() (accounts []*ag_solanago.AccountMeta) { |
| 35 | + return |
| 36 | +} |
| 37 | + |
| 38 | +// NewSetLoadedAccountsDataSizeLimitInstructionBuilder creates a new `SetLoadedAccountsDataSizeLimit` instruction builder. |
| 39 | +func NewSetLoadedAccountsDataSizeLimitInstructionBuilder() *SetLoadedAccountsDataSizeLimit { |
| 40 | + nd := &SetLoadedAccountsDataSizeLimit{} |
| 41 | + return nd |
| 42 | +} |
| 43 | + |
| 44 | +// Byytes limit |
| 45 | +func (inst *SetLoadedAccountsDataSizeLimit) SetBytes(bytes uint32) *SetLoadedAccountsDataSizeLimit { |
| 46 | + inst.Bytes = bytes |
| 47 | + return inst |
| 48 | +} |
| 49 | + |
| 50 | +func (inst SetLoadedAccountsDataSizeLimit) Build() *Instruction { |
| 51 | + return &Instruction{BaseVariant: ag_binary.BaseVariant{ |
| 52 | + Impl: inst, |
| 53 | + TypeID: ag_binary.TypeIDFromUint8(Instruction_SetLoadedAccountsDataSizeLimit), |
| 54 | + }} |
| 55 | +} |
| 56 | + |
| 57 | +// ValidateAndBuild validates the instruction parameters and accounts; |
| 58 | +// if there is a validation error, it returns the error. |
| 59 | +// Otherwise, it builds and returns the instruction. |
| 60 | +func (inst SetLoadedAccountsDataSizeLimit) ValidateAndBuild() (*Instruction, error) { |
| 61 | + if err := inst.Validate(); err != nil { |
| 62 | + return nil, err |
| 63 | + } |
| 64 | + return inst.Build(), nil |
| 65 | +} |
| 66 | + |
| 67 | +func (inst *SetLoadedAccountsDataSizeLimit) Validate() error { |
| 68 | + // Check whether all (required) parameters are set: |
| 69 | + if inst.Bytes == 0 { |
| 70 | + return errors.New("Bytes parameter is not set") |
| 71 | + } |
| 72 | + |
| 73 | + return nil |
| 74 | +} |
| 75 | + |
| 76 | +func (inst *SetLoadedAccountsDataSizeLimit) EncodeToTree(parent ag_treeout.Branches) { |
| 77 | + parent.Child(ag_format.Program(ProgramName, ProgramID)). |
| 78 | + // |
| 79 | + ParentFunc(func(programBranch ag_treeout.Branches) { |
| 80 | + programBranch.Child(ag_format.Instruction("SetLoadedAccountsDataSizeLimit")). |
| 81 | + // |
| 82 | + ParentFunc(func(instructionBranch ag_treeout.Branches) { |
| 83 | + |
| 84 | + // Parameters of the instruction: |
| 85 | + instructionBranch.Child("Params").ParentFunc(func(paramsBranch ag_treeout.Branches) { |
| 86 | + paramsBranch.Child(ag_format.Param("Bytes", inst.Bytes)) |
| 87 | + }) |
| 88 | + }) |
| 89 | + }) |
| 90 | +} |
| 91 | + |
| 92 | +func (obj SetLoadedAccountsDataSizeLimit) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { |
| 93 | + // Serialize `Bytes` param: |
| 94 | + err = encoder.Encode(obj.Bytes) |
| 95 | + if err != nil { |
| 96 | + return err |
| 97 | + } |
| 98 | + return nil |
| 99 | +} |
| 100 | +func (obj *SetLoadedAccountsDataSizeLimit) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { |
| 101 | + // Deserialize `Bytes`: |
| 102 | + err = decoder.Decode(&obj.Bytes) |
| 103 | + if err != nil { |
| 104 | + return err |
| 105 | + } |
| 106 | + return nil |
| 107 | +} |
| 108 | + |
| 109 | +// NewSetLoadedAccountsDataSizeLimitInstruction declares a new SetLoadedAccountsDataSizeLimit instruction with the provided parameters and accounts. |
| 110 | +func NewSetLoadedAccountsDataSizeLimitInstruction( |
| 111 | + // Parameters: |
| 112 | + bytes uint32, |
| 113 | +) *SetLoadedAccountsDataSizeLimit { |
| 114 | + return NewSetLoadedAccountsDataSizeLimitInstructionBuilder().SetBytes(bytes) |
| 115 | +} |
0 commit comments