diff --git a/account_balance_query_e2e_test.go b/account_balance_query_e2e_test.go index 7e65aacf..ce781afd 100644 --- a/account_balance_query_e2e_test.go +++ b/account_balance_query_e2e_test.go @@ -24,6 +24,7 @@ package hedera */ import ( + "strings" "testing" "github.com/stretchr/testify/assert" @@ -212,3 +213,27 @@ func TestIntegrationAccountBalanceQueryWorksWithHollowAccountAlias(t *testing.T) err = CloseIntegrationTestEnv(env, nil) require.NoError(t, err) } + +func TestIntegrationAccountBalanceQueryCanConnectToMainnetTls(t *testing.T) { + t.Parallel() + client := ClientForMainnet() + client.SetTransportSecurity(true) + + succeededOnce := false + for address, accountID := range client.GetNetwork() { + + if !strings.HasSuffix(address, ":50212") { + t.Errorf("Expected entry key to end with ':50212', but got %s", address) + } + + accountIDs := []AccountID{accountID} + _, err := NewAccountBalanceQuery(). + SetNodeAccountIDs(accountIDs). + SetAccountID(accountID). + Execute(client) + if err == nil { + succeededOnce = true + } + } + assert.True(t, succeededOnce) +} diff --git a/endpoint.go b/endpoint.go index 00e0dd28..0ad3c656 100644 --- a/endpoint.go +++ b/endpoint.go @@ -27,17 +27,17 @@ import ( ) type Endpoint struct { - address IPv4Address + address []byte port int32 domainName string } -func (endpoint *Endpoint) SetAddress(address IPv4Address) *Endpoint { +func (endpoint *Endpoint) SetAddress(address []byte) *Endpoint { endpoint.address = address return endpoint } -func (endpoint *Endpoint) GetAddress() IPv4Address { +func (endpoint *Endpoint) GetAddress() []byte { return endpoint.address } @@ -67,7 +67,7 @@ func EndpointFromProtobuf(serviceEndpoint *services.ServiceEndpoint) Endpoint { } return Endpoint{ - address: Ipv4AddressFromProtobuf(serviceEndpoint.GetIpAddressV4()), + address: serviceEndpoint.GetIpAddressV4(), port: port, domainName: serviceEndpoint.GetDomainName(), } @@ -75,7 +75,7 @@ func EndpointFromProtobuf(serviceEndpoint *services.ServiceEndpoint) Endpoint { func (endpoint *Endpoint) _ToProtobuf() *services.ServiceEndpoint { return &services.ServiceEndpoint{ - IpAddressV4: endpoint.address._ToProtobuf(), + IpAddressV4: endpoint.address, Port: endpoint.port, DomainName: endpoint.domainName, } @@ -86,6 +86,11 @@ func (endpoint *Endpoint) String() string { // If domain name is populated domainName + port return endpoint.domainName + ":" + fmt.Sprintf("%d", endpoint.port) } else { - return endpoint.address.String() + ":" + fmt.Sprintf("%d", endpoint.port) + return fmt.Sprintf("%d.%d.%d.%d:%d", + int(endpoint.address[0])&0xFF, + int(endpoint.address[1])&0xFF, + int(endpoint.address[2])&0xFF, + int(endpoint.address[3])&0xFF, + endpoint.port) } } diff --git a/examples/dab/main.go b/examples/dab/main.go index a06e48f8..2bccfe6c 100644 --- a/examples/dab/main.go +++ b/examples/dab/main.go @@ -36,8 +36,7 @@ func main() { description := "Hedera™ cryptocurrency" newDescription := "Hedera™ cryptocurrency - updated" - ipv4 := hedera.IPv4Address{} - ipv4.SetNetwork(0, 0).SetHost(0, 0) + ipv4 := []byte{127, 0, 0, 1} gossipEndpoint := hedera.Endpoint{} gossipEndpoint.SetAddress(ipv4).SetPort(50211) diff --git a/ipv4_address.go b/ipv4_address.go deleted file mode 100644 index dc64106e..00000000 --- a/ipv4_address.go +++ /dev/null @@ -1,67 +0,0 @@ -package hedera - -/*- - * - * Hedera Go SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -type IPv4Address struct { - network IPv4AddressPart - host IPv4AddressPart -} - -func (ip *IPv4Address) SetNetwork(left byte, right byte) *IPv4Address { - ip.network.left = left - ip.network.right = right - return ip -} - -func (ip *IPv4Address) GetNetwork() IPv4AddressPart { - return ip.network -} - -func (ip *IPv4Address) SetHost(left byte, right byte) *IPv4Address { - ip.host.left = left - ip.host.right = right - return ip -} - -func (ip *IPv4Address) GetHost() IPv4AddressPart { - return ip.host -} - -func Ipv4AddressFromProtobuf(byte []byte) IPv4Address { - return IPv4Address{ - network: IPv4AddressPart{ - left: byte[0], - right: byte[1], - }, - host: IPv4AddressPart{ - left: byte[2], - right: byte[3], - }, - } -} - -func (ip *IPv4Address) _ToProtobuf() []byte { - return []byte{ip.network.left, ip.network.right, ip.host.left, ip.host.right} -} - -func (ip *IPv4Address) String() string { - return ip.network.String() + "." + ip.host.String() -} diff --git a/ipv4_address_part.go b/ipv4_address_part.go deleted file mode 100644 index 69a76b75..00000000 --- a/ipv4_address_part.go +++ /dev/null @@ -1,52 +0,0 @@ -package hedera - -/*- - * - * Hedera Go SDK - * - * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -import ( - "fmt" -) - -type IPv4AddressPart struct { - left byte - right byte -} - -func (ip *IPv4AddressPart) SetLeft(left byte) *IPv4AddressPart { - ip.left = left - return ip -} - -func (ip *IPv4AddressPart) GetLeft() byte { - return ip.left -} - -func (ip *IPv4AddressPart) SetRight(right byte) *IPv4AddressPart { - ip.right = right - return ip -} - -func (ip *IPv4AddressPart) GetRight() byte { - return ip.right -} - -func (ip *IPv4AddressPart) String() string { - return fmt.Sprintf("%d.%d", uint(ip.left), uint(ip.right)) -} diff --git a/node_create_transaction_unit_test.go b/node_create_transaction_unit_test.go index 25fa7726..59b4789b 100644 --- a/node_create_transaction_unit_test.go +++ b/node_create_transaction_unit_test.go @@ -78,16 +78,7 @@ func endpoints(offsets ...uint) []Endpoint { for _, offset := range offsets { endpoints = append(endpoints, Endpoint{ - address: IPv4Address{ - network: IPv4AddressPart{ - left: byte(offset), - right: byte(offset), - }, - host: IPv4AddressPart{ - left: byte(offset), - right: byte(offset), - }, - }, + address: []byte{byte(offset), byte(offset), byte(offset), byte(offset)}, }) } diff --git a/query.go b/query.go index df6065c9..e556a73a 100644 --- a/query.go +++ b/query.go @@ -203,7 +203,7 @@ func (q *Query) SetPaymentTransactionID(transactionID TransactionID) *Query { func (q *Query) execute(client *Client, e QueryInterface) (*services.Response, error) { q.client = client - if client == nil || client.operator == nil { + if client == nil { return nil, errNoClientProvided }