common

package
v0.0.0-...-11a4fed Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ObserverMaxBlockNumber = 10000
	ObserverPruneInterval  = 10 * time.Minute
	ObserverAlertInterval  = 5 * time.Minute

	DeputyConfirmTxInterval      = 5 * time.Second
	DeputySendTxInterval         = 5 * time.Second
	DeputyCheckTxSentInterval    = 5 * time.Second
	DeputyExpireUserHTLTInterval = 10 * time.Second
	DeputyAlertInterval          = 5 * time.Minute
	DeputyReconInterval          = 1 * time.Hour
	DeputyMetricsInterval        = 10 * time.Second
	// The deputy overflow interval must be longer than the time it takes for a tx to be confirmed.
	// Otherwise funds will be sent from the deputy while a previous tx is still processing, resulting
	// in too much coins being removed fromthe hot wallet.
	DeputyRunOverflowInterval = 1 * time.Hour
)
View Source
const (
	DBDialectMysql   = "mysql"
	DBDialectSqlite3 = "sqlite3"
)
View Source
const BEP2Decimal = 8
View Source
const BNBSymbol = "BNB"
View Source
const ChainBinance = "BNB"
View Source
const ChainEth = "ETH"

chains supported now, if you want to add other chain, pls add chain name here

View Source
const ChainKava = "KAVA"
View Source
const EthSwapTypeErc20 = "erc20_swap"
View Source
const EthSwapTypeEth = "eth_swap"
View Source
const KAVASymbol = "KAVA"

Variables

View Source
var Fixed8Decimals = big.NewInt(int64(math.Pow10(8)))

Functions

This section is empty.

Types

type BlockAndTxLogs

type BlockAndTxLogs struct {
	Height          int64
	BlockHash       string
	ParentBlockHash string
	BlockTime       int64
	TxLogs          []*store.TxLog
}

type BnbStatus

type BnbStatus struct {
	Balance []types.TokenBalance `json:"balance"`
}

type DeputyMode

type DeputyMode int
const (
	DeputyModeNormal       DeputyMode = 0
	DeputyModeStopSendHTLT DeputyMode = 1
)

func (DeputyMode) MarshalJSON

func (mode DeputyMode) MarshalJSON() ([]byte, error)

func (DeputyMode) String

func (mode DeputyMode) String() string

type DeputyStatus

type DeputyStatus struct {
	Mode                         DeputyMode `json:"mode"`
	BnbChainHeight               int64      `json:"bnb_chain_height"`
	BnbSyncHeight                int64      `json:"bnb_sync_height"`
	OtherChainHeight             int64      `json:"other_chain_height"`
	OtherChainSyncHeight         int64      `json:"other_chain_sync_height"`
	BnbChainLastBlockFetchedAt   time.Time  `json:"bnb_chain_last_block_fetched_at"`
	OtherChainLastBlockFetchedAt time.Time  `json:"other_chain_last_block_fetched_at"`

	BnbStatus        interface{} `json:"bnb_status"`
	OtherChainStatus interface{} `json:"other_chain_status"`
}

type Error

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

func NewError

func NewError(err error, retryable bool) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Retryable

func (e *Error) Retryable() bool

type EthStatus

type EthStatus struct {
	Allowance    string `json:"allowance"`
	Erc20Balance string `json:"erc20_balance"`
	EthBalance   string `json:"eth_balance"`
}

type Executor

type Executor interface {
	// GetChain returns unique name of the chain(like BNB, ETH and etc)
	GetChain() string
	// GetHeight returns current height of chain
	GetHeight() (int64, error)
	// GetBlockAndTxs returns block info and txs included in this block
	GetBlockAndTxs(height int64) (*BlockAndTxLogs, error)
	// GetFetchInterval returns fetch interval of the chain like average blocking time, it is used in observer
	GetFetchInterval() time.Duration
	// GetDeputyAddress returns deputy account address
	GetDeputyAddress() string
	// GetColdWalletAddress returns the address of the deputy's cold wallet
	GetColdWalletAddress() string
	// GetSentTxStatus returns status of tx sent
	GetSentTxStatus(hash string) store.TxStatus
	// GetBalance returns balance of swap token for any address
	GetBalance(address string) (*big.Int, error)
	// GetStatus returns status of deputy account, like balance of deputy account
	GetStatus() (interface{}, error)
	// GetBalanceAlertMsg returns balance alert message if necessary, like account balance is less than amount in config
	GetBalanceAlertMsg() (string, error)
	// IsSameAddress returns is addrA the same with addrB
	IsSameAddress(addrA string, addrB string) bool
	// CalcSwapId calculate swap id for each chain
	CalcSwapId(randomNumberHash common.Hash, sender string, senderOtherChain string) ([]byte, error)
	// Claimable returns is swap claimable
	Claimable(swapId common.Hash) (bool, error)
	// Refundable returns is swap refundable
	Refundable(swapId common.Hash) (bool, error)
	// GetSwap returns swap request detail
	GetSwap(swapId common.Hash) (*SwapRequest, error)
	// HasSwap returns does swap exist
	HasSwap(swapId common.Hash) (bool, error)
	// HTLT sends htlt tx
	HTLT(randomNumberHash common.Hash, timestamp int64, heightSpan int64, recipientAddr string, otherChainSenderAddr string,
		otherChainRecipientAddr string, outAmount *big.Int) (string, *Error)
	// Claim sends claim tx
	Claim(swapId common.Hash, randomNumber common.Hash) (string, *Error)
	// Refund sends refund tx
	Refund(swapId common.Hash) (string, *Error)
	// SendAmount
	SendAmount(address string, amount *big.Int) (string, error)
}

type FailedSwaps

type FailedSwaps struct {
	TotalCount int           `json:"total_count"`
	CurPage    int           `json:"cur_page"`
	NumPerPage int           `json:"num_per_page"`
	Swaps      []*SwapStatus `json:"swaps"`
}

type KavaStatus

type KavaStatus struct {
	Balance sdk.Coins `json:"balance"`
}

type ReconciliationStatus

type ReconciliationStatus struct {
	Bep2TokenBalance          *big.Float
	Bep2TokenOutPending       *big.Float
	OtherChainTokenBalance    *big.Float
	OtherChainTokenOutPending *big.Float
}

type SwapRequest

type SwapRequest struct {
	Id                  common.Hash
	RandomNumberHash    common.Hash
	ExpireHeight        int64
	SenderAddress       string
	RecipientAddress    string
	RecipientOtherChain string
	OutAmount           *big.Int
}

type SwapStatus

type SwapStatus struct {
	Id               int64            `json:"id"`
	Type             store.SwapType   `json:"type"`
	SenderAddr       string           `json:"sender_addr"`
	ReceiverAddr     string           `json:"receiver_addr"`
	OtherChainAddr   string           `json:"other_chain_addr"`
	InAmount         string           `json:"in_amount"`
	OutAmount        string           `json:"out_amount"`
	RandomNumberHash string           `json:"random_number_hash"`
	ExpireHeight     int64            `json:"expire_height"`
	Height           int64            `json:"height"`
	Timestamp        int64            `json:"timestamp"`
	RandomNumber     string           `json:"random_number"`
	Status           store.SwapStatus `json:"status"`
	TxsSent          []*store.TxSent  `json:"txs_sent"`
}

Jump to

Keyboard shortcuts

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