helper

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: GPL-3.0 Imports: 66 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TendermintNodeFlag     = "node"
	WithHeimdallConfigFlag = "heimdall-config"
	HomeFlag               = "home"
	FlagClientHome         = "home-client"
	OverwriteGenesisFlag   = "overwrite-genesis"
	RestServerFlag         = "rest-server"
	BridgeFlag             = "bridge"
	LogLevel               = "log_level"
	LogsWriterFileFlag     = "logs_writer_file"
	SeedsFlag              = "seeds"

	MainChain   = "mainnet"
	MumbaiChain = "mumbai"
	AmoyChain   = "amoy"
	LocalChain  = "local"

	// heimdall-config flags
	MainRPCUrlFlag               = "eth_rpc_url"
	BorRPCUrlFlag                = "bor_rpc_url"
	TendermintNodeURLFlag        = "tendermint_rpc_url"
	HeimdallServerURLFlag        = "heimdall_rest_server"
	AmqpURLFlag                  = "amqp_url"
	CheckpointerPollIntervalFlag = "checkpoint_poll_interval"
	SyncerPollIntervalFlag       = "syncer_poll_interval"
	NoACKPollIntervalFlag        = "noack_poll_interval"
	ClerkPollIntervalFlag        = "clerk_poll_interval"
	SpanPollIntervalFlag         = "span_poll_interval"
	MilestonePollIntervalFlag    = "milestone_poll_interval"
	MainchainGasLimitFlag        = "main_chain_gas_limit"
	MainchainMaxGasPriceFlag     = "main_chain_max_gas_price"

	NoACKWaitTimeFlag = "no_ack_wait_time"
	ChainFlag         = "chain"

	// ---
	// TODO Move these to common client flags
	// BroadcastBlock defines a tx broadcasting mode where the client waits for
	// the tx to be committed in a block.
	BroadcastBlock = "block"

	// BroadcastSync defines a tx broadcasting mode where the client waits for
	// a CheckTx execution response only.
	BroadcastSync = "sync"

	// BroadcastAsync defines a tx broadcasting mode where the client returns
	// immediately.
	BroadcastAsync = "async"

	// RPC Endpoints
	DefaultMainRPCUrl = "http://localhost:9545"
	DefaultBorRPCUrl  = "http://localhost:8545"

	// RPC Timeouts
	DefaultEthRPCTimeout = 5 * time.Second
	DefaultBorRPCTimeout = 5 * time.Second

	// DefaultAmqpURL represents default AMQP url
	DefaultAmqpURL           = "amqp://guest:guest@localhost:5672/"
	DefaultHeimdallServerURL = "http://0.0.0.0:1317"
	DefaultTendermintNodeURL = "http://0.0.0.0:26657"

	NoACKWaitTime = 1800 * time.Second // Time ack service waits to clear buffer and elect new proposer (1800 seconds ~ 30 mins)

	DefaultCheckpointerPollInterval = 5 * time.Minute
	DefaultSyncerPollInterval       = 1 * time.Minute
	DefaultNoACKPollInterval        = 1010 * time.Second
	DefaultClerkPollInterval        = 10 * time.Second
	DefaultSpanPollInterval         = 1 * time.Minute

	DefaultMilestonePollInterval = 30 * time.Second

	DefaultEnableSH              = false
	DefaultSHStateSyncedInterval = 15 * time.Minute
	DefaultSHStakeUpdateInterval = 3 * time.Hour

	DefaultSHMaxDepthDuration = time.Hour

	DefaultMainchainGasLimit = uint64(5000000)

	DefaultMainchainMaxGasPrice = 400000000000 // 400 Gwei

	DefaultBorChainID = "15001"

	DefaultLogsType = "json"
	DefaultChain    = MainChain

	DefaultTendermintNode = "tcp://localhost:26657"

	DefaultMainnetSeeds = "" /* 239-byte string literal not displayed */

	DefaultMumbaiTestnetSeeds = "" /* 180-byte string literal not displayed */

	DefaultAmoyTestnetSeeds = "eb57fffe96d74312963ced94a94cbaf8e0d8ec2e@54.217.171.196:26656,080dcdffcc453367684b61d8f3ce032f357b0f73@13.251.184.185:26656"

	// Legacy value - DO NOT CHANGE
	// Maximum allowed event record data size
	LegacyMaxStateSyncSize = 100000

	// New max state sync size after hardfork
	MaxStateSyncSize = 30000

	//Milestone Length
	MilestoneLength = uint64(12)

	MilestonePruneNumber = uint64(100)

	MaticChainMilestoneConfirmation = uint64(16)

	//Milestone buffer Length
	MilestoneBufferLength = MilestoneLength * 5
	MilestoneBufferTime   = 256 * time.Second
	// Default Open Collector Endpoint
	DefaultOpenCollectorEndpoint = "localhost:4317"
)
View Source
const (
	// CommitTimeout commit timeout
	CommitTimeout = 2 * time.Minute
)
View Source
const (
	UnstakeInitEvent = "UnstakeInit"
)

smart contracts' events names

Variables

