github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/node_address.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 // NodeAddress is the address of a node on the Hedera network 28 type NodeAddress struct { 29 PublicKey string 30 AccountID *AccountID 31 NodeID int64 32 CertHash []byte 33 Addresses []Endpoint 34 Description string 35 } 36 37 func _NodeAddressFromProtobuf(nodeAd *services.NodeAddress) NodeAddress { 38 address := make([]Endpoint, 0) 39 40 for _, end := range nodeAd.GetServiceEndpoint() { 41 address = append(address, EndpointFromProtobuf(end)) 42 } 43 44 return NodeAddress{ 45 PublicKey: nodeAd.GetRSA_PubKey(), 46 AccountID: _AccountIDFromProtobuf(nodeAd.GetNodeAccountId()), 47 NodeID: nodeAd.GetNodeId(), 48 CertHash: nodeAd.GetNodeCertHash(), 49 Addresses: address, 50 Description: nodeAd.GetDescription(), 51 } 52 } 53 54 func (nodeAdd *NodeAddress) _ToProtobuf() *services.NodeAddress { 55 build := &services.NodeAddress{ 56 RSA_PubKey: nodeAdd.PublicKey, 57 NodeId: nodeAdd.NodeID, 58 NodeAccountId: nil, 59 NodeCertHash: nodeAdd.CertHash, 60 ServiceEndpoint: nil, 61 Description: nodeAdd.Description, 62 } 63 64 if nodeAdd.AccountID != nil { 65 build.NodeAccountId = nodeAdd.AccountID._ToProtobuf() 66 } 67 68 serviceEndpoint := make([]*services.ServiceEndpoint, 0) 69 for _, k := range nodeAdd.Addresses { 70 serviceEndpoint = append(serviceEndpoint, k._ToProtobuf()) 71 } 72 build.ServiceEndpoint = serviceEndpoint 73 74 return build 75 } 76 77 // String returns a string representation of the NodeAddress 78 func (nodeAdd NodeAddress) String() string { 79 Addresses := "" 80 for _, k := range nodeAdd.Addresses { 81 Addresses += k.String() 82 } 83 return nodeAdd.AccountID.String() + " " + Addresses + "\n" + "CertHash " + string(nodeAdd.CertHash) 84 }