github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/fee_components.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 // nolint 31 type FeeComponents struct { 32 Min int64 33 Max int64 34 Constant int64 35 TransactionBandwidthByte int64 36 TransactionVerification int64 37 TransactionRamByteHour int64 38 TransactionStorageByteHour int64 39 ContractTransactionGas int64 40 TransferVolumeHbar int64 41 ResponseMemoryByte int64 42 ResponseDiscByte int64 43 } 44 45 func _FeeComponentsFromProtobuf(feeComponents *services.FeeComponents) (FeeComponents, error) { 46 if feeComponents == nil { 47 return FeeComponents{}, errParameterNull 48 } 49 50 return FeeComponents{ 51 Min: feeComponents.GetMin(), 52 Max: feeComponents.GetMax(), 53 Constant: feeComponents.GetConstant(), 54 TransactionBandwidthByte: feeComponents.GetBpt(), 55 TransactionVerification: feeComponents.GetVpt(), 56 TransactionRamByteHour: feeComponents.GetRbh(), 57 TransactionStorageByteHour: feeComponents.GetSbh(), 58 ContractTransactionGas: feeComponents.GetGas(), 59 TransferVolumeHbar: feeComponents.GetTv(), 60 ResponseMemoryByte: feeComponents.GetBpr(), 61 ResponseDiscByte: feeComponents.GetSbpr(), 62 }, nil 63 } 64 65 func (feeComponents FeeComponents) _ToProtobuf() *services.FeeComponents { 66 return &services.FeeComponents{ 67 Min: feeComponents.Min, 68 Max: feeComponents.Max, 69 Constant: feeComponents.Constant, 70 Bpt: feeComponents.TransactionBandwidthByte, 71 Vpt: feeComponents.TransactionVerification, 72 Rbh: feeComponents.TransactionRamByteHour, 73 Sbh: feeComponents.TransactionStorageByteHour, 74 Gas: feeComponents.ContractTransactionGas, 75 Tv: feeComponents.TransferVolumeHbar, 76 Bpr: feeComponents.ResponseMemoryByte, 77 Sbpr: feeComponents.ResponseDiscByte, 78 } 79 } 80 81 // ToBytes returns the byte representation of the FeeComponents 82 func (feeComponents FeeComponents) ToBytes() []byte { 83 data, err := protobuf.Marshal(feeComponents._ToProtobuf()) 84 if err != nil { 85 return make([]byte, 0) 86 } 87 88 return data 89 } 90 91 // FeeComponentsFromBytes returns the FeeComponents from a byte array representation 92 func FeeComponentsFromBytes(data []byte) (FeeComponents, error) { 93 if data == nil { 94 return FeeComponents{}, errByteArrayNull 95 } 96 pb := services.FeeComponents{} 97 err := protobuf.Unmarshal(data, &pb) 98 if err != nil { 99 return FeeComponents{}, err 100 } 101 102 info, err := _FeeComponentsFromProtobuf(&pb) 103 if err != nil { 104 return FeeComponents{}, err 105 } 106 107 return info, nil 108 } 109 110 // String returns a string representation of the FeeComponents 111 func (feeComponents FeeComponents) String() string { 112 return fmt.Sprintf("Min: %d, Max: %d, Constant: %d,TransactionBandwithByte: %d,TransactionVerification: %d,TransactionRamByteHour: %d,TransactionStorageByteHour: %d, ContractTransactionGas: %d,TransferVolumeHbar: %d, ResponseMemoryByte: %d, ResponseDiscByte: %d", feeComponents.Min, feeComponents.Max, feeComponents.Constant, feeComponents.TransactionBandwidthByte, feeComponents.TransactionVerification, feeComponents.TransactionRamByteHour, feeComponents.TransactionStorageByteHour, feeComponents.ContractTransactionGas, feeComponents.TransferVolumeHbar, feeComponents.ResponseMemoryByte, feeComponents.ResponseDiscByte) 113 }