blockchain

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound  = errors.New("could not find specified account")
	ErrKeysNotFound     = errors.New("account either not found or not unlocked")
	ErrPasscodeNotFound = errors.New("could not find specified passcode")
)

Ethereum specific errors

Functions

func CalculateSelector

func CalculateSelector(functionSignature string) [4]byte

CalculateSelector calculates the hash of the supplied function signature

func CloneBigInt

func CloneBigInt(original *big.Int) *big.Int

CloneBigInt makes a deep copy of a big.Int

func CloneBigInt2

func CloneBigInt2(original [2]*big.Int) [2]*big.Int

CloneBigInt2 makes a deep copy of an array [2] of big.Int's

func CloneBigInt4

func CloneBigInt4(original [4]*big.Int) [4]*big.Int

CloneBigInt4 makes a deep copy of a array [4] of big.Int's

func CloneBigIntSlice

func CloneBigIntSlice(original []*big.Int) []*big.Int

CloneBigIntSlice makes a deep copy of a slice of big.Int's

func CloneSliceBigInt2

func CloneSliceBigInt2(original [][2]*big.Int) [][2]*big.Int

CloneSliceBigInt2 makes a deep copy of a slice of array [2] of big.Int's

func SleepWithContext

func SleepWithContext(ctx context.Context, delay time.Duration) error

SleepWithContext sleeps for a specified duration, unless the provided context completes earlier

func SlowReturn

func SlowReturn(ctx context.Context, delay time.Duration, value bool) bool

SlowReturn combines Sleep with returning specified bool value

func StringToBytes32

func StringToBytes32(str string) (b [32]byte)

StringToBytes32 is useful for convert a Go string into a bytes32 useful calling Solidity

Types

type Contracts

type Contracts struct {
	Crypto              *bindings.Crypto
	CryptoAddress       common.Address
	Deposit             *bindings.Deposit
	DepositAddress      common.Address
	Ethdkg              *bindings.ETHDKG
	EthdkgAddress       common.Address
	Participants        *bindings.Participants
	Registry            *bindings.Registry
	RegistryAddress     common.Address
	Snapshots           *bindings.Snapshots
	Staking             *bindings.Staking
	StakingToken        *bindings.Token
	StakingTokenAddress common.Address
	UtilityToken        *bindings.Token
	UtilityTokenAddress common.Address
	Validators          *bindings.Validators
	ValidatorsAddress   common.Address
	// contains filtered or unexported fields
}

Contracts contains bindings to smart contract system

func (*Contracts) DeployContracts

func (c *Contracts) DeployContracts(ctx context.Context, account accounts.Account) (*bindings.Registry, common.Address, error)

DeployContracts deploys and does basic setup for all contracts. It returns a binding to the registry, it's address or an error.

func (*Contracts) LookupContracts

func (c *Contracts) LookupContracts(registryAddress common.Address) error

LookupContracts uses the registry to lookup and create bindings for all required contracts

type Ethereum

type Ethereum interface {

	// Extensions for use with simulator
	Close() error
	Commit()

	IsEthereumAccessible() bool

	GetCallOpts(context.Context, accounts.Account) *bind.CallOpts
	GetTransactionOpts(context.Context, accounts.Account) (*bind.TransactOpts, error)

	LoadAccounts(string)
	LoadPasscodes(string) error

	UnlockAccount(accounts.Account) error

	TransferEther(common.Address, common.Address, *big.Int) error

	GetAccount(common.Address) (accounts.Account, error)
	GetAccountKeys(addr common.Address) (*keystore.Key, error)
	GetBalance(common.Address) (*big.Int, error)
	GetGethClient() GethClient
	GetCoinbaseAddress() common.Address
	GetCurrentHeight(context.Context) (uint64, error)
	GetDefaultAccount() accounts.Account
	GetEndpoint() string
	GetEvents(ctx context.Context, firstBlock uint64, lastBlock uint64, addresses []common.Address) ([]types.Log, error)
	GetFinalizedHeight(context.Context) (uint64, error)
	GetPeerCount(context.Context) (uint64, error)
	GetSnapshot() ([]byte, error)
	GetSyncProgress() (bool, *geth.SyncProgress, error)
	GetTimeoutContext() (context.Context, context.CancelFunc)
	GetValidators() ([]common.Address, error)

	WaitForReceipt(context.Context, *types.Transaction) (*types.Receipt, error)

	RetryCount() int
	RetryDelay() time.Duration

	Timeout() time.Duration

	Contracts() *Contracts
}

Ethereum contains state information about a connection to Ethereum

func NewEthereumEndpoint

func NewEthereumEndpoint(
	endpoint string,
	pathKeystore string,
	pathPasscodes string,
	defaultAccount string,
	timeout time.Duration,
	retryCount int,
	retryDelay time.Duration,
	finalityDelay int) (Ethereum, error)

NewEthereumEndpoint creates a new Ethereum abstraction

func NewEthereumSimulator

func NewEthereumSimulator(
	pathKeystore string,
	pathPasscodes string,
	retryCount int,
	retryDelay time.Duration,
	finalityDelay int,
	wei *big.Int,
	addresses ...string) (Ethereum, error)

NewEthereumSimulator returns a simulator for testing

type GethClient

type GethClient interface {

	// geth.ChainReader
	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
	BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
	HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
	TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
	TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
	SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (geth.Subscription, error)

	// geth.TransactionReader
	TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

	// geth.ChainStateReader
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
	CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)

	// bind.ContractBackend
	// -- bind.ContractCaller
	// CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
	CallContract(ctx context.Context, call geth.CallMsg, blockNumber *big.Int) ([]byte, error)

	// -- bind.ContractTransactor
	PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	EstimateGas(ctx context.Context, call geth.CallMsg) (gas uint64, err error)
	SendTransaction(ctx context.Context, tx *types.Transaction) error

	// -- bind.ContractFilterer
	FilterLogs(ctx context.Context, query geth.FilterQuery) ([]types.Log, error)
	SubscribeFilterLogs(ctx context.Context, query geth.FilterQuery, ch chan<- types.Log) (geth.Subscription, error)
}

GethClient is an amalgamation of the geth interfaces used

type Updater

type Updater struct {
	Logger  *logrus.Logger
	Updater *bindings.DiamondUpdateFacet
	TxnOpts *bind.TransactOpts
	// contains filtered or unexported fields
}

func (*Updater) Add

func (u *Updater) Add(signature string, facet common.Address) *types.Transaction

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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