common

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2023 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package common is for miscellaneous constants, types and interfaces used by many packages.

Index

Constants

View Source
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"
)
View Source
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

View Source
const (
	DefaultPrivKeyXMRTaker = "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d" // index 0
	DefaultPrivKeyXMRMaker = "6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1" // index 1
)

Ganache deterministic ethereum private wallet keys for the maker and taker in dev environments.

View Source
const (
	TimeFmtSecs  = "2006-01-02-15:04:05"
	TimeFmtNSecs = "2006-01-02-15:04:05.999999999"
)

Strings for formatting time.Time types

View Source
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

func FileExists(path string) (bool, error)

FileExists returns whether the given file exists. If a directory exists with the name of the passed file, an error is returned.

func GetFreeTCPPort

func GetFreeTCPPort() (uint, error)

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

func GetTopic(sig string) ethcommon.Hash

GetTopic returns the Ethereum topic (ie. keccak256 hash) of the given event or function signature string.

func MakeDir

func MakeDir(dir string) error

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

func ReceiptInfo(receipt *ethtypes.Receipt) string

ReceiptInfo creates a string for logging from an ethereum transaction receipt

func Reverse

func Reverse(s []byte) []byte

Reverse returns a copy of the slice with the bytes in reverse order

func SleepWithContext

func SleepWithContext(ctx context.Context, d time.Duration) error

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

func (c Config) EthKeyFileName() string

EthKeyFileName returns the path to the ethereum key file, whose default value depends on current value of the data dir.

func (Config) LibP2PKeyFile

func (c Config) LibP2PKeyFile() string

LibP2PKeyFile returns the path to the libp2p key file, whose default value depends on current value of the data dir.

func (Config) MoneroWalletPath

func (c Config) MoneroWalletPath() string

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

func (Environment) String

func (env Environment) String() string

String ...

type Message

type Message interface {
	String() string
	Encode() ([]byte, error)
	Type() byte
}

Message is implemented by all network messages

type MoneroNode

type MoneroNode struct {
	Host string
	Port uint
}

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.

type SwapStateNet

type SwapStateNet interface {
	HandleProtocolMessage(msg Message) error
	OfferID() types.Hash
	NotifyStreamClosed()
}

SwapStateNet handles incoming protocol messages for an initiated protocol. It is implemented by *xmrtaker.swapState and *xmrmaker.swapState

type SwapStateRPC

type SwapStateRPC interface {
	SendKeysMessage() Message
	OfferID() types.Hash
	Exit() error
}

SwapStateRPC contains the methods used by the RPC server into the 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL