chain

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: LGPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGasLimit           = 1000000
	DefaultGasPrice           = 50000000
	DefaultBlockConfirmations = 10
	DefaultGasMultiplier      = 1
)

Variables

View Source
var (
	OrderExist       = errors.New("order exist")
	NotVerifyAble    = errors.New("not verify able")
	ContractNotExist = errors.New("contract not exist")
)
View Source
var (
	McsOpt                = "mcs"
	TronMcsOpt            = "tronmcs"
	MaxGasPriceOpt        = "maxGasPrice"
	GasLimitOpt           = "gasLimit"
	GasMultiplier         = "gasMultiplier"
	LimitMultiplier       = "limitMultiplier"
	HttpOpt               = "http"
	StartBlockOpt         = "startBlock"
	BlockConfirmationsOpt = "blockConfirmations"
	SyncToMap             = "syncToMap"
	SyncIDList            = "syncIdList"
	LightNode             = "lightnode"
	Event                 = "event"
	Eth2Url               = "eth2Url"
	RedisOpt              = "redis"
	ApiUrl                = "apiUrl"
	OracleNode            = "oracleNode"
	RentNode              = "rentNode"
	EthFrom               = "ethFrom"
	FeeKey                = "feeKey"
	FeeType               = "feeType"
)

Chain specific options

Functions

func DefaultOracleHandler added in v1.2.0

func DefaultOracleHandler(m *Oracle, currentBlock *big.Int) error

func PreSendTx added in v1.2.0

func PreSendTx(idx int, selfChainId, toChainID uint64, blockNumber *big.Int, orderId []byte) (int64, error)

func Request added in v1.2.2

func Request(urlPath string) (interface{}, error)

func SetupBlockStore

func SetupBlockStore(cfg *Config, role mapprotocol.Role) (*blockstore.Blockstore, error)

Types

type AssembleProof added in v1.2.0

type AssembleProof func(*Messenger, *types.Log, int64, uint64, [][]byte) (*msg.Message, error)

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

func New

func New(chainCfg *core.ChainConfig, logger log15.Logger, sysErr chan<- error, role mapprotocol.Role,
	createConn core.CreateConn, opts ...SyncOpt) (*Chain, error)

func (*Chain) Conn

func (c *Chain) Conn() core.Connection

Conn return Connection interface for relayer register

func (*Chain) EthClient

func (c *Chain) EthClient() *ethclient.Client

EthClient return EthClient for global map connection

func (*Chain) Id

func (c *Chain) Id() msg.ChainId

func (*Chain) Name

func (c *Chain) Name() string

func (*Chain) SetRouter

func (c *Chain) SetRouter(r *core.Router)

func (*Chain) Start

func (c *Chain) Start() error

func (*Chain) Stop

func (c *Chain) Stop()

Stop signals to any running routines to exit

type CommonSync

type CommonSync struct {
	Cfg                Config
	Conn               core.Connection
	Log                log15.Logger
	Router             chains.Router
	Stop               <-chan int
	MsgCh              chan struct{}
	SysErr             chan<- error // Reports fatal error to core
	BlockConfirmations *big.Int
	BlockStore         blockstore.Blockstorer
	// contains filtered or unexported fields
}

func NewCommonSync

func NewCommonSync(conn core.Connection, cfg *Config, log log15.Logger, stop <-chan int, sysErr chan<- error,
	bs blockstore.Blockstorer, opts ...SyncOpt) *CommonSync

NewCommonSync creates and returns a listener

func (*CommonSync) BuildQuery

func (c *CommonSync) BuildQuery(contract ethcommon.Address, sig []constant.EventSig, startBlock *big.Int, endBlock *big.Int) eth.FilterQuery

BuildQuery constructs a query for the bridgeContract by hashing sig to get the event topic

func (*CommonSync) FilterLatestBlock added in v1.2.2

func (c *CommonSync) FilterLatestBlock() (*big.Int, error)

func (*CommonSync) GetMethod

func (c *CommonSync) GetMethod(topic ethcommon.Hash) string

func (*CommonSync) Match added in v1.2.2

func (c *CommonSync) Match(target string) int

func (*CommonSync) SetRouter

func (c *CommonSync) SetRouter(r chains.Router)

func (*CommonSync) WaitUntilMsgHandled

func (c *CommonSync) WaitUntilMsgHandled(counter int) error

WaitUntilMsgHandled this function will block untill message is handled

type Config

