common

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MonetdTomlDirDot    = ".monet"
	MonetcliTomlDirDot  = ".monetcli"
	MonetdTomlDirCaps   = "MONET"
	MonetcliTomlDirCaps = "MONETCLI"

	BabbleDir        = "babble"
	EthDir           = "eth"
	PwdFile          = "pwd.txt"
	PublishDir       = "publish"
	DefaultKeyfile   = "keyfile.json"
	EvmlcTomlDirCaps = "EVMLC"
	EvmlcTomlDirDot  = ".evmlc"

	TomlSuffix = ".toml"

	MonetdTomlName   = "monetd"
	MonetcliTomlName = "network"
	EvmlcTomlName    = "config"

	PeersJSON        = "peers.json"
	PeersGenesisJSON = "peers.genesis.json"
	GenesisJSON      = "genesis.json"

	PeersJSONTarget        = "babble/peers.json"
	PeersGenesisJSONTarget = "babble/peers.genesis.json"
	GenesisJSONTarget      = "eth/genesis.json"

	//  Commented out value was used when monetd repo was private
	//  DefaultSolidityContract = "https://raw.githubusercontent.com/mosaicnetworks/evm-lite/poa/e2e/smart-contracts/monet.sol"
	DefaultSolidityContract = "https://raw.githubusercontent.com/mosaicnetworks/monetd/master/smart-contract/genesis.sol"
	TemplateContract        = "template.sol"
	GenesisContract         = "contract0.sol"
	GenesisABI              = "contract0.abi"
	DefaultAccountBalance   = "1234000000000000000000"
	DefaultContractAddress  = "abbaabbaabbaabbaabbaabbaabbaabbaabbaabba"
)

Constants for files names and default values used in building configurations

View Source
const (
	ColourInfo    = color.FgGreen
	ColourWarning = color.FgHiMagenta
	ColourError   = color.FgHiRed
	ColourPrompt  = color.FgHiYellow
	ColourOther   = color.FgYellow
	ColourOutput  = color.FgHiCyan
	ColourDebug   = color.FgCyan
)

Colour constants used in the functions in src/common/logs.go

View Source
const (
	MsgInformation = 0
	MsgWarning     = 1
	MsgError       = 2
	MsgPrompt      = 3
	MsgDebug       = 4
	MsgOther       = 5
)

Log level constants

View Source
const (
	WizardExit                                            = "Exit"
	WizardTextCreateNewConfiguration                      = "Create New Configuration"
	WizardExitWithoutSavingChanges                        = "Exit Without Saving Changes"
	WizardEditExistingConfiguration                       = "Edit Existing Configuration"
	WizardChangeConfigDir                                 = "Change Configuration Directory"
	WizardRenameCurrentDirectoryandCreateNewConfiguration = "Rename Current Directory and Create New Configuration"
	WizardAddKeyPair                                      = "Add Key Pair"
	WizardCheckConfiguration                              = "Check Configuration"
	WizardCompile                                         = "Compile POA Contract"
	WizardGenerate                                        = "Generate Key Pair"
	WizardParams                                          = "Edit Params"
	WizardShow                                            = "Show Configuration"
	WizardView                                            = "View"
	WizardEdit                                            = "Edit"
	WizardDelete                                          = "Delete"
	WizardSaveChanges                                     = "Save Changes"
	WizardCancelChanges                                   = "Cancel Changes"
	WizardEditAgain                                       = "Edit Again"
	WizardPeers                                           = "Peers"
	WizardVersion                                         = "Version Info"
)

Constants for the labels used in Wizard select options. Constants are much safer than string literals for parsing the results of select commands.

Variables

View Source
var (
	//MonetdTomlDir contains the directory name for the monetd config
	//It varies by OS
	MonetdTomlDir string
	//MonetcliTomlDir contains the directory name for the monetd config
	//It varies by OS
	MonetcliTomlDir string
	//EvmlcTomlDir contains the directory name for the monetd config
	//It varies by OS
	EvmlcTomlDir string
)
View Source
var (
	//VerboseLogging controls where Message produces any output
	VerboseLogging = true
	//HideBanners Suppresses the figlet banner
	HideBanners = false
)

Functions

func Banner(msg string)

Banner outputs a title. It can be suppressed with a -q flag

func BannerTitle

func BannerTitle(msg string)

BannerTitle wraps ClearScreen, Banner and BlankLine to show a title on a cleared page with a blankline underneath

func BlankLine

func BlankLine()

BlankLine is a Wrapper function for a Blank Line on the terminal

func CheckIfExists

func CheckIfExists(dir string) bool

CheckIfExists checks if a file / directory exists

func CheckIsDir