View Source
var (
	DefaultCLIHome  = os.ExpandEnv("$HOME/.heimdallcli")
	DefaultNodeHome = os.ExpandEnv("$HOME/.heimdalld")
	MinBalance      = big.NewInt(100000000000000000) // aka 0.1 Ether
)
View Source
var ContractsABIsMap = make(map[string]*abi.ABI)

ContractsABIsMap is a cached map holding the ABIs of the contracts

View Source
var GenesisDoc tmTypes.GenesisDoc

GenesisDoc contains the genesis file

Logger stores global logger object

View Source
var ZeroAddress = common.Address{}

ZeroAddress represents empty address

View Source
var ZeroHash = common.Hash{}

ZeroHash represents empty hash

View Source
var ZeroPubKey = hmTypes.PubKey{}

ZeroPubKey represents empty pub key

Functions

func AppendBytes

func AppendBytes(data ...[]byte) []byte

AppendBytes appends bytes

func BroadcastMsgs

func BroadcastMsgs(cliCtx context.CLIContext, msgs []sdk.Msg) (sdk.TxResponse, error)

BroadcastMsgs creates transaction and broadcasts it

func BroadcastMsgsWithCLI

func BroadcastMsgsWithCLI(cliCtx context.CLIContext, msgs []sdk.Msg) error

BroadcastMsgsWithCLI creates message and sends tx Used from cli- waits till transaction is included in block

func BroadcastTx

func BroadcastTx(cliCtx context.CLIContext, tx authTypes.StdTx, mode string) (res sdk.TxResponse, err error)

BroadcastTx broadcasts transaction

func BroadcastTxBytes

func BroadcastTxBytes(cliCtx context.CLIContext, txBytes []byte, mode string) (sdk.TxResponse, error)

BroadcastTxBytes sends request to tendermint using CLI

func BuildAndBroadcastMsgs

func BuildAndBroadcastMsgs(cliCtx context.CLIContext, txBldr authTypes.TxBuilder, msgs []sdk.Msg) (sdk.TxResponse, error)

BuildAndBroadcastMsgs creates transaction and broadcasts it

func BuildAndBroadcastMsgsWithCLI

func BuildAndBroadcastMsgsWithCLI(cliCtx context.CLIContext, txBldr authTypes.TxBuilder, msgs []sdk.Msg) error

BuildAndBroadcastMsgsWithCLI implements a utility function that facilitates sending a series of messages in a signed transaction given a TxBuilder and a QueryContext. It ensures that the account exists, has a proper number and sequence set. In addition, it builds and signs a transaction with the supplied messages. Finally, it broadcasts the signed transaction to a node.

func DecorateWithHeimdallFlags added in v0.3.2

func DecorateWithHeimdallFlags(cmd *cobra.Command, v *viper.Viper, loggerInstance logger.Logger, caller string)

DecorateWithHeimdallFlags adds persistent flags for heimdall-config and bind flags with command

func DecorateWithTendermintFlags added in v0.3.2

func DecorateWithTendermintFlags(cmd *cobra.Command, v *viper.Viper, loggerInstance logger.Logger, message string)

DecorateWithTendermintFlags creates tendermint flags for desired command and bind them to viper

func EventByID

func EventByID(abiObject *abi.ABI, sigdata []byte) *abi.Event

EventByID looks up a event by the topic id

func ExponentialBackoff added in v0.3.2

func ExponentialBackoff(action func() error, max uint, wait time.Duration) error

ExponentialBackoff performs exponential backoff attempts on a given action

func FetchFromAPI added in v0.1.5

func FetchFromAPI(cliCtx cliContext.CLIContext, URL string) (result rest.ResponseWithHeight, err error)

FetchFromAPI fetches data from any URL

func FetchSideTxSigs added in v0.1.7

func FetchSideTxSigs(
	client *httpClient.HTTP,
	height int64,
	txHash []byte,
	sideTxData []byte,
) ([][3]*big.Int, error)

FetchSideTxSigs fetches side tx sigs from it

func FetchVotes added in v0.1.5

func FetchVotes(
	client *httpClient.HTTP,
	height int64,
) (votes []*tmTypes.CommitSig, sigs []byte, chainID string, err error)

FetchVotes fetches votes and extracts sigs from it

func FilterAttributes

func FilterAttributes(attributes []sdk.Attribute, fn func(sdk.Attribute) bool) *sdk.Attribute

FilterAttributes filter attributes by fn

func FilterEvents

func FilterEvents(events []sdk.StringEvent, fn func(sdk.StringEvent) bool) *sdk.StringEvent

FilterEvents filter events by fn

func GenerateAuthObj

func GenerateAuthObj(client *ethclient.Client, address common.Address, data []byte) (auth *bind.TransactOpts, err error)

func GetAalborgHardForkHeight added in v1.0.1

func GetAalborgHardForkHeight() int64

GetAalborgHardForkHeight returns AalborgHardForkHeight

func GetAddress

func GetAddress() []byte

GetAddress returns address object

func GetAmountFromPower added in v0.1.7

func GetAmountFromPower(power int64) (*big.Int, error)

GetAmountFromPower returns amount from power

func GetBeginBlockEvents added in v0.1.7

func GetBeginBlockEvents(client *httpClient.HTTP, height int64) ([]abci.Event, error)

GetBeginBlockEvents get block through per height

func GetBlock

