github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/transaction_fee_schedule.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 TransactionFeeSchedule struct {
    31  	RequestType RequestType
    32  	// Deprecated: use Fees
    33  	FeeData *FeeData
    34  	Fees    []*FeeData
    35  }
    36  
    37  func _TransactionFeeScheduleFromProtobuf(txFeeSchedule *services.TransactionFeeSchedule) (TransactionFeeSchedule, error) {
    38  	if txFeeSchedule == nil {
    39  		return TransactionFeeSchedule{}, errParameterNull
    40  	}
    41  
    42  	feeData := make([]*FeeData, 0)
    43  
    44  	for _, d := range txFeeSchedule.GetFees() {
    45  		temp, err := _FeeDataFromProtobuf(d)
    46  		if err != nil {
    47  			return TransactionFeeSchedule{}, err
    48  		}
    49  		feeData = append(feeData, &temp)
    50  	}
    51  
    52  	return TransactionFeeSchedule{
    53  		RequestType: RequestType(txFeeSchedule.GetHederaFunctionality()),
    54  		Fees:        feeData,
    55  	}, nil
    56  }
    57  
    58  func (txFeeSchedule TransactionFeeSchedule) _ToProtobuf() *services.TransactionFeeSchedule {
    59  	feeData := make([]*services.FeeData, 0)
    60  	if txFeeSchedule.Fees != nil {
    61  		for _, data := range txFeeSchedule.Fees {
    62  			feeData = append(feeData, data._ToProtobuf())
    63  		}
    64  	}
    65  
    66  	var singleFee *services.FeeData
    67  	if txFeeSchedule.FeeData != nil {
    68  		singleFee = txFeeSchedule.FeeData._ToProtobuf()
    69  	}
    70  
    71  	return &services.TransactionFeeSchedule{
    72  		HederaFunctionality: services.HederaFunctionality(txFeeSchedule.RequestType),
    73  		Fees:                feeData,
    74  		FeeData:             singleFee,
    75  	}
    76  }
    77  
    78  func (txFeeSchedule TransactionFeeSchedule) ToBytes() []byte {
    79  	data, err := protobuf.Marshal(txFeeSchedule._ToProtobuf())
    80  	if err != nil {
    81  		return make([]byte, 0)
    82  	}
    83  
    84  	return data
    85  }
    86  
    87  func (txFeeSchedule TransactionFeeSchedule) String() string {
    88  	str := ""
    89  	for _, dat := range txFeeSchedule.Fees {
    90  		str = str + dat.String() + ", "
    91  	}
    92  
    93  	if txFeeSchedule.FeeData != nil {
    94  		return fmt.Sprintf("RequestType: %s, Feedata: %s", txFeeSchedule.RequestType.String(), txFeeSchedule.FeeData.String())
    95  	}
    96  
    97  	return fmt.Sprintf("RequestType: %s, Feedata: %s", txFeeSchedule.RequestType.String(), str)
    98  }