Documentation ¶
Index ¶
- func BigIntsToStrings(bigInts []*big.Int) []string
- func CalculateTurnout(totalWeightStr, castedWeightStr string) float32
- func ExtractResults(election *api.Election, censusTokenDecimals uint32) (choices []string, results []*big.Int)
- func NormalizeAddressString(address string) string
- func NormalizeAddressStringSlice(addresses []string) []string
- func TruncateDecimals(num *big.Int, numberOfDecimals uint32) *big.Int
- func UnpackMetadata(metadata any) *api.ElectionDescription
- type ChainConfig
- type ChainsConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BigIntsToStrings ¶
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 ¶
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 ¶
NormalizeAddressString converts an Ethereum address to its normalized form.
func NormalizeAddressStringSlice ¶
NormalizeAddressStringSlice converts a slice of Ethereum addresses to their normalized form.
func TruncateDecimals ¶
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.