func GetBlock(cliCtx cosmosContext.CLIContext, height int64) (*ctypes.ResultBlock, error)

GetBlock returns a block

func GetBlockWithClient

func GetBlockWithClient(client *httpClient.HTTP, height int64) (*tmTypes.Block, error)

GetBlockWithClient get block through per height

func GetECDSAPrivKey

func GetECDSAPrivKey() *ecdsa.PrivateKey

GetECDSAPrivKey return ecdsa private key

func GetFromAddress

func GetFromAddress(cliCtx context.CLIContext) types.HeimdallAddress

GetFromAddress get from address

func GetGenesisDoc

func GetGenesisDoc() tmTypes.GenesisDoc

func GetHeimdallServerEndpoint added in v0.1.5

func GetHeimdallServerEndpoint(endpoint string) string

GetHeimdallServerEndpoint returns heimdall server endpoint

func GetLogsWriter added in v0.3.3

func GetLogsWriter(logsWriterFile string) io.Writer

func GetMainChainRPCClient

func GetMainChainRPCClient() *rpc.Client

GetMainChainRPCClient returns main chain RPC client

func GetMainClient

func GetMainClient() *ethclient.Client

GetMainClient returns main chain's eth client

func GetMaticClient

func GetMaticClient() *ethclient.Client

GetMaticClient returns matic's eth client

func GetMaticRPCClient

func GetMaticRPCClient() *rpc.Client

GetMaticRPCClient returns matic's RPC client

func GetMerkleProofList

func GetMerkleProofList(proof *merkle.SimpleProof) [][]byte

GetMerkleProofList return proof array each proof has one byte for direction: 0x0 for left and 0x1 for right

func GetMilestoneBorBlockHeight added in v1.0.1

func GetMilestoneBorBlockHeight() uint64

GetMilestoneBorBlockHeight returns milestoneBorBlockHeight

func GetNewHexToStringAlgoHeight added in v0.3.5

func GetNewHexToStringAlgoHeight() int64

GetNewHexToStringAlgoHeight returns newHexToStringAlgoHeight

func GetNewSelectionAlgoHeight added in v0.3.2

func GetNewSelectionAlgoHeight() int64

GetNewSelectionAlgoHeight returns newSelectionAlgoHeight

func GetNodeStatus

func GetNodeStatus(cliCtx cosmosContext.CLIContext) (*ctypes.ResultStatus, error)

GetNodeStatus returns node status

func GetPowerFromAmount

func GetPowerFromAmount(amount *big.Int) (*big.Int, error)

GetPowerFromAmount returns power from amount -- note that this will populate amount object

func GetPrivKey

func GetPrivKey() secp256k1.PrivKeySecp256k1

GetPrivKey returns priv key object

func GetPubKey

func GetPubKey() secp256k1.PubKeySecp256k1

GetPubKey returns pub key object

func GetPubObjects

func GetPubObjects(pubkey crypto.PubKey) secp256k1.PubKeySecp256k1

GetPubObjects returns PubKeySecp256k1 public key

func GetSideTxSigs added in v0.1.7

func GetSideTxSigs(txHash []byte, sideTxData []byte, unFilteredVotes []*tmTypes.CommitSig) (sigs [][3]*big.Int, err error)

GetSideTxSigs returns sigs bytes from vote by tx hash

func GetSignedTxBytes

func GetSignedTxBytes(cliCtx context.CLIContext, txBldr authTypes.TxBuilder, msgs []sdk.Msg) ([]byte, error)

GetSignedTxBytes returns signed tx bytes

func GetSignedTxBytesWithCLI

func GetSignedTxBytesWithCLI(cliCtx context.CLIContext, txBldr authTypes.TxBuilder, msgs []sdk.Msg) ([]byte, error)

GetSignedTxBytesWithCLI returns signed tx bytes

func GetSpanOverrideHeight added in v0.3.2

func GetSpanOverrideHeight() int64

GetSpanOverrideHeight returns spanOverrideHeight

func GetStdTxBytes

func GetStdTxBytes(cliCtx context.CLIContext, tx authTypes.StdTx) ([]byte, error)

GetStdTxBytes get tx bytes

func GetTxDecoder

func GetTxDecoder(cdc *codec.Codec) sdk.TxDecoder

GetTxDecoder returns tx decoder

func GetTxEncoder

func GetTxEncoder(cdc *codec.Codec) sdk.TxEncoder

GetTxEncoder returns tx encoder

func GetUpdatedValidators

func GetUpdatedValidators(
	currentSet *hmTypes.ValidatorSet,
	validators []*hmTypes.Validator,
	ackCount uint64,
) []*hmTypes.Validator

GetUpdatedValidators updates validators in validator set

func GetValidChains added in v0.3.2

func GetValidChains() []string

GetValidChains returns all the valid chains

func GetVoteBytes

func GetVoteBytes(unFilteredVotes []*tmTypes.CommitSig, chainID string) []byte

GetVoteBytes returns vote bytes

func GetVoteSigs added in v0.1.7

func GetVoteSigs(unFilteredVotes []*tmTypes.CommitSig) (sigs []byte)

GetVoteSigs returns sigs bytes from vote

func InitHeimdallConfig

func InitHeimdallConfig(homeDir string)

