Documentation ¶
Overview ¶
Package common is for miscellaneous constants, types and interfaces used by many packages.
Index ¶
- Constants
- func ChainNameFromEnv(env Environment) string
- func DefaultMoneroPortFromEnv(env Environment) uint
- func EthereumPrivateKeyToAddress(privkey *ecdsa.PrivateKey) ethcommon.Address
- func FileExists(path string) (bool, error)
- func GetFreeTCPPort() (uint, error)
- func GetTopic(sig string) ethcommon.Hash
- func MakeDir(dir string) error
- func ReceiptInfo(receipt *ethtypes.Receipt) string
- func Reverse(s []byte) []byte
- func SleepWithContext(ctx context.Context, d time.Duration) error
- func SwapTimeoutFromEnv(env Environment) time.Duration
- type Config
- type Environment
- type Message
- type MoneroNode
- type SwapState
- type SwapStateNet
- type SwapStateRPC
Constants ¶
const ( // DefaultMoneroWalletName is the default wallet name in {DATA_DIR}/wallet/ DefaultMoneroWalletName = "swap-wallet" // DefaultLibp2pKeyFileName is the default libp2p private key file name in {DATA_DIR} DefaultLibp2pKeyFileName = "net.key" // DefaultEthKeyFileName is the default ethereum private key file name in {DATA_DIR} DefaultEthKeyFileName = "eth.key" )
const ( DefaultMoneroDaemonMainnetPort = 18081 DefaultMoneroDaemonDevPort = DefaultMoneroDaemonMainnetPort DefaultMoneroDaemonStagenetPort = 38081 DefaultGanacheEndpoint = "http://127.0.0.1:8545" DefaultGanacheWSEndpoint = "ws://127.0.0.1:8545" DefaultSwapdPort = 5000 )
Daemon default ports and URLs
const ( DefaultPrivKeyXMRTaker = "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d" // index 0 DefaultPrivKeyXMRMaker = "6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1" // index 1 )
Ganache deterministic ethereum private wallet keys for the maker and taker in dev environments.
const ( TimeFmtSecs = "2006-01-02-15:04:05" TimeFmtNSecs = "2006-01-02-15:04:05.999999999" )
Strings for formatting time.Time types
const ( MainnetChainID = 1 OpMainnetChainID = 10 // Optimism SepoliaChainID = 11155111 GanacheChainID = 1337 HardhatChainID = 31337 )
Ethereum chain IDs
Variables ¶
This section is empty.
Functions ¶
func ChainNameFromEnv ¶ added in v0.4.0
func ChainNameFromEnv(env Environment) string
ChainNameFromEnv returns the expected chainID that we should find on the ethereum endpoint when running int the passed environment.
func DefaultMoneroPortFromEnv ¶
func DefaultMoneroPortFromEnv(env Environment) uint
DefaultMoneroPortFromEnv returns the default Monerod RPC port for an environment Reference: https://monerodocs.org/interacting/monerod-reference/
func EthereumPrivateKeyToAddress ¶
func EthereumPrivateKeyToAddress(privkey *ecdsa.PrivateKey) ethcommon.Address
EthereumPrivateKeyToAddress returns the address associated with a private key
func FileExists ¶
FileExists returns whether the given file exists. If a directory exists with the name of the passed file, an error is returned.
func GetFreeTCPPort ¶
GetFreeTCPPort returns an OS allocated and immediately freed port. There is nothing preventing something else on the system from using the port before the caller has a chance, but OS allocated ports are randomised to make the risk negligible.
func GetTopic ¶
GetTopic returns the Ethereum topic (ie. keccak256 hash) of the given event or function signature string.
func MakeDir ¶
MakeDir creates a directory, including leading directories, if they don't already exist. File permissions of created directories are only granted to the current user.
func ReceiptInfo ¶
ReceiptInfo creates a string for logging from an ethereum transaction receipt
func SleepWithContext ¶
SleepWithContext is the same as time.Sleep(...) but with preemption if the context is complete. Returns nil if the sleep completed, otherwise the context's error.
func SwapTimeoutFromEnv ¶
func SwapTimeoutFromEnv(env Environment) time.Duration
SwapTimeoutFromEnv returns the duration between swap timeouts given the environment.
Types ¶
type Config ¶
type Config struct { Env Environment DataDir string EthEndpoint string MoneroNodes []*MoneroNode SwapCreatorAddr ethcommon.Address Bootnodes []string }
Config contains constants that are defaults for various environments
func BootnodeConfig ¶ added in v0.4.0
func BootnodeConfig() *Config
BootnodeConfig is environment for bootnodes, which act across multiple environments
func ConfigDefaultsForEnv ¶
func ConfigDefaultsForEnv(env Environment) *Config
ConfigDefaultsForEnv returns the configuration defaults for the given environment.
func DevelopmentConfig ¶
func DevelopmentConfig() *Config
DevelopmentConfig is the monero and ethereum development environment configuration
func MainnetConfig ¶
func MainnetConfig() *Config
MainnetConfig is the mainnet ethereum and monero configuration
func StagenetConfig ¶
func StagenetConfig() *Config
StagenetConfig is the monero stagenet and ethereum Sepolia configuration
func (Config) EthKeyFileName ¶
EthKeyFileName returns the path to the ethereum key file, whose default value depends on current value of the data dir.
func (Config) LibP2PKeyFile ¶
LibP2PKeyFile returns the path to the libp2p key file, whose default value depends on current value of the data dir.
func (Config) MoneroWalletPath ¶
MoneroWalletPath returns the path to the wallet file, whose default value depends on current value of the data dir.
type Environment ¶
type Environment byte
Environment represents the environment the swap will run in (ie. mainnet, stagenet, or development)
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 )
func NewEnv ¶
func NewEnv(envStr string) (Environment, error)
NewEnv converts an environment string into the Environment type
type MoneroNode ¶
MoneroNode represents the host and port of monerod's RPC endpoint
type SwapState ¶
type SwapState interface { SwapStateNet SwapStateRPC }
SwapState is the interface used by other packages in *xmrtaker.swapState or *xmrmaker.swapState.
Directories ¶
Path | Synopsis |
---|---|
Package rpctypes provides the serialized types for queries and responses shared by swapd's JSON-RPC server and client-side libraries.
|
Package rpctypes provides the serialized types for queries and responses shared by swapd's JSON-RPC server and client-side libraries. |
Package types is for types that are shared by multiple packages
|
Package types is for types that are shared by multiple packages |