coin

package
v0.0.0-...-d953e0f Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2017 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package coin defines functions common to all masternode-based coins. Additionally, each coin which is implemented in this program will register itself with the coin package so that we can use this as the generic communication point for the client application. This draws a lot of inspiration from the `image` libraries in golang.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCouldNotConnectToServer = errors.New("couldn't connect to server")
	ErrAuthorizationFailed     = errors.New("authorization failure, bad rpcuser/rpcpass")
	ErrNoResponse              = errors.New("no response from server")
)

Functions

func Command

func Command(cli *types.CLI, cmd string, opts []string) error

Command executes a given coin's (specified by `name`), `cmd` function if one was registered. If the function was nil, then it has no implementation and we do nothing. If the command was not found we return an error.

func CreateConfFile

func CreateConfFile(fp string, m map[string]string) error

CreateConfFile generates a config file with the specified key-value pairs in `m`.

func DirExists

func DirExists(fp string) bool

DirExists returns true if `fp` is a directory and exists.

func ExecCmd

func ExecCmd(cmd string, args ...string) (io.ReadCloser, io.ReadCloser, error)

ExecCmd takes a executable at path specified by `cmd`, where `args` are a set of options to execute the command with. Returns the stdout, stderr and any errors from trying to execute the command. This function blocks until the command finishes.

func FileExists

func FileExists(fp string) bool

FileExists returns true if `fp` is a file and exists.

func GetRandomHex

func GetRandomHex(size int) string

Returns a random hex string of `size`.

func HomeDir

func HomeDir() string

HomeDir gets the user's home directory

func IsRegistered

func IsRegistered(name string) bool

IsRegistered returns true if the coin specified by `name` is known to the gomn system.

func LoadConfFile

func LoadConfFile(fp string) (map[string]string, error)

LoadConfFile returns a map of key-value pairs found in a `.conf` file pointed to by `fp`.

func RegisterCoin

func RegisterCoin(
	name string, port, rpcPort int,
	daemonBin, statusBin, configFile string,
	defWalletPath, defBinSubPath, defDataPath string,
	wdl *WalletDownloader, bdl *BootstrapDownloader,
	fnMap *FunctionMap, opaque interface{}) error

func RegisteredCoins

func RegisteredCoins() []string

RegisteredCoins returns a list of coins that the tool knows how to configure.

Types

type BootstrapDownloader

type BootstrapDownloader struct {
	DownloadURL     string // URL to fetch bootstrap archive
	CompressionType string // type of compression ["tar.gz", "zip", "none"]
}

func NewBootstrapDownloader

func NewBootstrapDownloader(url, ctype string) *BootstrapDownloader

NewBootstrapDownloader returns a new instance of a bootstrap downloader.

func (*BootstrapDownloader) DownloadToPath

func (b *BootstrapDownloader) DownloadToPath(bootstrapPath string, override *types.Bootstrap) error

DownloadToPath grabs a archive from a web url defined in `b` and extracts the file if needed into `bootstrapPath`.

type Coin

type Coin struct {

	// Coin specific functions to invoke!
	FnMap *FunctionMap
	// contains filtered or unexported fields
}

Coin represents all things needed to setup / interact-with or monitor a given coin's masternode.

func GetCoinByName

func GetCoinByName(name string) (*Coin, error)

func (*Coin) DoJSONRPCCommand

func (c *Coin) DoJSONRPCCommand(method string, params []interface{}) (*JSONRPCResponse, error)

DoJSONRPCCommand accepts a `method` and a list of values in `params` which will be sent over JSON RPC to the corresponding coin's daemon.

func (*Coin) DownloadBootstrap

func (c *Coin) DownloadBootstrap(args []string, override *types.Bootstrap) error

func (*Coin) DownloadWallet

func (c *Coin) DownloadWallet(args []string, override *types.Download) error

func (*Coin) GetBinPath

func (c *Coin) GetBinPath() string

func (*Coin) GetConfFilePath

func (c *Coin) GetConfFilePath() string

func (*Coin) GetConfig

func (c *Coin) GetConfig() map[string]string

func (*Coin) GetConfigValue

func (c *Coin) GetConfigValue(key string) string

GetConfigValue returns the value for a given key in the config file. Returns an empty string if the key is not found.

func (*Coin) GetDaemonBinPath

func (c *Coin) GetDaemonBinPath() string

func (*Coin) GetDataPath

func (c *Coin) GetDataPath() string

func (*Coin) GetName

func (c *Coin) GetName() string

func (*Coin) GetOpaque

func (c *Coin) GetOpaque() interface{}

func (*Coin) GetPort

func (c *Coin) GetPort() int

func (*Coin) GetRPCPort

func (c *Coin) GetRPCPort() int

func (*Coin) PrintCoinInfo

func (c *Coin) PrintCoinInfo(prefix string) error

PrintCoinInfo is a common function that can be used by all coin implementations to print common info for a given coin.

func (*Coin) StartDaemon

func (c *Coin) StartDaemon() error

func (*Coin) UpdateDynamic

func (c *Coin) UpdateDynamic(wallet, subpath, data string) error

type CoinFunc

type CoinFunc func(c *Coin, args []string) error

type CoinState

type CoinState struct {
	// contains filtered or unexported fields
}

CoinState represents a collection of dynamic coin properties that are only known at run-time.

type FunctionMap

type FunctionMap struct {
	InfoFn      CoinFunc
	DownloadFn  CoinFunc
	BootstrapFn CoinFunc
	ConfigureFn CoinFunc
	GetInfoFn   CoinFunc
}

func (*FunctionMap) Validate

func (fm *FunctionMap) Validate(c *Coin) error

type JSONRPCError

type JSONRPCError struct {
	Code    int64  `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

type JSONRPCResponse

type JSONRPCResponse struct {
	ID     int64                  `json:"id,omitempty"`
	Result map[string]interface{} `json:"result,omitempty"`
	Error  JSONRPCError           `json:"error,omitempty"`
}

type ProgressTracker

type ProgressTracker struct {
	// contains filtered or unexported fields
}

ProgressTracker implements the Write function so we can have it track the number of bytes being written.

func NewProgressTracker

func NewProgressTracker(total int64) *ProgressTracker

NewProgressTracker returns a instance that implements a writer interface so we can track progress of a download via a tee reader in the caller.

func (*ProgressTracker) Write

func (pt *ProgressTracker) Write(bs []byte) (int, error)

Write implements the Write function needed to satisfy the Writer interface.

type WalletDownloader

type WalletDownloader struct {
	Version         string // version of the wallet
	DownloadURL     string // url to fetch the wallet
	CompressionType string // type of compression ["tar.gz", "zip", "none"]
	Sha256sum       string // shasum for the download
	PathToBins      string // path from destination -> binary directory
}

WalletDownloader is a per-coin wallet fetcher.

func NewWalletDownloader

func NewWalletDownloader(v, url, ct, sha string) *WalletDownloader

NewWalletDownloader returns a new instance of a wallet downloader.

func (*WalletDownloader) DownloadToPath

func (w *WalletDownloader) DownloadToPath(walletPath string, override *types.Download) error

DownloadToPath grabs the underlying wallet file, and checks its sha256sum to verify that it is indeed the expected file. If so, it extracts the contents to the appropriate

Directories

Path Synopsis
Package pivx is a pivx specific implementation of the masternode monitor tool.
Package pivx is a pivx specific implementation of the masternode monitor tool.

Jump to

Keyboard shortcuts

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