InitHeimdallConfig initializes with viper config (from heimdall configuration)

func InitHeimdallConfigWith

func InitHeimdallConfigWith(homeDir string, heimdallConfigFileFromFLag string)

InitHeimdallConfigWith initializes passed heimdall/tendermint config files

func Paginate

func Paginate(numObjs, page, limit, defLimit int) (start, end int)

Paginate returns the correct starting and ending index for a paginated query, given that client provides a desired page and limit of objects and the handler provides the total number of objects. If the start page is invalid, non-positive values are returned signaling the request is invalid.

NOTE: The start page is assumed to be 1-indexed.

func PrepareTxBuilder

func PrepareTxBuilder(cliCtx context.CLIContext, txBldr authTypes.TxBuilder) (authTypes.TxBuilder, error)

PrepareTxBuilder populates a TxBuilder in preparation for the build of a Tx.

func PrintUnsignedStdTx

func PrintUnsignedStdTx(cliCtx context.CLIContext, txBldr authTypes.TxBuilder, msgs []sdk.Msg) error

PrintUnsignedStdTx builds an unsigned StdTx and prints it to os.Stdout.

func QueryTx

func QueryTx(cliCtx cosmosContext.CLIContext, hashHexStr string) (sdk.TxResponse, error)

QueryTx query tx from node

func QueryTxWithProof

func QueryTxWithProof(cliCtx cosmosContext.CLIContext, hash []byte) (*ctypes.ResultTx, error)

QueryTxWithProof query tx with proof from node

func QueryTxsByEvents

func QueryTxsByEvents(cliCtx cosmosContext.CLIContext, tags []string, page, limit int) (*sdk.SearchTxsResult, error)

QueryTxsByEvents performs a search for transactions for a given set of tags via Tendermint RPC. It returns a slice of Info object containing txs and metadata. An error is returned if the query fails.

func ReadStdTxFromFile

func ReadStdTxFromFile(cdc *amino.Codec, filename string) (stdTx authTypes.StdTx, err error)

ReadStdTxFromFile and decode a StdTx from the given filename. Can pass "-" to read from stdin.

func SetTestConfig added in v0.1.8

func SetTestConfig(_conf Configuration)

TEST PURPOSE ONLY SetTestConfig sets test configuration

func SignStdTx

func SignStdTx(cliCtx context.CLIContext, stdTx authTypes.StdTx, appendSig bool, offline bool) (authTypes.StdTx, error)

SignStdTx appends a signature to a StdTx and returns a copy of it. If appendSig is false, it replaces the signatures already attached with the new signature. Don't perform online validation or lookups if offline is true.

func TendermintTxDecode

func TendermintTxDecode(txString string) ([]byte, error)

TendermintTxDecode decodes transaction string and return base tx object

func ToBytes32

func ToBytes32(x []byte) [32]byte

ToBytes32 is a convenience method for converting a byte slice to a fix sized 32 byte array. This method will truncate the input if it is larger than 32 bytes.

func UnpackLog

func UnpackLog(abiObject *abi.ABI, out interface{}, event string, log *types.Log) error

UnpackLog unpacks log

func UnpackSigAndVotes

func UnpackSigAndVotes(payload []byte, abi abi.ABI) (votes []byte, sigs []byte, checkpointData []byte, err error)

UnpackSigAndVotes Unpacks Sig and Votes from Tx Payload

func UpdateTendermintConfig added in v0.3.2

func UpdateTendermintConfig(tendermintConfig *cfg.Config, v *viper.Viper)

UpdateTendermintConfig updates tenedermint config with flags and default values if needed

func ValidateTxResult

func ValidateTxResult(cliCtx cosmosContext.CLIContext, resTx *ctypes.ResultTx) error

ValidateTxResult performs transaction verification.

func WriteConfigFile

func WriteConfigFile(configFilePath string, config *Configuration)

WriteConfigFile renders config using the template and writes it to configFilePath.

func WriteGenesisFile added in v0.3.2

func WriteGenesisFile(chain string, filePath string, cdc *codec.Codec) (bool, error)

Types

type ChainManagerAddressMigration added in v0.3.4

type ChainManagerAddressMigration struct {
	MaticTokenAddress     hmTypes.HeimdallAddress
	RootChainAddress      hmTypes.HeimdallAddress
	StakingManagerAddress hmTypes.HeimdallAddress
	SlashManagerAddress   hmTypes.HeimdallAddress
	StakingInfoAddress    hmTypes.HeimdallAddress
	StateSenderAddress    hmTypes.HeimdallAddress
}

func GetChainManagerAddressMigration added in v0.3.4

func GetChainManagerAddressMigration(blockNum int64) (ChainManagerAddressMigration, bool)

type Configuration

