context

package
v0.0.0-...-2287164 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2020 License: GPL-3.0 Imports: 32 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	PerPage                 = 100 // (0, 100]
	HdrLimitPerBatch        = 50
	QueryConsensusPath      = "/custom/" + headersync.ModuleName + "/" + headersync.QueryConsensusPeers
	CosmosCrossChainModName = ccm.ModuleName
	RightHeightUpdate       = "update latest height"
	CosmosProofKey          = "make_from_cosmos_proof"
	ProofPath               = "/store/" + ccm.ModuleName + "/key"
	TxAlreadyExist          = "already done"
	NewEpoch                = "lower than epoch switching height"
	SeqErr                  = "verify correct account sequence and chain-id"
	BroadcastConnTimeOut    = "connection timed out"
	UtxoNotEnough           = "current utxo is not enoug"
	ChanBufSize             = 256
	QueryAccPath            = "/custom/acc/account"
	CosmosTxNotInEpoch      = "Compare height"
	NoUsefulHeaders         = "no header you commited is useful"
)

Variables

View Source
var (
	RCtx = &Ctx{}
)
View Source
var (
	SleepSecs = func(n int) {
		time.Sleep(time.Duration(n) * time.Second)
	}
)

Functions

func CalcCosmosFees

func CalcCosmosFees(gasPrice types.DecCoins, gas uint64) (types.Coins, error)

func GetAccountByPassword

func GetAccountByPassword(sdk *poly_go_sdk.PolySdk, path string, pwd []byte) (*poly_go_sdk.Account, error)

func GetCosmosPrivateKey

func GetCosmosPrivateKey(path string, pwd []byte) (crypto2.PrivKey, types.AccAddress, error)

func InitCtx

func InitCtx(conf *Conf) error

func NewCodecForRelayer

func NewCodecForRelayer() *codec.Codec

Types

type Conf

type Conf struct {
	CosmosRpcAddr        string `json:"cosmos_rpc_addr"`
	CosmosWallet         string `json:"cosmos_wallet"`
	CosmosWalletPwd      string `json:"cosmos_wallet_pwd"`
	CosmosStartHeight    int64  `json:"cosmos_start_height"`
	CosmosListenInterval int    `json:"cosmos_listen_interval"`
	CosmosChainId        string `json:"cosmos_chain_id"`
	CosmosGasPrice       string `json:"cosmos_gas_price"`
	CosmosGas            uint64 `json:"cosmos_gas"`

	PolyRpcAddr        string `json:"poly_rpc_addr"`
	PolyWallet         string `json:"poly_wallet"`
	PolyWalletPwd      string `json:"poly_wallet_pwd"`
	PolyStartHeight    uint32 `json:"poly_start_height"`
	PolyListenInterval int    `json:"poly_listen_interval"`
	PolyToCosmosKey    string `json:"poly_to_cosmos_key"`

	SideChainId    uint64 `json:"side_chain_id"`
	DBPath         string `json:"db_path"`
	ConfirmTimeout int    `json:"confirm_timeout"`

	LogLevel int `json:"log_level"`
}

func NewConf

func NewConf(file string) (*Conf, error)

type CosmosInfo

type CosmosInfo struct {
	// type 1 means header and tx; type 2 means only header;
	Type InfoType

	// to update height of chain
	Height int64

	// tx part
	Tx *CosmosTx

	// header part
	Hdrs []*cosmos.CosmosHeader
}

type CosmosSeq

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

func (*CosmosSeq) GetAndAdd

func (seq *CosmosSeq) GetAndAdd() uint64

type CosmosStatus

type CosmosStatus struct {
	Txs             *sync.Map // TODO: record a start time to test if it's not confirm for a long time, that could be tx lost
	Wg              *sync.WaitGroup
	IsBlocked       bool
	PolyEpochHeight uint32
}

func NewCosmosStatus

func NewCosmosStatus() (*CosmosStatus, error)

func (*CosmosStatus) AddTx

func (s *CosmosStatus) AddTx(hash bytes.HexBytes, info *PolyInfo) error

func (*CosmosStatus) Check

func (s *CosmosStatus) Check()

TODO: 交易丢失了怎么办,会一直循环查找地!!

func (*CosmosStatus) DelTx

func (s *CosmosStatus) DelTx(hash bytes.HexBytes) error

func (*CosmosStatus) Len

func (s *CosmosStatus) Len() int

func (*CosmosStatus) Show

func (s *CosmosStatus) Show()

type CosmosTx

type CosmosTx struct {
	Tx          *rpctypes.ResultTx
	ProofHeight int64
	Proof       []byte
	PVal        []byte
}

type Ctx

type Ctx struct {
	// configuration
	Conf *Conf

	// To transfer cross chain tx from listening to relaying
	ToCosmos chan *PolyInfo
	ToPoly   chan *CosmosInfo

	// Cosmos
	CMRpcCli *rpchttp.HTTP
	CMPrivk  tcrypto.PrivKey
	CMAcc    ctypes.AccAddress
	CMSeq    *CosmosSeq
	CMAccNum uint64
	CMFees   ctypes.Coins
	CMGas    uint64
	CMCdc    *codec.Codec

	// Poly chain
	Poly    *poly_go_sdk.PolySdk
	PolyAcc *poly_go_sdk.Account

	// DB
	Db *db.Database

	// status for relayed tx
	CMStatus   *CosmosStatus
	PolyStatus *PolyStatus
}

type InfoType

type InfoType int
const (
	TyTx InfoType = iota
	TyHeader
	TyUpdateHeight
)

type PolyInfo

type PolyInfo struct {
	// type 0 means only tx; type 2 means header and tx; type 1 means only header;
	Type InfoType

	// to update height of Poly on COSMOS
	Height uint32

	// tx part
	Tx *PolyTx

	// header part
	Hdr *types.Header

	// proof of header which is not during current epoch
	HeaderProof string

	// any header in current epoch can be trust anchor
	EpochAnchor string
}

type PolyStatus

type PolyStatus struct {
	Txs               *sync.Map
	Wg                *sync.WaitGroup
	IsBlocked         bool
	CosmosEpochHeight int64
}

func NewPolyStatus

func NewPolyStatus() (*PolyStatus, error)

func (*PolyStatus) AddTx

func (s *PolyStatus) AddTx(hash common.Uint256, rtx *rpctypes.ResultTx) error

func (*PolyStatus) Check

func (s *PolyStatus) Check()

func (*PolyStatus) DelTx

func (s *PolyStatus) DelTx(hash common.Uint256) error

func (*PolyStatus) Len

func (s *PolyStatus) Len() int

func (*PolyStatus) Show

func (s *PolyStatus) Show()

type PolyTx

type PolyTx struct {
	Height      uint32
	Proof       string
	TxHash      string
	IsEpoch     bool
	CCID        []byte
	FromChainId uint64
}

Jump to

Keyboard shortcuts

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