common

package
v0.0.0-...-2729ef7 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArbitrumGoerliChainID  int64 = 421613
	ArbitrumOneChainID     int64 = 42161
	ArbitrumSepoliaChainID int64 = 421614
)
View Source
const (
	// BloomByteLength represents the number of bytes used in a header log bloom.
	BloomByteLength = 256

	// BloomBitLength represents the number of bits used in a header log bloom.
	BloomBitLength = 8 * BloomByteLength
)

Variables

This section is empty.

Functions

func BinarySearch

func BinarySearch(top, bottom *big.Int, test func(amount *big.Int) bool) *big.Int

binarySearch finds the highest value within the range bottom-top at which the test function is true.

func CalculateLatestBlockHeader

func CalculateLatestBlockHeader(env Environment, blockNumberInput int) (err error)

func ConfirmCodeAt

func ConfirmCodeAt(ctx context.Context, client *ethclient.Client, addr common.Address, chainID int64)

func ConfirmContractDeployed

func ConfirmContractDeployed(context context.Context, client *ethclient.Client, transaction *types.Transaction, chainID int64) (address common.Address)

ConfirmContractDeployed confirms that the given contract deployment transaction completed and prints useful execution information.

func ConfirmTXMined

func ConfirmTXMined(context context.Context, client *ethclient.Client, transaction *types.Transaction, chainID int64, txInfo ...string) (receipt *types.Receipt)

ConfirmTXMined confirms that the given transaction is mined and prints useful execution information.

func ContractExplorerLink(chainID int64, contractAddress common.Address) string

ContractExplorerLink creates a block explorer link for the given contract address. If the chain ID is unrecognized the address is returned as-is.

func DeployLinkEthFeed

func DeployLinkEthFeed(e Environment, linkAddress string, weiPerUnitLink *big.Int) common.Address

func DeployLinkToken

func DeployLinkToken(e Environment) common.Address
func ExplorerLink(chainID int64, txHash common.Hash) string

ExplorerLink creates a block explorer link for the given transaction hash. If the chain ID is unrecognized, the hash is returned as-is.

func FundNode

func FundNode(e Environment, address string, fundingAmount *big.Int)

func FundNodes

func FundNodes(e Environment, transmitters []string, fundingAmount *big.Int)

func GetIbftExtraClean

func GetIbftExtraClean(extra []byte) (cleanedExtra []byte, err error)

Remove blockHeader.ExtraData.Committed without unpacking ExtraData into its full fledged type, which needs the full import of the package github.com/0xPolygon/polygon-edge. polygon-edge is a node implementation, and not a client. Adding polygon-edge as a dependency caused a lot of issues with conflicting dependency version with other libraries in this repo and some methods being referenced from older versions.

func GetPolygonEdgeRLPHeader

func GetPolygonEdgeRLPHeader(jsonRPCClient *rpc.Client, blockNum *big.Int) (rlpHeader []byte, hash string, err error)

func GetRlpHeaders

func GetRlpHeaders(env Environment, blockNumbers []*big.Int, getParentBlocks bool) (headers [][]byte, hashes []string, err error)

GetRlpHeaders gets RLP encoded headers of a list of block numbers Makes RPC network call eth_getBlockByNumber to blockchain RPC node to fetch header info

func IsArbitrumChainID

func IsArbitrumChainID(chainID int64) bool

IsArbitrumChainID returns true if and only if the given chain ID corresponds to an Arbitrum chain (testnet or mainnet).

func IsAvaxNetwork

func IsAvaxNetwork(chainID int64) bool

IsAvaxNetwork returns true if the given chain ID corresponds to an avalanche network.

func IsAvaxSubnet

func IsAvaxSubnet(chainID int64) bool

IsAvaxSubnet returns true if the given chain ID corresponds to an avalanche subnet.

func IsPolygonEdgeNetwork

func IsPolygonEdgeNetwork(chainID int64) bool

IsPolygonEdgeNetwork returns true if the given chain ID corresponds to an Pologyon Edge network.

func MarshalRLPWith

func MarshalRLPWith(arena *fastrlp.Arena, h *PolygonEdgeHeader) (*fastrlp.Value, error)

MarshalRLPWith marshals the header to RLP with a specific fastrlp.Arena Adding polygon-edge as a dependency caused a lot of issues with conflicting dependency version with other libraries in this repo and some methods being referenced from older versions Reference: https://github.com/0xPolygon/polygon-edge/blob/develop/types/rlp_marshal.go#L73C50-L73C53

func PanicErr

func PanicErr(err error)

PanicErr panics if error the given error is non-nil.

func ParseAddressSlice

func ParseAddressSlice(arg string) (ret []common.Address)

ParseAddressSlice parses the given comma-separated string of addresses into a slice of common.Address objects.

func ParseArgs