type Configuration struct {
	EthRPCUrl        string `mapstructure:"eth_rpc_url"`        // RPC endpoint for main chain
	BorRPCUrl        string `mapstructure:"bor_rpc_url"`        // RPC endpoint for bor chain
	TendermintRPCUrl string `mapstructure:"tendermint_rpc_url"` // tendemint node url
	SubGraphUrl      string `mapstructure:"sub_graph_url"`      // sub graph url

	EthRPCTimeout time.Duration `mapstructure:"eth_rpc_timeout"` // timeout for eth rpc
	BorRPCTimeout time.Duration `mapstructure:"bor_rpc_timeout"` // timeout for bor rpc

	AmqpURL           string `mapstructure:"amqp_url"`             // amqp url
	HeimdallServerURL string `mapstructure:"heimdall_rest_server"` // heimdall server url

	MainchainGasLimit uint64 `mapstructure:"main_chain_gas_limit"` // gas limit to mainchain transaction. eg....submit checkpoint.

	MainchainMaxGasPrice int64 `mapstructure:"main_chain_max_gas_price"` // max gas price to mainchain transaction. eg....submit checkpoint.

	// config related to bridge
	CheckpointerPollInterval time.Duration `mapstructure:"checkpoint_poll_interval"` // Poll interval for checkpointer service to send new checkpoints or missing ACK
	SyncerPollInterval       time.Duration `mapstructure:"syncer_poll_interval"`     // Poll interval for syncher service to sync for changes on main chain
	NoACKPollInterval        time.Duration `mapstructure:"noack_poll_interval"`      // Poll interval for ack service to send no-ack in case of no checkpoints
	ClerkPollInterval        time.Duration `mapstructure:"clerk_poll_interval"`
	SpanPollInterval         time.Duration `mapstructure:"span_poll_interval"`
	MilestonePollInterval    time.Duration `mapstructure:"milestone_poll_interval"`
	EnableSH                 bool          `mapstructure:"enable_self_heal"`         // Enable self healing
	SHStateSyncedInterval    time.Duration `mapstructure:"sh_state_synced_interval"` // Interval to self-heal StateSynced events if missing
	SHStakeUpdateInterval    time.Duration `mapstructure:"sh_stake_update_interval"` // Interval to self-heal StakeUpdate events if missing
	SHMaxDepthDuration       time.Duration `mapstructure:"sh_max_depth_duration"`    // Max duration that allows to suggest self-healing is not needed

	// wait time related options
	NoACKWaitTime time.Duration `mapstructure:"no_ack_wait_time"` // Time ack service waits to clear buffer and elect new proposer

	// Log related options
	LogsType       string `mapstructure:"logs_type"`        // if true, enable logging in json format
	LogsWriterFile string `mapstructure:"logs_writer_file"` // if given, Logs will be written to this file else os.Stdout

	// current chain - newSelectionAlgoHeight depends on this
	Chain string `mapstructure:"chain"`
}

Configuration represents heimdall config

func GetConfig

func GetConfig() Configuration

GetConfig returns cached configuration object

func GetDefaultHeimdallConfig

func GetDefaultHeimdallConfig() Configuration

GetDefaultHeimdallConfig returns configuration with default params

func (*Configuration) Merge added in v0.3.2

func (c *Configuration) Merge(cc *Configuration)

func (*Configuration) UpdateWithFlags added in v0.3.2

func (c *Configuration) UpdateWithFlags(v *viper.Viper, loggerInstance logger.Logger) error

type ContractCaller

type ContractCaller struct {
	MainChainClient   *ethclient.Client
	MainChainRPC      *rpc.Client
	MainChainTimeout  time.Duration
	MaticChainClient  *ethclient.Client
	MaticChainRPC     *rpc.Client
	MaticChainTimeout time.Duration

	RootChainABI     abi.ABI
	StakingInfoABI   abi.ABI
	ValidatorSetABI  abi.ABI
	StateReceiverABI abi.ABI
	StateSenderABI   abi.ABI
	StakeManagerABI  abi.ABI
	SlashManagerABI  abi.ABI
	MaticTokenABI    abi.ABI

	ReceiptCache *lru.Cache

	ContractInstanceCache map[common.Address]interface{}
}

ContractCaller contract caller

func NewContractCaller

func NewContractCaller() (contractCallerObj ContractCaller, err error)

NewContractCaller contract caller

func (*ContractCaller) ApproveTokens

func (c *ContractCaller) ApproveTokens(amount *big.Int, stakeManager common.Address, tokenAddress common.Address, maticTokenInstance *erc20.Erc20) error

ApproveTokens approves matic token for stake

func (*ContractCaller) CheckIfBlocksExist added in v0.1.8

func (c *ContractCaller) CheckIfBlocksExist(end uint64) bool

CheckIfBlocksExist - check if the given block exists on local chain

func (*ContractCaller) CurrentAccountStateRoot

func (c *ContractCaller) CurrentAccountStateRoot(stakingInfoInstance *stakinginfo.Stakinginfo) ([32]byte, error)

CurrentAccountStateRoot get current account root from on chain

func (*ContractCaller) CurrentHeaderBlock

func (c *ContractCaller) CurrentHeaderBlock(rootChainInstance *rootchain.Rootchain, childBlockInterval uint64) (uint64, error)

CurrentHeaderBlock fetches current header block

func (*ContractCaller) CurrentSpanNumber

func (c *ContractCaller) CurrentSpanNumber(validatorSetInstance *validatorset.Validatorset) (Number *big.Int)

CurrentSpanNumber get current span

func (*ContractCaller) CurrentStateCounter

func (c *ContractCaller) CurrentStateCounter(stateSenderInstance *statesender.Statesender) (Number *big.Int)

CurrentStateCounter get state counter

