Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiaff committed Jun 10, 2022
1 parent 653c8f8 commit 48b596a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
8 changes: 4 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 10 additions & 11 deletions mapper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

0 comments on commit 48b596a

Please sign in to comment.