func ParseArgs(flagSet *flag.FlagSet, args []string, requiredArgs ...string)

ParseArgs parses arguments and ensures required args are set.

func ParseBigIntSlice

func ParseBigIntSlice(arg string) (ret []*big.Int)

ParseBigIntSlice parses the given comma-separated string of integers into a slice of *big.Int objects.

func ParseHashSlice

func ParseHashSlice(arg string) (ret []common.Hash)

ParseHashSlice parses the given comma-separated string of hashes into a slice of common.Hash objects.

func ParseHexSlice

func ParseHexSlice(arg string) (ret [][]byte)

func ParseIntSlice

func ParseIntSlice(arg string) (ret []int)

ParseIntSlice parses the given comma-separated string of integers into a slice of int.

func TenderlySimLink(simID string) string
func UpkeepLink(chainID int64, upkeepID *big.Int) string

Types

type AvaBlockNonce

type AvaBlockNonce [8]byte

A AvaBlockNonce is a 64-bit hash which proves (combined with the mix-hash) that a sufficient amount of computation has been carried out on a block.

func EncodeNonce

func EncodeNonce(i uint64) AvaBlockNonce

EncodeNonce converts the given integer to a block nonce.

func (AvaBlockNonce) MarshalText

func (n AvaBlockNonce) MarshalText() ([]byte, error)

MarshalText encodes n as a hex string with 0x prefix.

func (AvaBlockNonce) Uint64

func (n AvaBlockNonce) Uint64() uint64

Uint64 returns the integer value of a block nonce.

func (*AvaBlockNonce) UnmarshalText

func (n *AvaBlockNonce) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type AvaBloom

type AvaBloom [BloomByteLength]byte

AvaBloom represents a 2048 bit bloom filter.

func (*AvaBloom) Add

func (b *AvaBloom) Add(d []byte)

Add adds d to the filter. Future calls of Test(d) will return true.

func (AvaBloom) Big

func (b AvaBloom) Big() *big.Int

Big converts b to a big integer. Note: Converting a bloom filter to a big.Int and then calling GetBytes does not return the same bytes, since big.Int will trim leading zeroes

func (AvaBloom) Bytes

func (b AvaBloom) Bytes() []byte

Bytes returns the backing byte slice of the bloom

func (AvaBloom) MarshalText

func (b AvaBloom) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string with 0x prefix.

func (*AvaBloom) SetBytes

func (b *AvaBloom) SetBytes(d []byte)

SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.

func (AvaBloom) Test

func (b AvaBloom) Test(topic []byte) bool

Test checks if the given topic is present in the bloom filter

func (*AvaBloom) UnmarshalText

func (b *AvaBloom) UnmarshalText(input []byte) error

UnmarshalText b as a hex string with 0x prefix.

type AvaHeader

