helper

package
v0.2.8-mumbai Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: GPL-3.0 Imports: 64 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeFlag               = "node"
	WithHeimdallConfigFlag = "with-heimdall-config"
	HomeFlag               = "home"
	FlagClientHome         = "home-client"

	// ---
	// 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"

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

	// 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

	DefaultMainchainGasLimit = uint64(5000000)

	DefaultMainchainMaxGasPrice = 400000000000 // 400 Gwei

	DefaultBorChainID string = "15001"

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

	// New max state sync size after hardfork
	MaxStateSyncSize = 30000
)
View Source
const (
	// CommitTimeout commit timeout
	CommitTimeout = 2 * time.Minute
)

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 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 BytesToPubkey

func BytesToPubkey(pubKey []byte) secp256k1.PubKeySecp256k1

BytesToPubkey converts bytes to Pubkey

func EventByID

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

EventByID looks up a event by the topic id

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 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 GetAmountFromString

func GetAmountFromString(amount string) (*big.Int, error)

GetAmountFromString converts string to its big Int

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 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 GetMaticEthClient added in v0.1.7

func GetMaticEthClient() *eth.EthAPIBackend

GetMaticEthClient 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 GetNodeStatus

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

GetNodeStatus returns node status

func GetPkObjects

GetPkObjects from crypto priv key

func GetPowerFromAmount

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

GetPowerFromAmount returns power from amount -- note that this will polute 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 GetReceiptLogData

func GetReceiptLogData(log *ethTypes.Log) []byte

GetReceiptLogData get receipt log data

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 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 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, heimdallConfigFilePath string)

InitHeimdallConfigWith initializes passed heimdall/tendermint config files

func NewLru added in v0.1.6

func NewLru(size int) (*lru.Cache, error)

NewLru create instance of lru

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 StringToPubkey

func StringToPubkey(pubkeyStr string) (secp256k1.PubKeySecp256k1, error)

StringToPubkey converts string to Pubkey

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 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.

Types

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

	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"`

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

Configuration represents heimdall config

func GetConfig

func GetConfig() Configuration

GetConfig returns cached configuration object

func GetDefaultHeimdallConfig

func GetDefaultHeimdallConfig() Configuration

GetDefaultHeimdallConfig returns configration with default params

func ParseConfig

func ParseConfig() (*Configuration, error)

ParseConfig retrieves the default environment configuration for the application.

type ContractCaller

type ContractCaller struct {
	MainChainClient  *ethclient.Client
	MainChainRPC     *rpc.Client
	MaticChainClient *ethclient.Client
	MaticChainRPC    *rpc.Client

	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 wont fit in uint64)

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 tranasction

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) 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) 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 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)
	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(sigedData []byte, sigs [][3]*big.Int, rootchainAddress common.Address, rootChainInstance *rootchain.Rootchain) (err error)
	SendTick(sigedData []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

Jump to

Keyboard shortcuts

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