github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/transfer.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 "github.com/hashgraph/hedera-protobufs-go/services" 25 ) 26 27 // Transfer is a transfer of hbars or tokens from one account to another 28 type Transfer struct { 29 AccountID AccountID 30 Amount Hbar 31 IsApproved bool 32 } 33 34 func _TransferFromProtobuf(pb *services.AccountAmount) Transfer { 35 if pb == nil { 36 return Transfer{} 37 } 38 39 accountID := AccountID{} 40 if pb.AccountID != nil { 41 accountID = *_AccountIDFromProtobuf(pb.AccountID) 42 } 43 44 return Transfer{ 45 AccountID: accountID, 46 Amount: HbarFromTinybar(pb.Amount), 47 IsApproved: pb.GetIsApproval(), 48 } 49 } 50 51 func (transfer Transfer) _ToProtobuf() *services.TransferList { // nolint 52 var ammounts = make([]*services.AccountAmount, 0) 53 ammounts = append(ammounts, &services.AccountAmount{ 54 AccountID: transfer.AccountID._ToProtobuf(), 55 Amount: transfer.Amount.AsTinybar(), 56 }) 57 58 return &services.TransferList{ 59 AccountAmounts: ammounts, 60 } 61 }