helpers

package
v0.0.0-...-740805f Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigIntsToStrings

func BigIntsToStrings(bigInts []*big.Int) []string

bigIntsToStrings converts a slice of *big.Int to a slice of their string representations. It safely handles nil pointers within the input slice.

func CalculateTurnout

func CalculateTurnout(totalWeightStr, castedWeightStr string) float32

CalculateTurnout computes the turnout percentage from two big.Int strings. If the strings are not valid numbers, it returns zero.

func ExtractResults

func ExtractResults(election *api.Election, censusTokenDecimals uint32) (choices []string, results []*big.Int)

ExtractResults extracts the choices and results from an election. It returns nil if there is an issue processing the data.

func NormalizeAddressString

func NormalizeAddressString(address string) string

NormalizeAddressString converts an Ethereum address to its normalized form.

func NormalizeAddressStringSlice

func NormalizeAddressStringSlice(addresses []string) []string

NormalizeAddressStringSlice converts a slice of Ethereum addresses to their normalized form.

func TruncateDecimals

func TruncateDecimals(num *big.Int, numberOfDecimals uint32) *big.Int

TruncateDecimals takes a big.Int representing a fixed-point number and truncates it to a whole number by removing the specified number of decimal places.

func UnpackMetadata

func UnpackMetadata(metadata any) *api.ElectionDescription

UnpackMetadata is a helper function to unpack the metadata of an election to the api.ElectionDescription type.

Types

type ChainConfig

type ChainConfig struct {
	ChainID             uint64
	ChainAlias          string
	Name                string
	Endpoints           []string
	CommunityHubAddress string
}

ChainConfig represents the configuration of a chain, including the chain ID, the chain alias, the chain name, the endpoints, and the address of the CommunityHub contract.

type ChainsConfig

type ChainsConfig []*ChainConfig

ChainsConfig is a slice of ChainConfig.

func LoadChainsConfig

func LoadChainsConfig(path string, availableAliases []string) (ChainsConfig, error)

LoadChainsConfig loads the chains configuration from the file at the given path. It returns a ChainsConfig struct with the configuration loaded from the file. If something goes wrong loading the file or parsing the JSON, it returns an error.

func (ChainsConfig) ChainChainIDByAlias

func (c ChainsConfig) ChainChainIDByAlias() map[string]uint64

ChainAliasesByChainID returns a map with the chain ID as the key and the chain alias as the value.

func (ChainsConfig) ContractsAddressesByChainAlias

func (c ChainsConfig) ContractsAddressesByChainAlias() map[string]common.Address

ContractsAddressesByChainID returns a map with the chain ID as the key and the CommunityHub contract address as the value.

Jump to

Keyboard shortcuts

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