github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/mirror_network.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  	"math/rand"
    25  )
    26  
    27  type _MirrorNetwork struct {
    28  	_ManagedNetwork
    29  }
    30  
    31  func _NewMirrorNetwork() *_MirrorNetwork {
    32  	return &_MirrorNetwork{
    33  		_ManagedNetwork: _NewManagedNetwork(),
    34  	}
    35  }
    36  
    37  func (network *_MirrorNetwork) _SetNetwork(newNetwork []string) (err error) {
    38  	newMirrorNetwork := make(map[string]_IManagedNode)
    39  	for _, url := range newNetwork {
    40  		if newMirrorNetwork[url], err = _NewMirrorNode(url); err != nil {
    41  			return err
    42  		}
    43  	}
    44  
    45  	return network._ManagedNetwork._SetNetwork(newMirrorNetwork)
    46  }
    47  
    48  func (network *_MirrorNetwork) _GetNetwork() []string {
    49  	temp := make([]string, 0)
    50  	for url := range network._ManagedNetwork.network { //nolint
    51  		temp = append(temp, url)
    52  	}
    53  
    54  	return temp
    55  }
    56  
    57  // nolint:unused
    58  // Deprecated: _SetTransportSecurity is no longer supported, as only secured connections are now allowed.
    59  func (network *_MirrorNetwork) _SetTransportSecurity(transportSecurity bool) *_MirrorNetwork {
    60  	return network
    61  }
    62  
    63  func (network *_MirrorNetwork) _GetNextMirrorNode() *_MirrorNode {
    64  	node := network._ManagedNetwork.healthyNodes[rand.Intn(len(network.healthyNodes))] // nolint
    65  	if node, ok := node.(*_MirrorNode); ok {
    66  		return node
    67  	}
    68  	return &_MirrorNode{}
    69  }