mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-09 14:18:03 -05:00
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
// Copyright 2023 The AthanorLabs/atomic-swap Authors
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Environment represents the environment the swap will run in (ie. mainnet, stagenet, or development)
|
|
type Environment byte
|
|
|
|
const (
|
|
// Undefined is a placeholder, do not pass it to functions
|
|
Undefined Environment = iota
|
|
// Mainnet is for real use with mainnet monero and ethereum endpoints
|
|
Mainnet
|
|
// Stagenet is for testing with stagenet monero and gorerli ethereum endpoints
|
|
Stagenet
|
|
// Development is for testing with a local monerod in regtest mode and Ganache simulating ethereum
|
|
Development
|
|
// Bootnode should only be used by bootnodes, which provide a chain independent service
|
|
Bootnode
|
|
)
|
|
|
|
// String ...
|
|
func (env Environment) String() string {
|
|
switch env {
|
|
case Mainnet:
|
|
return "mainnet"
|
|
case Stagenet:
|
|
return "stagenet"
|
|
case Development:
|
|
return "dev"
|
|
case Bootnode:
|
|
return "bootnode"
|
|
}
|
|
|
|
return "undefined"
|
|
}
|
|
|
|
// NewEnv converts an environment string into the Environment type
|
|
func NewEnv(envStr string) (Environment, error) {
|
|
switch strings.ToLower(envStr) {
|
|
case "mainnet":
|
|
return Mainnet, nil
|
|
case "stagenet":
|
|
return Stagenet, nil
|
|
case "dev":
|
|
return Development, nil
|
|
case "bootnode":
|
|
return Bootnode, nil
|
|
default:
|
|
return Undefined, fmt.Errorf(`unknown environment %q, expected "mainnet", "stagenet" or "dev"`, envStr)
|
|
}
|
|
}
|