type Config struct {
	Name               string      // Human-readable chain name
	Id                 msg.ChainId // ChainID
	Endpoint           string      // url for rpc endpoint
	From               string      // address of key to use
	KeystorePath       string      // Location of keyfiles
	BlockstorePath     string
	FreshStart         bool // Disables loading from blockstore at start
	McsContract        []common.Address
	GasLimit           *big.Int
	MaxGasPrice        *big.Int
	GasMultiplier      float64
	LimitMultiplier    float64
	Http               bool // Config for type of connection
	StartBlock         *big.Int
	BlockConfirmations *big.Int
	SyncToMap          bool // Whether sync blockchain headers to Map
	MapChainID         msg.ChainId
	SyncChainIDList    []msg.ChainId  // chain ids which map sync to
	LightNode          common.Address // the lightnode to sync header
	SyncMap            map[msg.ChainId]*big.Int
	Events             []constant.EventSig
	SkipError          bool
	Eth2Endpoint       string
	ApiUrl             string
	OracleNode         common.Address
	TronContract       []common.Address
	Filter             bool
	FilterHost         string
}

Config encapsulates all necessary parameters in ethereum compatible forms

func ParseConfig

func ParseConfig(chainCfg *core.ChainConfig) (*Config, error)

ParseConfig uses a core.ChainConfig to construct a corresponding Config

type Maintainer

type Maintainer struct {
	*CommonSync
	// contains filtered or unexported fields
}

func NewMaintainer

func NewMaintainer(cs *CommonSync) *Maintainer

func (*Maintainer) Sync

func (m *Maintainer) Sync() error

type Messenger

type Messenger struct {
	*CommonSync
}

func NewMessenger

func NewMessenger(cs *CommonSync) *Messenger

func (*Messenger) Sync

func (m *Messenger) Sync() error

type Mos

type Mos func(*Messenger, *big.Int) (int, error)

type MulSignInfoResp added in v1.2.2

type MulSignInfoResp struct {
	Version [32]byte
	Quorum  *big.Int
	Singers []common.Address
}

func MulSignInfo added in v1.2.2

func MulSignInfo(idx int, selfChainId, toChainID uint64) (*MulSignInfoResp, error)

type Oracle added in v1.2.0

type Oracle struct {
	*CommonSync
}

func NewOracle added in v1.2.0

func NewOracle(cs *CommonSync) *Oracle

func (*Oracle) Sync added in v1.2.0

func (m *Oracle) Sync() error

type OracleHandler added in v1.2.0

type OracleHandler func(*Oracle, *big.Int) error

type OrderStatusResp added in v1.2.0

type OrderStatusResp struct {
	Exists     bool
	Verifiable bool
	NodeType   *big.Int
}

func OrderStatus added in v1.2.0

func OrderStatus(idx int, selfChainId, toChainID uint64, blockNumber *big.Int, orderId []byte) (*OrderStatusResp, error)

type ProposalInfoResp added in v1.2.2

type ProposalInfoResp struct {
	Singers    []common.Address
	Signatures [][]byte
	CanVerify  bool
}

func ProposalInfo added in v1.2.2

func ProposalInfo(idx int, selfChainId, toChainID uint64, blockNumber *big.Int, receipt common.Hash, version [32]byte) (*ProposalInfoResp, error)

func Signer added in v1.2.2

func Signer(cli *ethclient.Client, selfId, toId uint64, log *types.Log) (*ProposalInfoResp, error)

type SyncHeader2Map

type SyncHeader2Map func(*Maintainer, *big.Int) error

type SyncOpt

type SyncOpt func(*CommonSync)

func OptOfAssembleProof added in v1.2.0

func OptOfAssembleProof(fn AssembleProof) SyncOpt

func OptOfInitHeight

func OptOfInitHeight(height int64) SyncOpt

func OptOfMos

func OptOfMos(fn Mos) SyncOpt

func OptOfOracleHandler added in v1.2.0

func OptOfOracleHandler(fn OracleHandler) SyncOpt

func OptOfSync2Map

func OptOfSync2Map(fn SyncHeader2Map) SyncOpt

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(conn core.Connection, cfg *Config, log log15.Logger, stop <-chan int, sysErr chan<- error) *Writer

NewWriter creates and returns Writer

func (*Writer) ResolveMessage

func (w *Writer) ResolveMessage(m msg.Message) bool

ResolveMessage handles any given message based on type A bool is returned to indicate failure/success, this should be ignored except for within tests.

Jump to

Keyboard shortcuts

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