func (*ContractCaller) DecodeNewHeaderBlockEvent

func (c *ContractCaller) DecodeNewHeaderBlockEvent(contractAddress common.Address, receipt *ethTypes.Receipt, logIndex uint64) (*rootchain.RootchainNewHeaderBlock, error)

DecodeNewHeaderBlockEvent represents new header block event

func (*ContractCaller) DecodeSignerUpdateEvent

func (c *ContractCaller) DecodeSignerUpdateEvent(contractAddress common.Address, receipt *ethTypes.Receipt, logIndex uint64) (*stakinginfo.StakinginfoSignerChange, error)

DecodeSignerUpdateEvent represents sig update event

func (*ContractCaller) DecodeSlashedEvent added in v0.1.7

func (c *ContractCaller) DecodeSlashedEvent(contractAddress common.Address, receipt *ethTypes.Receipt, logIndex uint64) (*stakinginfo.StakinginfoSlashed, error)

DecodeSlashedEvent represents tick ack on contract

func (*ContractCaller) DecodeStateSyncedEvent

func (c *ContractCaller) DecodeStateSyncedEvent(contractAddress common.Address, receipt *ethTypes.Receipt, logIndex uint64) (*statesender.StatesenderStateSynced, error)

DecodeStateSyncedEvent decode state sync data

func (*ContractCaller) DecodeUnJailedEvent added in v0.1.7

func (c *ContractCaller) DecodeUnJailedEvent(contractAddress common.Address, receipt *ethTypes.Receipt, logIndex uint64) (*stakinginfo.StakinginfoUnJailed, error)

DecodeUnJailedEvent represents unJail on contract

func (*ContractCaller) DecodeValidatorExitEvent

func (c *ContractCaller) DecodeValidatorExitEvent(contractAddress common.Address, receipt *ethTypes.Receipt, logIndex uint64) (*stakinginfo.StakinginfoUnstakeInit, error)

DecodeValidatorExitEvent represents validator stake unStake event

func (*ContractCaller) DecodeValidatorJoinEvent

func (c *ContractCaller) DecodeValidatorJoinEvent(contractAddress common.Address, receipt *ethTypes.Receipt, logIndex uint64) (*stakinginfo.StakinginfoStaked, error)

DecodeValidatorJoinEvent represents validator staked event

func (*ContractCaller) DecodeValidatorStakeUpdateEvent

func (c *ContractCaller) DecodeValidatorStakeUpdateEvent(contractAddress common.Address, receipt *ethTypes.Receipt, logIndex uint64) (*stakinginfo.StakinginfoStakeUpdate, error)

DecodeValidatorStakeUpdateEvent represents validator stake update event

func (*ContractCaller) DecodeValidatorTopupFeesEvent

func (c *ContractCaller) DecodeValidatorTopupFeesEvent(contractAddress common.Address, receipt *ethTypes.Receipt, logIndex uint64) (*stakinginfo.StakinginfoTopUpFee, error)

DecodeValidatorTopupFeesEvent represents topUp for fees tokens

func (*ContractCaller) GetBalance

func (c *ContractCaller) GetBalance(address common.Address) (*big.Int, error)