func CheckIsDir(file string) (bool, error)

CheckIsDir checks if file is a directory

func CheckPeersAddress

func CheckPeersAddress(peerfile string, babbleListen string) (bool, error)

CheckPeersAddress verifies that a given peer is in the peers file In particular that the configured babble listener is in exactly the same form within the peers file

func ClearScreen

func ClearScreen()

ClearScreen clears the CLI screen. Implementation is OS-specific

func ContinuePrompt

func ContinuePrompt()

ContinuePrompt pauses until enter is pressed

func CopyFileContents

func CopyFileContents(src, dst string) (err error)

CopyFileContents writes the contents to src to a new file dst. This operation is silently destructive

func CreateNewConfig

func CreateNewConfig(configDir string) error

CreateNewConfig creates a new configuration with a single parameter. The defaults will take care of all else.

func DefaultHomeDir

func DefaultHomeDir(tomlDir string) (string, error)

DefaultHomeDir returns a default location for a configuration file.

func FaceOut

func FaceOut(NewColour color.Attribute)

FaceOut function

func GetMyIP

func GetMyIP() string

GetMyIP returns the IP address of this instance as a string.

func GetNodeSafeLabel

func GetNodeSafeLabel(moniker string) string

GetNodeSafeLabel converts a free format string into a node label friendly format Anything other than an alphanumeric is converted to _

func IsValidAddress

func IsValidAddress(v string) bool

IsValidAddress checks if is a valid ethereum style address

func LoadToml

func LoadToml(tomlFile string) (*toml.Tree, error)

LoadToml loads a toml file and returns a tree

func LoadTomlConfig

func LoadTomlConfig(configDir string) (*toml.Tree, error)

LoadTomlConfig is a wrapper to LoadToml, that explicitly loads a monetcli config

func Message

func Message(a ...interface{}) (n int, err error)

Message is a simple wrapper for stdout logging. Setting VerboseLayout to false disables its output

func MessageWithType

func MessageWithType(msgType int, a ...interface{}) (n int, err error)

MessageWithType is a central point for cli logging messages It colour codes the output, suppressing Debug messages if --verbose option not enabled

func PublicKeyHexToAddressHex

func PublicKeyHexToAddressHex(publicKey string) (string, error)

PublicKeyHexToAddressHex takes a Hex string public key and returns a hex string Ethereum style address

func RequestBool

func RequestBool(promptText string, defaultValue bool) bool

RequestBool prompts the user for a boolean answer and parses the string to return a bool type

func RequestFile

func RequestFile(promptText string, defaultValue string) string

RequestFile prompts the user for a file name.

func RequestPassword

func RequestPassword(promptText string, defaultValue string) string

RequestPassword prompts the user for input using a mask to hide their answer

func RequestSelect

func RequestSelect(promptText string, answerSet []string, defaultValue string) string

RequestSelect is a wrapper to a promptui selecting one from an option

func RequestString

func RequestString(promptText string, defaultValue string) string

RequestString prompts the user for a string

func SafeRenameDir

func SafeRenameDir(origDir string) error

SafeRenameDir renames a folder to folder.~n~ where n is the lowest value where the folder does not already exist. n is capped at 100 - which would require the user to manually tidy the parent folder.

func SaveToml

func SaveToml(tree *toml.Tree, tomlFile string) error

SaveToml writes a tree (back) to a toml file

func SaveTomlConfig

func SaveTomlConfig(configDir string, tree *toml.Tree) error

SaveTomlConfig is a wrapper to SaveToml, that explicitly saves a monetcli config

func SetParamsWithParams

func SetParamsWithParams(configDir string) error

SetParamsWithParams allows the interactive editing of parameters in the cli config file

func ShowConfigFile

func ShowConfigFile(filename string) error

ShowConfigFile echoes the given file to screen

func TransformCliTomlToD

func TransformCliTomlToD(tree *toml.Tree, monetConfigDir string) error

TransformCliTomlToD process monetcli config to become a monetd config - largely by removing unused keys which are used for peers and genesis files.

func WriteToFile

func WriteToFile(filename string, data string) error

WriteToFile writes a string variable to a file. It overwrites any pre-existing data silently.

Types

type KeyValue

type KeyValue struct {
	Key      string
	Value    interface{}
	Override bool
	Prompt   string
	Answers  []string
	DataType string
}

KeyValue is a struct for holding toml keys, default values and whether the default overrides the monetcli supplied value

func GetMonetDefaultConfigKeys

func GetMonetDefaultConfigKeys(monetConfigDir string) []KeyValue

GetMonetDefaultConfigKeys defines the default config values

Jump to

Keyboard shortcuts

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