Skip to content

Commit

Permalink
chore: fix several lints
Browse files Browse the repository at this point in the history
  • Loading branch information
qtbeee authored and janaakhterov committed Jul 24, 2020
1 parent 4aa01d5 commit bb589f2
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 45 deletions.
4 changes: 2 additions & 2 deletions account_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ func (id AccountID) toProto() *proto.AccountID {

// UnmarshalJSON implements the encoding.JSON interface.
func (id *AccountID) UnmarshalJSON(data []byte) error {
accountId, err := AccountIDFromString(strings.Replace(string(data), "\"", "", 2))
accountID, err := AccountIDFromString(strings.Replace(string(data), "\"", "", 2))

if err != nil {
println("error was not nil")
return err
}

id = &accountId
id = &accountID

return nil
}
Expand Down
39 changes: 20 additions & 19 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/hashgraph/hedera-sdk-go/proto"
"google.golang.org/grpc"
"io/ioutil"
"math/rand"
"os"

"github.com/hashgraph/hedera-sdk-go/proto"
"google.golang.org/grpc"
)

// Default max fees and payments to 1 h-bar
Expand All @@ -33,7 +34,7 @@ type node struct {
address string
}

// Transaction signer is a closure or function that defines how transactions will be signed
// TransactionSigner is a closure or function that defines how transactions will be signed
type TransactionSigner func(message []byte) []byte

type operator struct {
Expand All @@ -44,23 +45,23 @@ type operator struct {
}

var mainnetNodes = map[string]AccountID{
"35.237.200.180:50211": AccountID{Account: 3},
"35.186.191.247:50211": AccountID{Account: 4},
"35.192.2.25:50211": AccountID{Account: 5},
"35.199.161.108:50211": AccountID{Account: 6},
"35.203.82.240:50211": AccountID{Account: 7},
"35.236.5.219:50211": AccountID{Account: 8},
"35.197.192.225:50211": AccountID{Account: 9},
"35.242.233.154:50211": AccountID{Account: 10},
"35.240.118.96:50211": AccountID{Account: 11},
"35.204.86.32:50211": AccountID{Account: 12},
"35.237.200.180:50211": {Account: 3},
"35.186.191.247:50211": {Account: 4},
"35.192.2.25:50211": {Account: 5},
"35.199.161.108:50211": {Account: 6},
"35.203.82.240:50211": {Account: 7},
"35.236.5.219:50211": {Account: 8},
"35.197.192.225:50211": {Account: 9},
"35.242.233.154:50211": {Account: 10},
"35.240.118.96:50211": {Account: 11},
"35.204.86.32:50211": {Account: 12},
}

var testnetNodes = map[string]AccountID{
"0.testnet.hedera.com:50211": AccountID{Account: 3},
"1.testnet.hedera.com:50211": AccountID{Account: 4},
"2.testnet.hedera.com:50211": AccountID{Account: 5},
"3.testnet.hedera.com:50211": AccountID{Account: 6},
"0.testnet.hedera.com:50211": {Account: 3},
"1.testnet.hedera.com:50211": {Account: 4},
"2.testnet.hedera.com:50211": {Account: 5},
"3.testnet.hedera.com:50211": {Account: 6},
}

// ClientForMainnet returns a preconfigured client for use with the standard
Expand Down Expand Up @@ -132,7 +133,7 @@ func ClientFromJSON(jsonBytes []byte) (*Client, error) {
return client, nil
}

operatorId, err := AccountIDFromString(clientConfig.Operator.AccountID)
operatorID, err := AccountIDFromString(clientConfig.Operator.AccountID)
if err != nil {
return nil, err
}
Expand All @@ -143,7 +144,7 @@ func ClientFromJSON(jsonBytes []byte) (*Client, error) {
}

operator := operator{
accountID: operatorId,
accountID: operatorID,
privateKey: &operatorKey,
publicKey: operatorKey.PublicKey(),
signer: operatorKey.Sign,
Expand Down
11 changes: 6 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package hedera

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

const testClientJson string = `{
const testClientJSON string = `{
"network": {
"0.0.3": "35.237.200.180:50211",
"0.0.4": "35.186.191.247:50211",
Expand All @@ -20,7 +21,7 @@ const testClientJson string = `{
}
}`

const testClientJsonWithOperator string = `{
const testClientJSONWithOperator string = `{
"network": {
"0.0.3": "35.237.200.180:50211",
"0.0.4": "35.186.191.247:50211",
Expand All @@ -40,7 +41,7 @@ const testClientJsonWithOperator string = `{
}`

func TestClientFromJSON(t *testing.T) {
client, err := ClientFromJSON([]byte(testClientJson))
client, err := ClientFromJSON([]byte(testClientJSON))
assert.NoError(t, err)

assert.NotNil(t, client)
Expand All @@ -49,7 +50,7 @@ func TestClientFromJSON(t *testing.T) {
}

func TestClientFromJSONWithOperator(t *testing.T) {
client, err := ClientFromJSON([]byte(testClientJsonWithOperator))
client, err := ClientFromJSON([]byte(testClientJSONWithOperator))
assert.NoError(t, err)

assert.NotNil(t, client)
Expand Down
9 changes: 7 additions & 2 deletions consensus_message_submit_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func NewConsensusMessageSubmitTransaction() ConsensusMessageSubmitTransaction {
pb := &proto.ConsensusSubmitMessageTransactionBody{}

inner := newTransactionBuilder()
inner.pb.Data = &proto.TransactionBody_ConsensusSubmitMessage{pb}
inner.pb.Data = &proto.TransactionBody_ConsensusSubmitMessage{ConsensusSubmitMessage: pb}

builder := ConsensusMessageSubmitTransaction{inner, pb, 10, nil, ConsensusTopicID{}, TransactionID{}, 0, 0, false}

return builder
}

// SetTopic sets the topic to submit the message to.
// SetTopicID sets the topic to submit the message to.
func (builder ConsensusMessageSubmitTransaction) SetTopicID(id ConsensusTopicID) ConsensusMessageSubmitTransaction {
builder.topicID = id
return builder
Expand Down Expand Up @@ -161,6 +161,7 @@ func (builder ConsensusMessageSubmitTransaction) Build(client *Client) (Transact
// We override the embedded fluent setter methods to return the outer type
//

// SetMaxTransactionFee sets the max transaction fee for this Transaction.
func (builder ConsensusMessageSubmitTransaction) SetMaxTransactionFee(maxTransactionFee Hbar) ConsensusMessageSubmitTransaction {
return ConsensusMessageSubmitTransaction{
builder.TransactionBuilder.SetMaxTransactionFee(maxTransactionFee),
Expand All @@ -175,6 +176,7 @@ func (builder ConsensusMessageSubmitTransaction) SetMaxTransactionFee(maxTransac
}
}

// SetMemo sets the memo for this Transaction.
func (builder ConsensusMessageSubmitTransaction) SetMemo(memo string) ConsensusMessageSubmitTransaction {
return ConsensusMessageSubmitTransaction{builder.TransactionBuilder.SetTransactionMemo(memo),
builder.pb,
Expand All @@ -188,6 +190,7 @@ func (builder ConsensusMessageSubmitTransaction) SetMemo(memo string) ConsensusM
}
}

// SetTransactionValidDuration sets the valid duration for this Transaction.
func (builder ConsensusMessageSubmitTransaction) SetTransactionValidDuration(validDuration time.Duration) ConsensusMessageSubmitTransaction {
return ConsensusMessageSubmitTransaction{builder.TransactionBuilder.SetTransactionValidDuration(validDuration),
builder.pb,
Expand All @@ -201,6 +204,7 @@ func (builder ConsensusMessageSubmitTransaction) SetTransactionValidDuration(val
}
}

// SetTransactionID sets the TransactionID for this Transaction.
func (builder ConsensusMessageSubmitTransaction) SetTransactionID(transactionID TransactionID) ConsensusMessageSubmitTransaction {
return ConsensusMessageSubmitTransaction{builder.TransactionBuilder.SetTransactionID(transactionID),
builder.pb,
Expand All @@ -214,6 +218,7 @@ func (builder ConsensusMessageSubmitTransaction) SetTransactionID(transactionID
}
}

// SetNodeAccountID sets the node AccountID for this Transaction.
func (builder ConsensusMessageSubmitTransaction) SetNodeAccountID(nodeAccountID AccountID) ConsensusMessageSubmitTransaction {
return ConsensusMessageSubmitTransaction{builder.TransactionBuilder.SetNodeAccountID(nodeAccountID),
builder.pb,
Expand Down
5 changes: 3 additions & 2 deletions consensus_topic_info_query.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package hedera

import (
"github.com/hashgraph/hedera-sdk-go/proto"
"time"

"github.com/hashgraph/hedera-sdk-go/proto"
)

type ConsensusTopicInfoQuery struct {
Expand Down Expand Up @@ -32,7 +33,7 @@ func NewConsensusTopicInfoQuery() *ConsensusTopicInfoQuery {
return &ConsensusTopicInfoQuery{inner, pb}
}

// SetTopicId sets the topic to retrieve info about (the parameters and running state of).
// SetTopicID sets the topic to retrieve info about (the parameters and running state of).
func (builder *ConsensusTopicInfoQuery) SetTopicID(id ConsensusTopicID) *ConsensusTopicInfoQuery {
builder.pb.TopicID = id.toProto()
return builder
Expand Down
2 changes: 1 addition & 1 deletion contract_bytecode_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/hashgraph/hedera-sdk-go/proto"
)

// ContractBytcodeQuery retrieves the bytecode for a smart contract instance
// ContractBytecodeQuery retrieves the bytecode for a smart contract instance
type ContractBytecodeQuery struct {
QueryBuilder
pb *proto.ContractGetBytecodeQuery
Expand Down
5 changes: 3 additions & 2 deletions contract_create_transaction.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package hedera

import (
"github.com/hashgraph/hedera-sdk-go/proto"
"time"

"github.com/hashgraph/hedera-sdk-go/proto"
)

// ContractCreateTransaction starts a new smart contract instance. After the instance is created, the ContractID for it
Expand Down Expand Up @@ -60,7 +61,7 @@ func (builder ContractCreateTransaction) SetBytecodeFileID(id FileID) ContractCr
return builder
}

// SetAdminKeyu sets the key required to arbitrarily modify the state of the instance and its fields. If this is left
// SetAdminKey sets the key required to arbitrarily modify the state of the instance and its fields. If this is left
// unset, then such modifications are not possible, and there is no administrator that can override the normal operation
// of the smart contract instance. Note that if it is created with no admin keys, then there is no administrator to
// authorize changing the admin keys, so there can never be any admin keys for that instance.
Expand Down
3 changes: 2 additions & 1 deletion contract_function_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hedera

import (
"encoding/binary"

"github.com/hashgraph/hedera-sdk-go/proto"
)

Expand Down Expand Up @@ -77,7 +78,7 @@ func (result ContractFunctionResult) GetBytes32(index uint64) []byte {
return result.ContractCallResult[index*32 : index*32+32]
}

// GetStrings gets a string from the result at the given index
// GetString gets a string from the result at the given index
func (result ContractFunctionResult) GetString(index uint64) string {
return string(result.GetBytes(index))
}
Expand Down
9 changes: 5 additions & 4 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"encoding/hex"
"encoding/pem"
"fmt"
"golang.org/x/crypto/ed25519"
"golang.org/x/crypto/pbkdf2"
"io"
"io/ioutil"
"strings"

"golang.org/x/crypto/ed25519"
"golang.org/x/crypto/pbkdf2"

"github.com/hashgraph/hedera-sdk-go/proto"
)

Expand Down Expand Up @@ -122,7 +123,7 @@ func Ed25519PrivateKeyFromMnemonic(mnemonic Mnemonic, passPhrase string) (Ed2551
digest := h.Sum(nil)

keyBytes := digest[0:32]
chainCode := digest[32:len(digest)]
chainCode := digest[32:]

// note the index is for derivation, not the index of the slice
for _, index := range []uint32{44, 3030, 0, 0} {
Expand Down Expand Up @@ -277,7 +278,7 @@ func deriveChildKey(parentKey []byte, chainCode []byte, index uint32) ([]byte, [
h.Write(input)
digest := h.Sum(nil)

return digest[0:32], digest[32:len(digest)]
return digest[0:32], digest[32:]
}

// PublicKey returns the Ed25519PublicKey associated with this Ed25519PrivateKey.
Expand Down
3 changes: 2 additions & 1 deletion crypto_transfer_transaction.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package hedera

import (
"github.com/hashgraph/hedera-sdk-go/proto"
"time"

"github.com/hashgraph/hedera-sdk-go/proto"
)

// Transfer hbar from some account balances to other account balances. The accounts list can contain up to 10 accounts.
Expand Down
5 changes: 3 additions & 2 deletions file_create_transaction.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package hedera

import (
"github.com/hashgraph/hedera-sdk-go/proto"
"time"

"github.com/hashgraph/hedera-sdk-go/proto"
)

// FileCreateTransaction creates a new file, containing the given contents. It is referenced by its FileID, and does
Expand Down Expand Up @@ -34,7 +35,7 @@ func NewFileCreateTransaction() FileCreateTransaction {
return builder
}

// AddKeys adds a key to the internal list of keys associated with the file. All of the keys on the list must sign to
// AddKey adds a key to the internal list of keys associated with the file. All of the keys on the list must sign to
// create or modify a file, but only one of them needs to sign in order to delete the file. Each of those "keys" may
// itself be threshold key containing other keys (including other threshold keys). In other words, the behavior is an
// AND for create/modify, OR for delete. This is useful for acting as a revocation server. If it is desired to have the
Expand Down
9 changes: 5 additions & 4 deletions file_update_transaction_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package hedera

import (
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestSerializeFileUpdateTransaction(t *testing.T) {
Expand Down Expand Up @@ -66,11 +67,11 @@ func TestFileUpdateTransaction_Execute(t *testing.T) {
fileID := receipt.fileID
assert.NotNil(t, fileID)

var new_contents = []byte("Good Night, World")
var newContents = []byte("Good Night, World")

txID, err = NewFileUpdateTransaction().
SetFileID(*fileID).
SetContents(new_contents).
SetContents(newContents).
Execute(client)

assert.NoError(t, err)
Expand All @@ -83,7 +84,7 @@ func TestFileUpdateTransaction_Execute(t *testing.T) {
Execute(client)
assert.NoError(t, err)

assert.Equal(t, new_contents, contents)
assert.Equal(t, newContents, contents)

txID, err = NewFileDeleteTransaction().
SetFileID(*fileID).
Expand Down

0 comments on commit bb589f2

Please sign in to comment.