utils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Copyright 2022 Nethermind

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssingPorts

func AssingPorts(host string, defaults map[string]string) (ports map[string]string, err error)

AssingPorts : Checks if port is occupied in a given host

params :- a. host string Host which port is to be checked b. port string Port to be checked

returns :- a. bool True if <port> is available. False otherwise

func CheckContainers

func CheckContainers(generationPath string) (string, error)

CheckContainers : Check if containers of generated docker-compose script are running

params :- a. generationPath string Path to the generated docker-compose script

returns :- a. string Output of 'docker ps --services --filter status=running' b. error Error if any

func CheckDependencies

func CheckDependencies(dependencies []string) (pending []string)

CheckDependencies : This function is responsible for checking if on-premise setup dependencies are installed on host machine

params :- a. dependencies []string List of dependencies to be checked

returns :- a. []string List of dependencies that are not installed

func CheckErr

func CheckErr(descr string, isErr bool, err error) error

CheckErr : Helper function for tests. Check if a given error was expected.

params :- a. desc string Description of the error in case of failure b. isError bool Whether the error was expected or not c. err error Error to check

returns :- a. error Error if any

func Contains

func Contains(list []string, str string) bool

Contains : Checks if a string slice contains a string

params :- a. list []string String slice to be checked b. str string String to be checked

returns :- a. bool True if str is in list, false otherwise

func ContainsOnly

func ContainsOnly(list []string, target []string) bool

ContainsOnly : Checks if a string slice contains only strings of a given string slice

params :- a. list []string String slice to be checked b. target []string String slice to be checked

returns :- a. bool True if every string in list is in target, false otherwise

func Filter added in v0.3.0

func Filter[K any](list []K, filter func(K) bool) []K

Filter : Filter a slice given a predicate

params :- a. list []K List to be filtered b. filter func(K) bool Predicate to be applied to each element of the list

returns :- a. []K Filtered list

func GenerateValidatorKey

func GenerateValidatorKey(arg ValidatorKeyData) (err error)

GenerateValidatorKey : Generates a validator key using the eth2.0-deposit-cli tool. The key can be generated using a new or existing mnemonic. Key's path is set to $(pwd)/keystore.

params :- a. arg ValidatorKeyData Data for keystore generation

returns :- a. error Error if any

func GetDistroName

func GetDistroName() (_ string, err error)

GetDistroName : Get the name and version of the linux distribution of the host machine.

params :- None

returns :- a. string "<Distribution_Name> <Distribution_Version>" a. error Error if any

func HandleInstructions

func HandleInstructions(dependencies []string, handler func(string) error) (err error)

HandleInstructions : This function is responsible for handling the dependencies needed for sedge setup If install support for a dependency exists, then `handler` will process it, for example, installing it or showing instructions for it.

params :- a. []string dependencies List of dependencies needed for sedge setup b. func(string) error handler Handler for each dependency

returns :- a. error Error if any

func InstallDependency

func InstallDependency(dependency string) (err error)

InstallDependency : This function is responsible for installing the dependencies using pre-written bash scripts

params :- a. string dependency Dependency to be installed

returns :- a. error Error if any

func IsAddress

func IsAddress(a string) bool

IsAddress : Checks if a string is an Ethereum address

params :- a. a string String to be checked

returns :- a. bool True if <a> is a valid Ethereum address. False otherwise

func PreCheck

func PreCheck(generationPath string) error

PreCheck : Check if docker-compose can be used to interact with the generated docker-compose script

params :- a. generationPath string Path to the generated docker-compose script

returns :- a. error Error if any

func ShowInstructions

func ShowInstructions(dependency string) error

ShowInstructions : This function is responsible for showing instructions for installing each dependency

params :- a. string dependency Dependency whose instruction will be showed

returns :- a. error Error if any

func SkipLines

func SkipLines(content string, symbol string) string

SkipLines : Skips lines starting with `symbol`

params :- a. content string String to be processed b. symbol string Symbol to be skipped

returns :- a. string Processed string

func SupportedNetworks

func SupportedNetworks() (networkNames []string, err error)

SupportedNetworks : Get supported networks names. A network is supported if it has a folder with the network name in either templates/envs or templates/services forder.

params :- none

returns :- a. []string List of supported network names b. error Error if any

func ZipString

func ZipString(lists ...[]string) ([][]string, error)

ZipString : Zip string slices

params :- a. lists ...[]string String slices to be zipped

returns :- a. [][]string Zipped string slices b. error Error if any

Types

type DepositCLI

type DepositCLI struct {
	// Network : Network name, e.g. "mainnet", "goerli"
	Network string
	// Path : Path to the keystore folder
	Path string
	// Password : Keystore password
	Password string
	// LenPass : Slice used to hide password in template
	LenPass []struct{}
	// Image : staking-deposit-cli docker image
	Image string
	// Eth1WithdrawalAddress : Address to be used to create withdrawal credentials
	Eth1WithdrawalAddress string
}

DepositCLI : Struct Data for eth2.0-deposit-cli command template

type DistroInfo

type DistroInfo struct {
	Name         string
	Architecture string
	Version      string
}

DistroInfo : Struct Contains name, architecture and version of the linux distribution of the host machine

type ValidatorKeyData

type ValidatorKeyData struct {
	// Existing: True if a existing mnemonic is being used. False to create and use a new one.
	Existing bool
	// Network : Target network
	Network string
	// Path : Path to the keystore folder
	Path string
	// Password : Keystore password
	Password string
	// Eth1WithdrawalAddress : Address to be used to create withdrawal credentials
	Eth1WithdrawalAddress string
}

ValidatorKeyData : Struct Data for Keystore generation

Jump to

Keyboard shortcuts

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