type AvaHeader struct {
	ParentHash  common.Hash    `json:"parentHash"       gencodec:"required"`
	UncleHash   common.Hash    `json:"sha3Uncles"       gencodec:"required"`
	Coinbase    common.Address `json:"miner"            gencodec:"required"`
	Root        common.Hash    `json:"stateRoot"        gencodec:"required"`
	TxHash      common.Hash    `json:"transactionsRoot" gencodec:"required"`
	ReceiptHash common.Hash    `json:"receiptsRoot"     gencodec:"required"`
	Bloom       AvaBloom       `json:"logsBloom"        gencodec:"required"`
	Difficulty  *big.Int       `json:"difficulty"       gencodec:"required"`
	Number      *big.Int       `json:"number"           gencodec:"required"`
	GasLimit    uint64         `json:"gasLimit"         gencodec:"required"`
	GasUsed     uint64         `json:"gasUsed"          gencodec:"required"`
	Time        uint64         `json:"timestamp"        gencodec:"required"`
	Extra       []byte         `json:"extraData"        gencodec:"required"`
	MixDigest   common.Hash    `json:"mixHash"`
	Nonce       AvaBlockNonce  `json:"nonce"`
	ExtDataHash common.Hash    `json:"extDataHash"      gencodec:"required"`

	// BaseFee was added by EIP-1559 and is ignored in legacy headers.
	BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`

	// ExtDataGasUsed was added by Apricot Phase 4 and is ignored in legacy
	// headers.
	//
	// It is not a uint64 like GasLimit or GasUsed because it is not possible to
	// correctly encode this field optionally with uint64.
	ExtDataGasUsed *big.Int `json:"extDataGasUsed" rlp:"optional"`

	// BlockGasCost was added by Apricot Phase 4 and is ignored in legacy
	// headers.
	BlockGasCost *big.Int `json:"blockGasCost" rlp:"optional"`
}

AvaHeader is a copy of github.com/ava-labs/coreth/core/types.Header to avoid importing the whole module.

func (*AvaHeader) Hash

func (h *AvaHeader) Hash() common.Hash

func (*AvaHeader) UnmarshalJSON

func (h *AvaHeader) UnmarshalJSON(input []byte) error

type AvaSubnetHeader

type AvaSubnetHeader struct {
	ParentHash   common.Hash    `json:"parentHash"       gencodec:"required"`
	UncleHash    common.Hash    `json:"sha3Uncles"       gencodec:"required"`
	Coinbase     common.Address `json:"miner"            gencodec:"required"`
	Root         common.Hash    `json:"stateRoot"        gencodec:"required"`
	TxHash       common.Hash    `json:"transactionsRoot" gencodec:"required"`
	ReceiptHash  common.Hash    `json:"receiptsRoot"     gencodec:"required"`
	Bloom        AvaBloom       `json:"logsBloom"        gencodec:"required"`
	Difficulty   *big.Int       `json:"difficulty"       gencodec:"required"`
	Number       *big.Int       `json:"number"           gencodec:"required"`
	GasLimit     uint64         `json:"gasLimit"         gencodec:"required"`
	GasUsed      uint64         `json:"gasUsed"          gencodec:"required"`
	Time         uint64         `json:"timestamp"        gencodec:"required"`
	Extra        []byte         `json:"extraData"        gencodec:"required"`
	MixDigest    common.Hash    `json:"mixHash"`
	Nonce        AvaBlockNonce  `json:"nonce"`
	BaseFee      *big.Int       `json:"baseFeePerGas" rlp:"optional"`
	BlockGasCost *big.Int       `json:"blockGasCost" rlp:"optional"`
}

AvaSubnetHeader is a copy of github.com/ava-labs/subnet-evm/core/types.Header to avoid importing the whole module.

func (*AvaSubnetHeader) Hash

func (h *AvaSubnetHeader) Hash() common.Hash

func (*AvaSubnetHeader) UnmarshalJSON

func (h *AvaSubnetHeader) UnmarshalJSON(input []byte) error

type Environment

type Environment struct {
	Owner *bind.TransactOpts
	Ec    *ethclient.Client

	Jc *rpc.Client

	ChainID int64
}

func SetupEnv

func SetupEnv(overrideNonce bool) Environment

SetupEnv returns an Environment object populated from environment variables. If overrideNonce is set to true, the nonce will be set to what is returned by NonceAt (rather than the typical PendingNonceAt).

type ExtraData

type ExtraData string

func (ExtraData) Decode

func (e ExtraData) Decode() ([]byte, error)

type Nonce

type Nonce [8]byte

func (Nonce) MarshalText

func (n Nonce) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Nonce) String

func (n Nonce) String() string

func (*Nonce) UnmarshalJSON

func (n *Nonce) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a nonce in hex syntax.

type PolygonEdgeHeader

type PolygonEdgeHeader struct {
	ParentHash   common.Hash    `json:"parentHash"       gencodec:"required"`
	Sha3Uncles   common.Hash    `json:"sha3Uncles"       gencodec:"required"`
	Miner        common.Address `json:"miner"`
	StateRoot    common.Hash    `json:"stateRoot"        gencodec:"required"`
	TxRoot       common.Hash    `json:"transactionsRoot" gencodec:"required"`
	ReceiptsRoot common.Hash    `json:"receiptsRoot"     gencodec:"required"`
	LogsBloom    types.Bloom    `json:"logsBloom"        gencodec:"required"`
	Difficulty   hexutil.Uint64 `json:"difficulty"       gencodec:"required"`
	Number       hexutil.Uint64 `json:"number"           gencodec:"required"`
	GasLimit     hexutil.Uint64 `json:"gasLimit"         gencodec:"required"`
	GasUsed      hexutil.Uint64 `json:"gasUsed"          gencodec:"required"`
	Timestamp    hexutil.Uint64 `json:"timestamp"        gencodec:"required"`
	ExtraData    ExtraData      `json:"extraData"        gencodec:"required"`
	MixHash      common.Hash    `json:"mixHash"`
	Nonce        Nonce          `json:"nonce"`
	Hash         common.Hash    `json:"hash"`

	// baseFeePerGas is the response format from go-ethereum. Polygon-Edge
	// seems to have fixed this in this commit:
	// https://github.com/0xPolygon/polygon-edge/commit/e859acf7e7f0286ceeecce022b978c8fdb57d71b
	// But node operators dont seem to have updated their polygon-edge client
	// version and still send baseFee instead of baseFeePerGas.
	// BaseFee was added by EIP-1559 and is ignored in legacy headers.
	BaseFee    hexutil.Uint64 `json:"baseFeePerGas"`
	BaseFeeAlt hexutil.Uint64 `json:"baseFee,omitempty"`
}

Header represents a block header in the Ethereum blockchain.

Directories

Path Synopsis
vrf

Jump to

Keyboard shortcuts

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