common

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Major uint = 0
	Minor uint = 5
	Patch uint = 0
)

These constants define the application version and follow the semantic versioning 2.0.0 spec (http://semver.org/).

Variables

View Source
var (
	// PreRelease is defined as a variable so it can be overridden during
	// the build process with '-ldflags "-X github.com/btceasypay/bitcoinpay/version.PreRelease=foo"' if
	// needed.  It MUST only contain characters from semanticAlphabet per
	// the semantic versioning spec.
	PreRelease = ""

	// appBuild is defined as a variable so it can be overridden during the
	// build process with '-ldflags "-X github.com/btceasypay/bitcoinpay/version.Build=foo"' if needed.  It
	// MUST only contain characters from semanticBuildAlphabet per the
	// semantic versioning spec.
	Build = "dev"
)
View Source
var CurrentHeight = uint64(0)
View Source
var DevicesTypesForCPUMining = cl.DeviceTypeCPU
View Source
var DevicesTypesForGPUMining = cl.DeviceTypeGPU
View Source
var JobID = ""
View Source
var MinerLoger log.Logger

log is a logger that is initialized with no output filters. This means the package will not perform any logging by default until the caller requests it.

Functions

func AppDataDir

func AppDataDir(appName string, roaming bool) string

AppDataDir returns an operating system specific directory to be used for storing application data for an application.

The appName parameter is the name of the application the data directory is being requested for. This function will prepend a period to the appName for POSIX style operating systems since that is standard practice. An empty appName or one with a single dot is treated as requesting the current directory so only "." will be returned. Further, the first character of appName will be made lowercase for POSIX style operating systems and uppercase for Mac and Windows since that is standard practice.

The roaming parameter only applies to Windows where it specifies the roaming application data profile (%APPDATA%) should be used instead of the local one (%LOCALAPPDATA%) that is used by default.

Example results:

dir := AppDataDir("myapp", false)
 POSIX (Linux/BSD): ~/.myapp
 Mac OS: $HOME/Library/Application Support/Myapp
 Windows: %LOCALAPPDATA%\Myapp
 Plan 9: $home/myapp

func BlockBitsToTarget

func BlockBitsToTarget(bits string, width int) []byte

func CheckBase58Addr

func CheckBase58Addr(addr, network string, p *params.Params) bool

func ConvertHashToString

func ConvertHashToString(hash bitcoinpay.Hash) string

func ConvertLogLevel

func ConvertLogLevel(level string) l.Lvl

func DiffToTarget

func DiffToTarget(diff float64, powLimit *big.Int, powType pow.PowType) (*big.Int, error)

func FormatHashRate

func FormatHashRate(h float64, unit string) string

FormatHashRate sets the units properly when displaying a hashrate.

func GetCurrentDir

func GetCurrentDir() string

func GetDevices

func GetDevices(t cl.DeviceType, needPlatform string) []*cl.Device

func GetNeedHashTimesByTarget

func GetNeedHashTimesByTarget(target string) *big.Int

func GetVersion

func GetVersion() string

func HexMustDecode

func HexMustDecode(hexStr string) []byte

func InArray

func InArray(val interface{}, arr interface{}) bool

func InitNet

func InitNet(network string, p *params.Params) *params.Params

func Int2lehex

func Int2lehex(x int64, width int) string

func Int2varinthex

func Int2varinthex(x int64) string

func RandUint32

func RandUint32() (uint32, error)

func RandUint64

func RandUint64() uint64

func Reverse

func Reverse(src []byte) []byte

Reverse reverses a byte array.

func ReverseByWidth

func ReverseByWidth(s []byte, width int) []byte

func RolloverExtraNonce

func RolloverExtraNonce(v *uint32)

RolloverExtraNonce rolls over the extraNonce if it goes over 0x00FFFFFF many hashes, since the first byte is reserved for the ID.

func SliceContains

func SliceContains(s []uint64, e uint64) bool

func SliceRemove

func SliceRemove(s []uint64, e uint64) []uint64

func String

func String() string

version returns the application version as a properly formed string per the semantic versioning 2.0.0 spec (http://semver.org/).

func Target2BlockBits

func Target2BlockBits(target string) []byte

func Timeout

func Timeout(timeout time.Duration, runFunc func()) bool

func TimeoutRun

func TimeoutRun(timeout time.Duration, runFunc, afterFun func()) bool

func Uint32EndiannessSwap

func Uint32EndiannessSwap(v uint32) uint32

Uint32EndiannessSwap swaps the endianness of a uint32.

func UseLogger

func UseLogger(logger log.Logger)

UseLogger uses a specified Logger to output package logging info.

func Usleep

func Usleep(sec int)

Types

type CommandConfig

type CommandConfig struct {
	ListDevices bool `short:"l" long:"listdevices" description:"List number of devices."`
	Version     bool `short:"v" long:"version" description:"show the version of miner"`
}

type FileConfig

type FileConfig struct {
	ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"`
	// Debugging options
	MinerLogFile string `long:"minerlog" description:"Write miner log file"`
}

type GlobalConfig

type GlobalConfig struct {
	OptionConfig    OptionalConfig
	LogConfig       FileConfig
	DeviceConfig    CommandConfig
	SoloConfig      SoloConfig
	PoolConfig      PoolConfig
	NecessaryConfig NecessaryConfig
}

func LoadConfig

func LoadConfig() (*GlobalConfig, []string, error)

loadConfig initializes and parses the config using a config file and command line options.

The configuration proceeds as follows:

  1. Start with a default config with sane settings
  2. Pre-parse the command line to check for an alternative config file
  3. Load configuration file overwriting defaults with any specified options
  4. Parse CLI options and overwrite/add any specified options

The above results in btcd functioning properly without any config settings while still allowing the user to override settings with config files and command line options. Command line options always take precedence.

type NecessaryConfig

type NecessaryConfig struct {
	// Config / log options
	Pow     string `short:"P" long:"pow" description:"blake2bd|cuckaroo|cuckatoo"`
	Symbol  string `short:"S" long:"symbol" description:"Symbol" default-mask:"BTP"`
	NetWork string `short:"N" long:"network" description:"network privnet|testnet|mainnet" default-mask:"testnet"`
	Param   *params.Params
}

type OptionalConfig

type OptionalConfig struct {
	// Config / log options
	CPUMiner            bool   `long:"cpuminer" description:"CPUMiner" default-mask:"false"`
	Proxy               string `long:"proxy" description:"Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)"`
	ProxyUser           string `long:"proxyuser" description:"Username for proxy server"`
	ProxyPass           string `long:"proxypass" default-mask:"-" description:"Password for proxy server"`
	TrimmerCount        int    `long:"trimmerTimes" description:"the cuckaroo trimmer times"`
	Intensity           int    `` /* 132-byte string literal not displayed */
	WorkSize            int    `` /* 158-byte string literal not displayed */
	Timeout             int    `long:"timeout" description:"rpc timeout." default-mask:"60"`
	UseDevices          string `` /* 135-byte string literal not displayed */
	MaxTxCount          int    `long:"max_tx_count" description:"max pack tx count" default-mask:"1000"`
	MaxSigCount         int    `long:"max_sig_count" description:"max sign tx count" default-mask:"4000"`
	LogLevel            string `long:"log_level" description:"info|debug|error|warn|trace" default-mask:"info"`
	StatsServer         string `long:"stats_server" description:"stats web server" default-mask:"127.0.0.1:1235"`
	Restart             int    ` description:"restart server" default-mask:"0"`
	Accept              int    ` description:"Accept count" default-mask:"0"`
	Reject              int    ` description:"Reject count" default-mask:"0"`
	Stale               int    ` description:"Stale count" default-mask:"0"`
	Target              string ` description:"Target"`
	EdgeBits            int    `long:"edge_bits" description:"edge bits" default-mask:"24"`
	LocalSize           int    `long:"local_size" description:"local size" default-mask:"4096"`
	GroupSize           int    `long:"group_size" description:"work group size" default-mask:"256"`
	Cuda                bool   `long:"cuda" description:"is cuda" default-mask:"false"`
	TaskInterval        int    `long:"task_interval" description:"get blocktemplate interval" default-mask:"2"`
	TaskForceStop       bool   `` /* 152-byte string literal not displayed */
	MiningSyncMode      bool   `long:"mining_sync_mode" description:"force stop the current task when new task come." default-mask:"true"`
	ForceSolo           bool   `long:"force_solo" description:"force solo mining" default-mask:"false"`
	BigGraphStartHeight int    `` /* 139-byte string literal not displayed */
	Expand              int    `long:"expand" description:"expand enum 0,1,2" default-mask:"0"`
	Ntrims              int    `long:"ntrims" description:"trim times " default-mask:"50"`
	Genablocks          int    `long:"genablocks" description:"genablocks" default-mask:"4096"`
	Genatpb             int    `long:"genatpb" description:"genatpb" default-mask:"256"`
	Genbtpb             int    `long:"genbtpb" description:"genbtpb" default-mask:"256"`
	Trimtpb             int    `long:"trimtpb" description:"genbtpb" default-mask:"64"`
	Tailtpb             int    `long:"tailtpb" description:"tailtpb" default-mask:"1024"`
	Recoverblocks       int    `long:"recoverblocks" description:"recoverblocks" default-mask:"1024"`
	Recovertpb          int    `long:"recovertpb" description:"recovertpb" default-mask:"1024"`
}

type PoolConfig

type PoolConfig struct {
	// Pool related options
	Pool         string `short:"o" long:"pool" description:"Pool to connect to (e.g.stratum+tcp://pool:port)"`
	PoolUser     string `short:"m" long:"pooluser" description:"Pool username"`
	PoolPassword string `short:"n" long:"poolpass" default-mask:"-" description:"Pool password"`
}

type RpcClient

type RpcClient struct {
	Cfg *GlobalConfig
}

func (*RpcClient) RpcResult

func (rpc *RpcClient) RpcResult(method string, params []interface{}) []byte

type SoloConfig

type SoloConfig struct {
	// RPC connection options
	MinerAddr   string `short:"M" long:"mineraddress" description:"Miner Address" default-mask:""`
	RPCServer   string `short:"s" long:"rpcserver" description:"RPC server to connect to"`
	RPCUser     string `short:"u" long:"rpcuser" description:"RPC username"`
	RPCPassword string `short:"p" long:"rpcpass" default-mask:"-" description:"RPC password"`
	RandStr     string `long:"randstr" description:"Rand String,Your Unique Marking." default-mask:"Come from Bitcoinpay!"`
	NoTLS       bool   `long:"notls" description:"Do not verify tls certificates" default-mask:"true"`
	RPCCert     string `long:"rpccert" description:"RPC server certificate chain for validation"`
}

Directories

Path Synopsis
Package flags provides an extensive command line option parser.
Package flags provides an extensive command line option parser.
Current limitations:
Current limitations:

Jump to

Keyboard shortcuts

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