From c76c08162d90e1fe4585197afb362e6796d249c6 Mon Sep 17 00:00:00 2001 From: Yukai Date: Fri, 10 Jun 2022 11:51:26 -0700 Subject: [PATCH] lint --- cmd/server/main.go | 8 ++++---- mapper/helper.go | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index c93f8ac6..f2a41cce 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -124,14 +124,14 @@ func main() { } asserter, err := asserter.NewServer( - mapper.OperationTypes, // supported operation types - true, // historical balance lookup + mapper.OperationTypes, // supported operation types + true, // historical balance lookup []*types.NetworkIdentifier{ // supported networks networkP, networkC, }, - []string{}, // call methods - false, // mempool coins + []string{}, // call methods + false, // mempool coins ) if err != nil { log.Fatal("server asserter init error:", err) diff --git a/mapper/helper.go b/mapper/helper.go index 70eaea6a..b78b4c4d 100644 --- a/mapper/helper.go +++ b/mapper/helper.go @@ -8,6 +8,9 @@ import ( "github.com/coinbase/rosetta-sdk-go/types" ) +var errUnsupportedChain = errors.New("unsupported chain") +var errUnsupportedNetwork = errors.New("unsupported network") + // EqualFoldContains checks if the array contains the string regardless of casing func EqualFoldContains(arr []string, str string) bool { for _, a := range arr { @@ -20,31 +23,27 @@ func EqualFoldContains(arr []string, str string) bool { // IsPChain checks network identifier to make sure sub-network identifier set to "P" func IsPChain(networkIdentifier *types.NetworkIdentifier) bool { - if networkIdentifier != nil && + return networkIdentifier != nil && networkIdentifier.SubNetworkIdentifier != nil && - networkIdentifier.SubNetworkIdentifier.Network == PChainNetworkIdentifier { - return true - } - - return false + networkIdentifier.SubNetworkIdentifier.Network == PChainNetworkIdentifier } // GetAliasAndHRP fetches chain id alias and hrp for address formatting. // Right now only P chain id alias is supported func GetAliasAndHRP(networkIdentifier *types.NetworkIdentifier) (string, string, error) { - var chainIDAlias, hrp string if !IsPChain(networkIdentifier) { - return "", "", errors.New("only support P chain alias") + return "", "", errUnsupportedChain } - chainIDAlias = PChainIDAlias + + var hrp string switch networkIdentifier.Network { case FujiNetwork: hrp = constants.GetHRP(constants.FujiID) case MainnetNetwork: hrp = constants.GetHRP(constants.MainnetID) default: - return "", "", errors.New("can't recognize network") + return "", "", errUnsupportedNetwork } - return chainIDAlias, hrp, nil + return PChainIDAlias, hrp, nil }