github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/fee_schedules.go (about)

     1  package hedera
     2  
     3  /*-
     4   *
     5   * Hedera Go SDK
     6   *
     7   * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
     8   *
     9   * Licensed under the Apache License, Version 2.0 (the "License");
    10   * you may not use this file except in compliance with the License.
    11   * You may obtain a copy of the License at
    12   *
    13   *      http://www.apache.org/licenses/LICENSE-2.0
    14   *
    15   * Unless required by applicable law or agreed to in writing, software
    16   * distributed under the License is distributed on an "AS IS" BASIS,
    17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    18   * See the License for the specific language governing permissions and
    19   * limitations under the License.
    20   *
    21   */
    22  
    23  import (
    24  	"fmt"
    25  
    26  	"github.com/hashgraph/hedera-protobufs-go/services"
    27  	protobuf "google.golang.org/protobuf/proto"
    28  )
    29  
    30  type FeeSchedules struct {
    31  	current *FeeSchedule
    32  	next    *FeeSchedule
    33  }
    34  
    35  func _FeeSchedulesFromProtobuf(feeSchedules *services.CurrentAndNextFeeSchedule) (FeeSchedules, error) {
    36  	if feeSchedules == nil {
    37  		return FeeSchedules{}, errParameterNull
    38  	}
    39  
    40  	var current FeeSchedule
    41  	var err error
    42  	if feeSchedules.CurrentFeeSchedule != nil {
    43  		current, err = _FeeScheduleFromProtobuf(feeSchedules.GetCurrentFeeSchedule())
    44  		if err != nil {
    45  			return FeeSchedules{}, err
    46  		}
    47  	}
    48  
    49  	var next FeeSchedule
    50  	if feeSchedules.NextFeeSchedule != nil {
    51  		next, err = _FeeScheduleFromProtobuf(feeSchedules.GetNextFeeSchedule())
    52  		if err != nil {
    53  			return FeeSchedules{}, err
    54  		}
    55  	}
    56  
    57  	return FeeSchedules{
    58  		current: &current,
    59  		next:    &next,
    60  	}, nil
    61  }
    62  
    63  func (feeSchedules FeeSchedules) _ToProtobuf() *services.CurrentAndNextFeeSchedule {
    64  	var current *services.FeeSchedule
    65  	if feeSchedules.current != nil {
    66  		current = feeSchedules.current._ToProtobuf()
    67  	}
    68  
    69  	var next *services.FeeSchedule
    70  	if feeSchedules.next != nil {
    71  		next = feeSchedules.next._ToProtobuf()
    72  	}
    73  
    74  	return &services.CurrentAndNextFeeSchedule{
    75  		CurrentFeeSchedule: current,
    76  		NextFeeSchedule:    next,
    77  	}
    78  }
    79  
    80  // ToBytes returns the byte representation of the FeeSchedules
    81  func (feeSchedules FeeSchedules) ToBytes() []byte {
    82  	data, err := protobuf.Marshal(feeSchedules._ToProtobuf())
    83  	if err != nil {
    84  		return make([]byte, 0)
    85  	}
    86  
    87  	return data
    88  }
    89  
    90  // FeeSchedulesFromBytes returns a FeeSchedules object from a raw byte array
    91  func FeeSchedulesFromBytes(data []byte) (FeeSchedules, error) {
    92  	if data == nil {
    93  		return FeeSchedules{}, errByteArrayNull
    94  	}
    95  	pb := services.CurrentAndNextFeeSchedule{}
    96  	err := protobuf.Unmarshal(data, &pb)
    97  	if err != nil {
    98  		return FeeSchedules{}, err
    99  	}
   100  
   101  	info, err := _FeeSchedulesFromProtobuf(&pb)
   102  	if err != nil {
   103  		return FeeSchedules{}, err
   104  	}
   105  
   106  	return info, nil
   107  }
   108  
   109  // String returns a string representation of the FeeSchedules
   110  func (feeSchedules FeeSchedules) String() string {
   111  	return fmt.Sprintf("Current: %s, Next: %s", feeSchedules.current.String(), feeSchedules.next.String())
   112  }