GetBalance get balance of account (returns big.Int balance won't fit in uint64)

func (*ContractCaller) GetBlockByNumber added in v1.0.1

func (c *ContractCaller) GetBlockByNumber(ctx context.Context, blockNumber uint64) *ethTypes.Block

GetBlockByNumber returns blocks by number from child chain (bor)

func (*ContractCaller) GetBlockNumberFromTxHash

func (c *ContractCaller) GetBlockNumberFromTxHash(tx common.Hash) (*big.Int, error)

GetBlockNumberFromTxHash gets block number of transaction

func (*ContractCaller) GetCheckpointSign

func (c *ContractCaller) GetCheckpointSign(txHash common.Hash) ([]byte, []byte, []byte, error)

GetCheckpointSign returns sigs input of committed checkpoint transaction

func (*ContractCaller) GetConfirmedTxReceipt

func (c *ContractCaller) GetConfirmedTxReceipt(tx common.Hash, requiredConfirmations uint64) (*ethTypes.Receipt, error)

GetConfirmedTxReceipt returns confirmed tx receipt

func (*ContractCaller) GetHeaderInfo

func (c *ContractCaller) GetHeaderInfo(number uint64, rootChainInstance *rootchain.Rootchain, childBlockInterval uint64) (
	root common.Hash,
	start uint64,
	end uint64,
	createdAt uint64,
	proposer types.HeimdallAddress,
	err error,
)

GetHeaderInfo get header info from checkpoint number

func (*ContractCaller) GetLastChildBlock

func (c *ContractCaller) GetLastChildBlock(rootChainInstance *rootchain.Rootchain) (uint64, error)

GetLastChildBlock fetch current child block

func (*ContractCaller) GetMainChainBlock

func (c *ContractCaller) GetMainChainBlock(blockNum *big.Int) (header *ethTypes.Header, err error)

GetMainChainBlock returns main chain block header

func (*ContractCaller) GetMainChainBlockTime added in v0.3.2

func (c *ContractCaller) GetMainChainBlockTime(ctx context.Context, blockNum uint64) (time.Time, error)

GetMainChainBlockTime returns main chain block time

func (*ContractCaller) GetMainChainFinalizedBlock added in v0.3.2

func (c *ContractCaller) GetMainChainFinalizedBlock() (header *ethTypes.Header, err error)

GetMainChainFinalizedBlock returns finalized main chain block header (post-merge)

func (*ContractCaller) GetMainTxReceipt

func (c *ContractCaller) GetMainTxReceipt(txHash common.Hash) (*ethTypes.Receipt, error)

GetMainTxReceipt returns main tx receipt

func (*ContractCaller) GetMaticChainBlock

func (c *ContractCaller) GetMaticChainBlock(blockNum *big.Int) (header *ethTypes.Header, err error)

GetMaticChainBlock returns child chain block header

func (*ContractCaller) GetMaticTokenInstance added in v0.1.5

func (c *ContractCaller) GetMaticTokenInstance(maticTokenAddress common.Address) (*erc20.Erc20, error)

GetMaticTokenInstance returns stakingInfo contract instance for selected base chain

func (*ContractCaller) GetMaticTxReceipt

func (c *ContractCaller) GetMaticTxReceipt(txHash common.Hash) (*ethTypes.Receipt, error)

GetMaticTxReceipt returns matic tx receipt

func (*ContractCaller) GetRootChainInstance added in v0.1.5

func (c *ContractCaller) GetRootChainInstance(rootChainAddress common.Address) (*rootchain.Rootchain, error)

GetRootChainInstance returns RootChain contract instance for selected base chain

func (*ContractCaller) GetRootHash added in v0.1.7

func (c *ContractCaller) GetRootHash(start uint64, end uint64, checkpointLength uint64) ([]byte, error)

GetRootHash get root hash from bor chain

func (*ContractCaller) GetSlashManagerInstance added in v0.1.7

func (c *ContractCaller) GetSlashManagerInstance(slashManagerAddress common.Address) (*slashmanager.Slashmanager, error)

GetSlashManagerInstance returns slashManager contract instance for selected base chain

func (*ContractCaller) GetSpanDetails

func (c *ContractCaller) GetSpanDetails(id *big.Int, validatorSetInstance *validatorset.Validatorset) (
	*big.Int,
	*big.Int,
	*big.Int,
	error,
)

GetSpanDetails get span details

func (*ContractCaller) GetStakeManagerInstance added in v0.1.5

func (c *ContractCaller) GetStakeManagerInstance(stakingManagerAddress common.Address) (*stakemanager.Stakemanager, error)

GetStakeManagerInstance returns stakingInfo contract instance for selected base chain

func (*ContractCaller) GetStakingInfoInstance added in v0.1.5

func (c *ContractCaller) GetStakingInfoInstance(stakingInfoAddress common.Address) (*stakinginfo.Stakinginfo, error)

GetStakingInfoInstance returns stakingInfo contract instance for selected base chain

func (*ContractCaller) GetStateReceiverInstance added in v0.1.5

func (c *ContractCaller) GetStateReceiverInstance(stateReceiverAddress common.Address) (*statereceiver.Statereceiver, error)

GetStateReceiverInstance returns stakingInfo contract instance for selected base chain

func (*ContractCaller) GetStateSenderInstance added in v0.1.5

func (c *ContractCaller) GetStateSenderInstance(stateSenderAddress common.Address) (*statesender.Statesender, error)

GetStateSenderInstance returns stakingInfo contract instance for selected base chain

func (*ContractCaller) GetValidatorInfo

func (c *ContractCaller) GetValidatorInfo(valID types.ValidatorID, stakingInfoInstance *stakinginfo.Stakinginfo) (validator types.Validator, err error)

GetValidatorInfo get validator info

func (*ContractCaller) GetValidatorSetInstance added in v0.1.5

func (c *ContractCaller) GetValidatorSetInstance(validatorSetAddress common.Address) (*validatorset.Validatorset, error)

GetValidatorSetInstance returns stakingInfo contract instance for selected base chain

func (*ContractCaller) GetVoteOnHash added in v1.0.1

func (c *ContractCaller) GetVoteOnHash(start uint64, end uint64, milestoneLength uint64, hash string, milestoneID string) (bool, error)

GetRootHash get root hash from bor chain

func (*ContractCaller) IsTxConfirmed

func (c *ContractCaller) IsTxConfirmed(tx common.Hash, requiredConfirmations uint64) bool

IsTxConfirmed is tx confirmed

func (*ContractCaller) SendCheckpoint

func (c *ContractCaller) SendCheckpoint(signedData []byte, sigs [][3]*big.Int, rootChainAddress common.Address, rootChainInstance *rootchain.Rootchain) (er error)

SendCheckpoint sends checkpoint to rootchain contract todo return err

func (*ContractCaller) SendTick added in v0.1.7

func (c *ContractCaller) SendTick(signedData []byte, sigs []byte, slashManagerAddress common.Address, slashManagerInstance *slashmanager.Slashmanager) (er error)

SendTick sends slash tick to rootchain contract

func (*ContractCaller) StakeFor

func (c *ContractCaller) StakeFor(val common.Address, stakeAmount *big.Int, feeAmount *big.Int, acceptDelegation bool, stakeManagerAddress common.Address, stakeManagerInstance *stakemanager.Stakemanager) error

StakeFor stakes for a validator

type HTTPClient added in v0.3.2

type HTTPClient interface {
	Get(string) (resp *http.Response, err error)
}
var (
	Client HTTPClient
)

type IContractCaller

type IContractCaller interface {
	GetHeaderInfo(headerID uint64, rootChainInstance *rootchain.Rootchain, childBlockInterval uint64) (root common.Hash, start, end, createdAt uint64, proposer types.HeimdallAddress, err error)
	GetRootHash(start uint64, end uint64, checkpointLength uint64) ([]byte, error)
	GetVoteOnHash(start uint64, end uint64, milestoneLength uint64, hash string, milestoneID string) (bool, error)
	GetValidatorInfo(valID types.ValidatorID, stakingInfoInstance *stakinginfo.Stakinginfo) (validator types.Validator, err error)
	GetLastChildBlock(rootChainInstance *rootchain.Rootchain) (uint64, error)
	CurrentHeaderBlock(rootChainInstance *rootchain.Rootchain, childBlockInterval uint64) (uint64, error)
	GetBalance(address common.Address) (*big.Int, error)
	SendCheckpoint(signedData []byte, sigs [][3]*big.Int, rootChainAddress common.Address, rootChainInstance *rootchain.Rootchain) (err error)
	SendTick(signedData []byte, sigs []byte, slashManagerAddress common.Address, slashManagerInstance *slashmanager.Slashmanager) (err error)
	GetCheckpointSign(txHash common.Hash) ([]byte, []byte, []byte, error)
	GetMainChainBlock(*big.Int) (*ethTypes.Header, error)
	GetMaticChainBlock(*big.Int) (*ethTypes.Header, error)
	IsTxConfirmed(common.Hash, uint64) bool
	GetConfirmedTxReceipt(common.Hash, uint64) (*ethTypes.Receipt, error)
	GetBlockNumberFromTxHash(common.Hash) (*big.Int, error)

	// decode header event
	DecodeNewHeaderBlockEvent(common.Address, *ethTypes.Receipt, uint64) (*rootchain.RootchainNewHeaderBlock, error)
	// decode validator events
	DecodeValidatorTopupFeesEvent(common.Address, *ethTypes.Receipt, uint64) (*stakinginfo.StakinginfoTopUpFee, error)
	DecodeValidatorJoinEvent(common.Address, *ethTypes.Receipt, uint64) (*stakinginfo.StakinginfoStaked, error)
	DecodeValidatorStakeUpdateEvent(common.Address, *ethTypes.Receipt, uint64) (*stakinginfo.StakinginfoStakeUpdate, error)
	DecodeValidatorExitEvent(common.Address, *ethTypes.Receipt, uint64) (*stakinginfo.StakinginfoUnstakeInit, error)
	DecodeSignerUpdateEvent(common.Address, *ethTypes.Receipt, uint64) (*stakinginfo.StakinginfoSignerChange, error)
	// decode state events
	DecodeStateSyncedEvent(common.Address, *ethTypes.Receipt, uint64) (*statesender.StatesenderStateSynced, error)

	// decode slashing events
	DecodeSlashedEvent(common.Address, *ethTypes.Receipt, uint64) (*stakinginfo.StakinginfoSlashed, error)
	DecodeUnJailedEvent(common.Address, *ethTypes.Receipt, uint64) (*stakinginfo.StakinginfoUnJailed, error)

	GetMainTxReceipt(common.Hash) (*ethTypes.Receipt, error)
	GetMaticTxReceipt(common.Hash) (*ethTypes.Receipt, error)
	ApproveTokens(*big.Int, common.Address, common.Address, *erc20.Erc20) error
	StakeFor(common.Address, *big.Int, *big.Int, bool, common.Address, *stakemanager.Stakemanager) error
	CurrentAccountStateRoot(stakingInfoInstance *stakinginfo.Stakinginfo) ([32]byte, error)

	// bor related contracts
	CurrentSpanNumber(validatorSet *validatorset.Validatorset) (Number *big.Int)
	GetSpanDetails(id *big.Int, validatorSet *validatorset.Validatorset) (*big.Int, *big.Int, *big.Int, error)
	CurrentStateCounter(stateSenderInstance *statesender.Statesender) (Number *big.Int)
	CheckIfBlocksExist(end uint64) bool

	GetRootChainInstance(rootChainAddress common.Address) (*rootchain.Rootchain, error)
	GetStakingInfoInstance(stakingInfoAddress common.Address) (*stakinginfo.Stakinginfo, error)
	GetValidatorSetInstance(validatorSetAddress common.Address) (*validatorset.Validatorset, error)
	GetStakeManagerInstance(stakingManagerAddress common.Address) (*stakemanager.Stakemanager, error)
	GetSlashManagerInstance(slashManagerAddress common.Address) (*slashmanager.Slashmanager, error)
	GetStateSenderInstance(stateSenderAddress common.Address) (*statesender.Statesender, error)
	GetStateReceiverInstance(stateReceiverAddress common.Address) (*statereceiver.Statereceiver, error)
	GetMaticTokenInstance(maticTokenAddress common.Address) (*erc20.Erc20, error)
}

IContractCaller represents contract caller

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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