chain

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: AGPL-3.0 Imports: 36 Imported by: 0

Documentation

Overview

Package chain provides the functions to interact with the Ethereum-like control blockchain

Index

Constants

This section is empty.

Variables

View Source
var (
	EthereumSynced = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: "ethereum",
		Name:      "synced",
		Help:      "Boolean, 1 if chain is synced",
	})
	EthereumHeight = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: "ethereum",
		Name:      "height",
		Help:      "Current height of the ethereum chain",
	})
	EthereumMaxHeight = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: "ethereum",
		Name:      "max_height",
		Help:      "Height of the ethereum chain (last block)",
	})
	EthereumPeers = prometheus.NewGauge(prometheus.GaugeOpts{
		Namespace: "ethereum",
		Name:      "peers",
		Help:      "Number of ethereum peers connected",
	})
)

Ethereum collectors

View Source
var AvailableChains = []string{"mainnet", "goerli", "xdai", "xdaistage", "sokol"}

Functions

func EnsResolve added in v0.6.0

func EnsResolve(ctx context.Context, ensRegistryAddr, ethDomain, w3uri string) (contractAddr string, err error)

EnsResolve resolves the voting process contract address through the stardard ENS

func NameHash added in v0.6.3

func NameHash(name string) (hash [32]byte, err error)

nameHash generates a hash from a name that can be used to look up the name in ENS

func NameHashPart added in v0.6.3

func NameHashPart(currentHash [32]byte, name string) (hash [32]byte, err error)

func Normalize added in v0.6.3

func Normalize(input string) (output string, err error)

normalize normalizes a name according to the ENS standard

func ResolveEntityMetadataURL added in v0.6.0

func ResolveEntityMetadataURL(ctx context.Context, ensRegistryAddr, entityID, ethEndpoint string) (string, error)

ResolveEntityMetadataURL returns the metadata URL given an entityID

func VotingProcessAddress added in v0.3.0

func VotingProcessAddress(ctx context.Context, publicRegistryAddr, domain, ethEndpoint string) (string, error)

VotingProcessAddress gets the Voting process main contract address

Types

type ENSCallerHandler added in v0.3.0

type ENSCallerHandler struct {
	// Registry public registry contract instance
	Registry *contracts.EnsRegistryWithFallbackCaller
	// Resolver resolver contract instance
	Resolver *contracts.EntityResolverCaller
	// EthereumClient is the client interacting with the ethereum node
	EthereumClient *ethclient.Client
	// PublicRegistryAddr public registry contract address
	PublicRegistryAddr string
	// ResolverAddr address resolved by calling Resolve() on Registry contract
	ResolverAddr string
}

ENSCallerHandler contains the contracts and their addresses and an eth client

func (*ENSCallerHandler) NewENSRegistryWithFallbackHandle added in v0.3.0

func (e *ENSCallerHandler) NewENSRegistryWithFallbackHandle() (err error)

NewENSRegistryWithFallbackHandle connects to a web3 endpoint and creates an ENS public registry read only contact instance

func (*ENSCallerHandler) NewEntityResolverHandle added in v0.3.0

func (e *ENSCallerHandler) NewEntityResolverHandle() (err error)

NewEntityResolverHandle connects to a web3 endpoint and creates an EntityResolver read only contact instance

func (*ENSCallerHandler) Resolve added in v0.3.0

func (e *ENSCallerHandler) Resolve(ctx context.Context, nameHash [32]byte, resolvePublicRegistry bool) (string, error)

Resolve if resolvePublicRegistry is set to true it will resolve the given namehash on the public registry. If false it will resolve the given namehash on a standard resolver

type EthChainConfig

type EthChainConfig struct {
	RPCHost        string
	RPCPort        int
	NodePort       int
	NetworkId      int
	NetworkGenesis []byte
	BootstrapNodes []string
	TrustedPeers   []*enode.Node
	KeyStore       string
	DataDir        string
	IPCPath        string
	LightMode      bool
	W3external     string
}

func NewConfig

func NewConfig(ethCfg *config.EthCfg, w3Cfg *config.W3Cfg) (*EthChainConfig, error)

NewConfig returns an Ethereum config using some default values

type EthChainContext

type EthChainContext struct {
	Node          *node.Node
	API           *eth.EthAPIBackend // Ethereum backend API (if fastmode enabled)
	LAPI          *les.LesApiBackend // Ethereum Light API (if lightmode enabled)
	Config        *eth.Config
	Keys          *keystore.KeyStore
	DefaultConfig *EthChainConfig
	ProcessHandle *ProcessHandle
	MetricsAgent  *metrics.Agent
	RestartLock   sync.RWMutex
}

func Init

func (*EthChainContext) CollectMetrics added in v0.3.0

func (e *EthChainContext) CollectMetrics(ctx context.Context, ma *metrics.Agent)

CollectMetrics constantly updates the metric values for prometheus The function is blocking, should be called in a go routine If the metrics Agent is nil, do nothing

func (*EthChainContext) PrintInfo

func (e *EthChainContext) PrintInfo(ctx context.Context, seconds time.Duration)

PrintInfo prints every N seconds some ethereum information (sync and height). It's blocking!

func (*EthChainContext) Start

func (e *EthChainContext) Start()

Start starts an Ethereum blockchain connection and web3 APIs

func (*EthChainContext) SyncGuard added in v0.4.0

func (e *EthChainContext) SyncGuard(ctx context.Context)

func (*EthChainContext) SyncInfo

func (e *EthChainContext) SyncInfo(ctx context.Context) (info EthSyncInfo, err error)

SyncInfo returns the height and syncing Ethereum blockchain information

type EthSyncInfo added in v0.3.0

type EthSyncInfo struct {
	Height    uint64
	MaxHeight uint64
	Synced    bool
	Peers     int
	Mode      string
}

type ProcessHandle

type ProcessHandle struct {
	VotingProcess  *contracts.VotingProcess
	EthereumClient *ethclient.Client
}

These methods represent an exportable abstraction over raw contract bindings` Use these methods, rather than those present in the contracts folder

func NewVotingProcessHandle

func NewVotingProcessHandle(contractAddressHex string, dialEndpoint string) (*ProcessHandle, error)

Constructor for proc_transactor on node

func (*ProcessHandle) CancelProcessTxArgs

func (ph *ProcessHandle) CancelProcessTxArgs(ctx context.Context, pid [32]byte) (*types.CancelProcessTx, error)

func (*ProcessHandle) Genesis

func (ph *ProcessHandle) Genesis(ctx context.Context) (string, error)

func (*ProcessHandle) Oracles

func (ph *ProcessHandle) Oracles(ctx context.Context) ([]string, error)

func (*ProcessHandle) ProcessIndex

func (ph *ProcessHandle) ProcessIndex(ctx context.Context, pid [32]byte) (*big.Int, error)

func (*ProcessHandle) ProcessTxArgs

func (ph *ProcessHandle) ProcessTxArgs(ctx context.Context, pid [32]byte) (*types.NewProcessTx, error)

func (*ProcessHandle) Validators

func (ph *ProcessHandle) Validators(ctx context.Context) ([]string, error)

type Specs

type Specs struct {
	Name            string   // Identity name
	GenesisB64      string   // Base64 JSON encoded genesis file
	GenesisHash     string   // Genesis Hash
	NetworkId       int      // Ethereum Like network identification number
	BootNodes       []string // List of Bootnodes for this network
	StartingBlock   int64    // Where to start looking for events
	ENSregistryAddr string
}

Specs defines a set of blockchain network specifications

func SpecsFor

func SpecsFor(name string) (*Specs, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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