github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/live_hash.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 protobuf "google.golang.org/protobuf/proto" 26 27 "time" 28 ) 29 30 // LiveHash is a hash that is live on the Hedera network 31 type LiveHash struct { 32 AccountID AccountID 33 Hash []byte 34 Keys KeyList 35 // Deprecated 36 Duration time.Time 37 LiveHashDuration time.Duration 38 } 39 40 func (liveHash *LiveHash) _ToProtobuf() *services.LiveHash { 41 return &services.LiveHash{ 42 AccountId: liveHash.AccountID._ToProtobuf(), 43 Hash: liveHash.Hash, 44 Keys: liveHash.Keys._ToProtoKeyList(), 45 Duration: _DurationToProtobuf(liveHash.LiveHashDuration), 46 } 47 } 48 49 func _LiveHashFromProtobuf(hash *services.LiveHash) (LiveHash, error) { 50 if hash == nil { 51 return LiveHash{}, errParameterNull 52 } 53 54 var keyList KeyList 55 var err error 56 if hash.Keys != nil { 57 keyList, err = _KeyListFromProtobuf(hash.Keys) 58 if err != nil { 59 return LiveHash{}, err 60 } 61 } 62 63 accountID := AccountID{} 64 if hash.AccountId != nil { 65 accountID = *_AccountIDFromProtobuf(hash.AccountId) 66 } 67 68 var duration time.Duration 69 if hash.Duration != nil { 70 duration = _DurationFromProtobuf(hash.Duration) 71 } 72 73 return LiveHash{ 74 AccountID: accountID, 75 Hash: hash.Hash, 76 Keys: keyList, 77 LiveHashDuration: duration, 78 }, nil 79 } 80 81 // ToBytes returns the byte representation of the LiveHash 82 func (liveHash LiveHash) ToBytes() []byte { 83 data, err := protobuf.Marshal(liveHash._ToProtobuf()) 84 if err != nil { 85 return make([]byte, 0) 86 } 87 88 return data 89 } 90 91 // LiveHashFromBytes returns a LiveHash object from a raw byte array 92 func LiveHashFromBytes(data []byte) (LiveHash, error) { 93 if data == nil { 94 return LiveHash{}, errByteArrayNull 95 } 96 pb := services.LiveHash{} 97 err := protobuf.Unmarshal(data, &pb) 98 if err != nil { 99 return LiveHash{}, err 100 } 101 102 liveHash, err := _LiveHashFromProtobuf(&pb) 103 if err != nil { 104 return LiveHash{}, err 105 } 106 107 return liveHash, nil 108 }