Documentation ¶
Overview ¶
Package tokens defines the common interfaces and supported bridges in sub directories.
Index ¶
- Constants
- Variables
- func CalcSwappedValue(pairID string, value *big.Int, isSrc bool) *big.Int
- func CheckSwapValue(pairID string, value *big.Int, isSrc bool) bool
- func CmpAndSetLatestBlockHeight(latest uint64, isSrc bool)
- func FromBits(value *big.Int, decimals uint8) float64
- func GetAllPairIDs() []string
- func GetBigValueThreshold(pairID string, isSrc bool) *big.Int
- func GetStableConfirmations(isSrc bool) uint64
- func GetTokenPairsConfig() map[string]*TokenPairConfig
- func GetTokenPairsDir() string
- func IsTokenPairExist(pairID string) bool
- func LoadTokenPairsConfig(check bool)
- func LoadTokenPairsConfigInDir(dir string, check bool) (map[string]*TokenPairConfig, error)
- func SetLatestBlockHeight(latest uint64, isSrc bool)
- func SetTokenPairsConfig(pairsConfig map[string]*TokenPairConfig, check bool)
- func SetTokenPairsDir(dir string)
- func ShouldRegisterSwapForError(err error) bool
- func ToBits(value float64, decimals uint8) *big.Int
- type AllExtras
- type BlockExtraArgs
- type BlocknetCoreAPIArgs
- type BtcExtraArgs
- type BtcExtraConfig
- type BtcOutPoint
- type BuildTxArgs
- type ChainConfig
- func (c *ChainConfig) CheckConfig(isServer bool) error
- func (c *ChainConfig) GetFixedGasPrice() *big.Int
- func (c *ChainConfig) GetMaxGasFeeCap() *big.Int
- func (c *ChainConfig) GetMaxGasPrice() *big.Int
- func (c *ChainConfig) GetMaxGasTipCap() *big.Int
- func (c *ChainConfig) GetMinReserveFee() *big.Int
- func (c *ChainConfig) IsInCallByContractWhitelist(caller string) bool
- type CrossChainBridge
- type CrossChainBridgeBase
- func (b *CrossChainBridgeBase) GetChainConfig() *ChainConfig
- func (b *CrossChainBridgeBase) GetDcrmPublicKey(pairID string) string
- func (b *CrossChainBridgeBase) GetGatewayConfig() *GatewayConfig
- func (b *CrossChainBridgeBase) GetTokenConfig(pairID string) *TokenConfig
- func (b *CrossChainBridgeBase) IsSrcEndpoint() bool
- func (b *CrossChainBridgeBase) SetChainAndGateway(chainCfg *ChainConfig, gatewayCfg *GatewayConfig)
- type EthExtraArgs
- type ForkChecker
- type GatewayConfig
- type GatewayExtras
- type NonceSetter
- type P2shAddressInfo
- type SwapInfo
- type SwapTxType
- type SwapType
- type TokenConfig
- func (c *TokenConfig) CalcAndStoreValue()
- func (c *TokenConfig) CheckConfig(isSrc bool) error
- func (c *TokenConfig) GetDcrmAddressPrivateKey() *ecdsa.PrivateKey
- func (c *TokenConfig) IsErc20() bool
- func (c *TokenConfig) IsProxyErc20() bool
- func (c *TokenConfig) LoadDcrmAddressPrivateKey() error
- func (c *TokenConfig) VerifyDcrmPublicKey() error
- type TokenPairConfig
- type TxStatus
- type TxSwapInfo
Constants ¶
const ( LockMemoPrefix = "SWAPTO:" UnlockMemoPrefix = "SWAPTX:" AggregateMemo = "aggregate" MaxPlusGasPricePercentage = uint64(100) )
transaction memo prefix
Variables ¶
var ( AggregateIdentifier = "aggregate" SrcBridge CrossChainBridge DstBridge CrossChainBridge SrcNonceSetter NonceSetter DstNonceSetter NonceSetter SrcForkChecker ForkChecker DstForkChecker ForkChecker SrcLatestBlockHeight uint64 DstLatestBlockHeight uint64 SrcStableConfirmations uint64 DstStableConfirmations uint64 IsDcrmDisabled bool )
common variables
var ( ErrSwapTypeNotSupported = errors.New("swap type not supported in this endpoint") ErrBridgeSourceNotSupported = errors.New("bridge source not supported") ErrBridgeDestinationNotSupported = errors.New("bridge destination not supported") ErrUnknownSwapType = errors.New("unknown swap type") ErrMsgHashMismatch = errors.New("message hash mismatch") ErrWrongCountOfMsgHashes = errors.New("wrong count of msg hashed") ErrWrongRawTx = errors.New("wrong raw tx") ErrWrongExtraArgs = errors.New("wrong extra args") ErrNoBtcBridge = errors.New("no btc bridge exist") ErrWrongSwapinTxType = errors.New("wrong swapin tx type") ErrBuildSwapTxInWrongEndpoint = errors.New("build swap in/out tx in wrong endpoint") ErrTxBeforeInitialHeight = errors.New("transaction before initial block height") ErrAddressIsInBlacklist = errors.New("address is in black list") ErrSwapIsClosed = errors.New("swap is closed") ErrTodo = errors.New("developing: TODO") ErrTxNotFound = errors.New("tx not found") ErrTxNotStable = errors.New("tx not stable") ErrTxWithWrongReceiver = errors.New("tx with wrong receiver") ErrTxWithWrongContract = errors.New("tx with wrong contract") ErrTxWithWrongInput = errors.New("tx with wrong input data") ErrTxWithWrongLogData = errors.New("tx with wrong log data") ErrTxIsAggregateTx = errors.New("tx is aggregate tx") ErrWrongP2shBindAddress = errors.New("wrong p2sh bind address") ErrTxFuncHashMismatch = errors.New("tx func hash mismatch") ErrDepositLogNotFound = errors.New("deposit log not found or removed") ErrSwapoutLogNotFound = errors.New("swapout log not found or removed") ErrUnknownPairID = errors.New("unknown pair ID") ErrBindAddressMismatch = errors.New("bind address mismatch") ErrRPCQueryError = errors.New("rpc query error") ErrWrongSwapValue = errors.New("wrong swap value") ErrTxIncompatible = errors.New("tx incompatible") ErrTxWithWrongReceipt = errors.New("tx with wrong receipt") // errors should register ErrTxWithWrongMemo = errors.New("tx with wrong memo") ErrTxWithWrongValue = errors.New("tx with wrong value") ErrTxWithWrongSender = errors.New("tx with wrong sender") ErrTxSenderNotRegistered = errors.New("tx sender not registered") ErrBindAddrIsContract = errors.New("bind address is contract") )
common errors
Functions ¶
func CalcSwappedValue ¶
CalcSwappedValue calc swapped value (get rid of fee)
func CheckSwapValue ¶
CheckSwapValue check swap value is in right range
func CmpAndSetLatestBlockHeight ¶
CmpAndSetLatestBlockHeight cmp and set latest block height
func GetBigValueThreshold ¶
GetBigValueThreshold get big value threshold
func GetStableConfirmations ¶
GetStableConfirmations get stable confirmations
func GetTokenPairsConfig ¶
func GetTokenPairsConfig() map[string]*TokenPairConfig
GetTokenPairsConfig get token pairs config
func IsTokenPairExist ¶
IsTokenPairExist is token pair exist
func LoadTokenPairsConfig ¶
func LoadTokenPairsConfig(check bool)
LoadTokenPairsConfig load token pairs config
func LoadTokenPairsConfigInDir ¶
func LoadTokenPairsConfigInDir(dir string, check bool) (map[string]*TokenPairConfig, error)
LoadTokenPairsConfigInDir load token pairs config
func SetLatestBlockHeight ¶
SetLatestBlockHeight set latest block height
func SetTokenPairsConfig ¶
func SetTokenPairsConfig(pairsConfig map[string]*TokenPairConfig, check bool)
SetTokenPairsConfig set token pairs config
func SetTokenPairsDir ¶
func SetTokenPairsDir(dir string)
SetTokenPairsDir set token pairs directory
func ShouldRegisterSwapForError ¶
ShouldRegisterSwapForError return true if this error should record in database
Types ¶
type AllExtras ¶
type AllExtras struct { BtcExtra *BtcExtraArgs `json:"btcExtra,omitempty"` EthExtra *EthExtraArgs `json:"ethExtra,omitempty"` }
AllExtras struct
type BlockExtraArgs ¶
type BlockExtraArgs struct { CoreAPIs []BlocknetCoreAPIArgs UTXOAPIAddresses []string }
BlockExtraArgs struct
type BlocknetCoreAPIArgs ¶
type BlocknetCoreAPIArgs struct { APIAddress string RPCUser string RPCPassword string DisableTLS bool }
BlocknetCoreAPIArgs struct
type BtcExtraArgs ¶
type BtcExtraArgs struct { RelayFeePerKb *int64 `json:"relayFeePerKb,omitempty"` ChangeAddress *string `json:"-"` PreviousOutPoints []*BtcOutPoint `json:"previousOutPoints,omitempty"` }
BtcExtraArgs struct
type BtcExtraConfig ¶
type BtcExtraConfig struct { MinRelayFee int64 MinRelayFeePerKb int64 MaxRelayFeePerKb int64 PlusFeePercentage uint64 EstimateFeeBlocks int UtxoAggregateMinCount int UtxoAggregateMinValue uint64 UtxoAggregateToAddress string }
BtcExtraConfig used to build swpout to btc tx
type BtcOutPoint ¶
BtcOutPoint struct
type BuildTxArgs ¶
type BuildTxArgs struct { SwapInfo `json:"swapInfo,omitempty"` From string `json:"from,omitempty"` To string `json:"to,omitempty"` Value *big.Int `json:"value,omitempty"` OriginValue *big.Int `json:"originValue,omitempty"` SwapValue *big.Int `json:"swapvalue,omitempty"` Memo string `json:"memo,omitempty"` Input *[]byte `json:"input,omitempty"` Extra *AllExtras `json:"extra,omitempty"` ReplaceNum uint64 `json:"replaceNum,omitempty"` }
BuildTxArgs struct
func (*BuildTxArgs) GetExtraArgs ¶
func (args *BuildTxArgs) GetExtraArgs() *BuildTxArgs
GetExtraArgs get extra args
func (*BuildTxArgs) GetTxGasPrice ¶
func (args *BuildTxArgs) GetTxGasPrice() *big.Int
GetTxGasPrice get tx gas price
func (*BuildTxArgs) GetTxNonce ¶
func (args *BuildTxArgs) GetTxNonce() uint64
GetTxNonce get tx nonce
func (*BuildTxArgs) SetTxNonce ¶
func (args *BuildTxArgs) SetTxNonce(nonce uint64)
SetTxNonce set tx nonce
type ChainConfig ¶
type ChainConfig struct { BlockChain string NetID string Confirmations *uint64 InitialHeight *uint64 EnableScan bool EnableScanPool bool CallByContractWhitelist []string `json:",omitempty"` MinReserveFee string BaseFeePercent int64 BaseGasPrice string `json:",omitempty"` MaxGasPriceFluctPercent uint64 `json:",omitempty"` ReplacePlusGasPricePercent uint64 `json:",omitempty"` WaitTimeToReplace int64 // seconds MaxReplaceCount int EnableReplaceSwap bool FixedGasPrice string `json:",omitempty"` MaxGasPrice string `json:",omitempty"` IsDynamicFeeTxEnabled bool PlusGasTipCapPercent uint64 PlusGasFeeCapPercent uint64 BlockCountFeeHistory int MaxGasTipCap string MaxGasFeeCap string // contains filtered or unexported fields }
ChainConfig struct
func (*ChainConfig) CheckConfig ¶
func (c *ChainConfig) CheckConfig(isServer bool) error
CheckConfig check chain config
func (*ChainConfig) GetFixedGasPrice ¶
func (c *ChainConfig) GetFixedGasPrice() *big.Int
GetFixedGasPrice get fixed gas price
func (*ChainConfig) GetMaxGasFeeCap ¶
func (c *ChainConfig) GetMaxGasFeeCap() *big.Int
GetMaxGasFeeCap get max fee gas cap
func (*ChainConfig) GetMaxGasPrice ¶
func (c *ChainConfig) GetMaxGasPrice() *big.Int
GetMaxGasPrice get max gas price
func (*ChainConfig) GetMaxGasTipCap ¶
func (c *ChainConfig) GetMaxGasTipCap() *big.Int
GetMaxGasTipCap get max gas tip cap
func (*ChainConfig) GetMinReserveFee ¶
func (c *ChainConfig) GetMinReserveFee() *big.Int
GetMinReserveFee get min reserve fee
func (*ChainConfig) IsInCallByContractWhitelist ¶
func (c *ChainConfig) IsInCallByContractWhitelist(caller string) bool
IsInCallByContractWhitelist is in call by contract whitelist
type CrossChainBridge ¶
type CrossChainBridge interface { IsSrcEndpoint() bool SetChainAndGateway(*ChainConfig, *GatewayConfig) GetChainConfig() *ChainConfig GetGatewayConfig() *GatewayConfig GetTokenConfig(pairID string) *TokenConfig VerifyTokenConfig(*TokenConfig) error IsValidAddress(address string) bool GetTransaction(txHash string) (interface{}, error) GetTransactionStatus(txHash string) (*TxStatus, error) VerifyTransaction(pairID, txHash string, allowUnstable bool) (*TxSwapInfo, error) VerifyMsgHash(rawTx interface{}, msgHash []string) error BuildRawTransaction(args *BuildTxArgs) (rawTx interface{}, err error) SignTransaction(rawTx interface{}, pairID string) (signedTx interface{}, txHash string, err error) DcrmSignTransaction(rawTx interface{}, args *BuildTxArgs) (signedTx interface{}, txHash string, err error) SendTransaction(signedTx interface{}) (txHash string, err error) GetLatestBlockNumber() (uint64, error) GetLatestBlockNumberOf(apiAddress string) (uint64, error) GetBalance(accountAddress string) (*big.Int, error) GetTokenBalance(tokenType, tokenAddress, accountAddress string) (*big.Int, error) GetTokenSupply(tokenType, tokenAddress string) (*big.Int, error) }
CrossChainBridge interface
func GetCrossChainBridge ¶
func GetCrossChainBridge(isSrc bool) CrossChainBridge
GetCrossChainBridge get bridge of specified endpoint
type CrossChainBridgeBase ¶
type CrossChainBridgeBase struct { ChainConfig *ChainConfig GatewayConfig *GatewayConfig IsSrc bool }
CrossChainBridgeBase base bridge
func NewCrossChainBridgeBase ¶
func NewCrossChainBridgeBase(isSrc bool) *CrossChainBridgeBase
NewCrossChainBridgeBase new base bridge
func (*CrossChainBridgeBase) GetChainConfig ¶
func (b *CrossChainBridgeBase) GetChainConfig() *ChainConfig
GetChainConfig get chain config
func (*CrossChainBridgeBase) GetDcrmPublicKey ¶
func (b *CrossChainBridgeBase) GetDcrmPublicKey(pairID string) string
GetDcrmPublicKey get dcrm address's public key
func (*CrossChainBridgeBase) GetGatewayConfig ¶
func (b *CrossChainBridgeBase) GetGatewayConfig() *GatewayConfig
GetGatewayConfig get gateway config
func (*CrossChainBridgeBase) GetTokenConfig ¶
func (b *CrossChainBridgeBase) GetTokenConfig(pairID string) *TokenConfig
GetTokenConfig get token config
func (*CrossChainBridgeBase) IsSrcEndpoint ¶
func (b *CrossChainBridgeBase) IsSrcEndpoint() bool
IsSrcEndpoint returns if bridge is at the source endpoint
func (*CrossChainBridgeBase) SetChainAndGateway ¶
func (b *CrossChainBridgeBase) SetChainAndGateway(chainCfg *ChainConfig, gatewayCfg *GatewayConfig)
SetChainAndGateway set chain and gateway config
type EthExtraArgs ¶
type EthExtraArgs struct { Gas *uint64 `json:"gas,omitempty"` GasPrice *big.Int `json:"gasPrice,omitempty"` GasTipCap *big.Int `json:"gasTipCap,omitempty"` GasFeeCap *big.Int `json:"gasFeeCap,omitempty"` Nonce *uint64 `json:"nonce,omitempty"` }
EthExtraArgs struct
type ForkChecker ¶
type ForkChecker interface {
GetBlockHashOf(urls []string, height uint64) (hash string, err error)
}
ForkChecker fork checker interface
func GetForkChecker ¶
func GetForkChecker(isSrc bool) ForkChecker
GetForkChecker get fork checker of specified endpoint
type GatewayConfig ¶
type GatewayConfig struct { APIAddress []string APIAddressExt []string Extras *GatewayExtras `json:",omitempty"` }
GatewayConfig struct
type NonceSetter ¶
type NonceSetter interface { GetTxBlockInfo(txHash string) (blockHeight, blockTime uint64) GetPoolNonce(address, height string) (uint64, error) SetNonce(pairID string, value uint64) AdjustNonce(pairID string, value uint64) (nonce uint64) InitNonces(nonces map[string]uint64) }
NonceSetter interface (for eth-like)
func GetNonceSetter ¶
func GetNonceSetter(isSrc bool) NonceSetter
GetNonceSetter get nonce setter of specified endpoint
type P2shAddressInfo ¶
type P2shAddressInfo struct { BindAddress string P2shAddress string RedeemScript string RedeemScriptDisasm string }
P2shAddressInfo struct
type SwapInfo ¶
type SwapInfo struct { PairID string `json:"pairid,omitempty"` SwapID string `json:"swapid,omitempty"` SwapType SwapType `json:"swaptype,omitempty"` TxType SwapTxType `json:"txtype,omitempty"` Bind string `json:"bind,omitempty"` Identifier string `json:"identifier,omitempty"` Reswapping bool `json:"reswapping,omitempty"` }
SwapInfo struct
type SwapTxType ¶
type SwapTxType uint32
SwapTxType type
const ( SwapinTx SwapTxType = iota // 0 SwapoutTx // 1 P2shSwapinTx // 2 )
SwapTxType constants
func (SwapTxType) String ¶
func (s SwapTxType) String() string
type TokenConfig ¶
type TokenConfig struct { ID string `json:",omitempty"` Name string Symbol string Decimals *uint8 Description string `json:",omitempty"` DepositAddress string `json:",omitempty"` DcrmAddress string DcrmPubkey string `json:"-"` ContractAddress string `json:",omitempty"` ContractCodeHash string `json:",omitempty"` MaximumSwap *float64 // whole unit (eg. BTC, ETH, FSN), not Satoshi MinimumSwap *float64 // whole unit BigValueThreshold *float64 SwapFeeRate *float64 MaximumSwapFee *float64 MinimumSwapFee *float64 PlusGasPricePercentage uint64 `json:",omitempty"` DisableSwap bool IsDelegateContract bool DelegateToken string `json:",omitempty"` IsacentswapAdapter bool `json:",omitempty"` // PRQ IsMappingTokenProxy bool `json:",omitempty"` // VTX DefaultGasLimit uint64 `json:",omitempty"` AllowSwapinFromContract bool `json:",omitempty"` AllowSwapoutFromContract bool `json:",omitempty"` // use private key address instead DcrmAddressKeyStore string `json:"-"` DcrmAddressPassword string `json:"-"` DcrmAddressKeyFile string `json:"-"` // contains filtered or unexported fields }
TokenConfig struct
func FindTokenConfig ¶
func FindTokenConfig(address string, isSrc bool) (configs []*TokenConfig, pairIDs []string)
FindTokenConfig find by (tx to) address
func GetTokenConfig ¶
func GetTokenConfig(pairID string, isSrc bool) *TokenConfig
GetTokenConfig get token config
func GetTokenConfigsByDirection ¶
func GetTokenConfigsByDirection(pairID string, isSwapin bool) (fromTokenConfig, toTokenConfig *TokenConfig)
GetTokenConfigsByDirection get token configs by direction
func (*TokenConfig) CalcAndStoreValue ¶
func (c *TokenConfig) CalcAndStoreValue()
CalcAndStoreValue calc and store value (minus duplicate calculation)
func (*TokenConfig) CheckConfig ¶
func (c *TokenConfig) CheckConfig(isSrc bool) error
CheckConfig check token config
func (*TokenConfig) GetDcrmAddressPrivateKey ¶
func (c *TokenConfig) GetDcrmAddressPrivateKey() *ecdsa.PrivateKey
GetDcrmAddressPrivateKey get private key
func (*TokenConfig) IsProxyErc20 ¶
func (c *TokenConfig) IsProxyErc20() bool
IsProxyErc20 return if token is proxy contract of erc20
func (*TokenConfig) LoadDcrmAddressPrivateKey ¶
func (c *TokenConfig) LoadDcrmAddressPrivateKey() error
LoadDcrmAddressPrivateKey load private key
func (*TokenConfig) VerifyDcrmPublicKey ¶
func (c *TokenConfig) VerifyDcrmPublicKey() error
VerifyDcrmPublicKey verify public key
type TokenPairConfig ¶
type TokenPairConfig struct { PairID string SrcToken *TokenConfig DestToken *TokenConfig }
TokenPairConfig pair config
func AddPairConfig ¶
func AddPairConfig(configFile string) (pairConfig *TokenPairConfig, err error)
AddPairConfig add pair config dynamically
func GetTokenPairConfig ¶
func GetTokenPairConfig(pairID string) *TokenPairConfig
GetTokenPairConfig get token pair config
func (*TokenPairConfig) CheckConfig ¶
func (c *TokenPairConfig) CheckConfig() (err error)
CheckConfig check token pair config
type TxStatus ¶
type TxStatus struct { Receipt interface{} `json:"receipt,omitempty"` Confirmations uint64 `json:"confirmations"` BlockHeight uint64 `json:"block_height"` BlockHash string `json:"block_hash"` BlockTime uint64 `json:"block_time"` }
TxStatus struct
func (*TxStatus) IsSwapTxOnChainAndFailed ¶
func (s *TxStatus) IsSwapTxOnChainAndFailed(token *TokenConfig) bool
IsSwapTxOnChainAndFailed to make failed of swaptx
type TxSwapInfo ¶
type TxSwapInfo struct { PairID string `json:"pairid"` Hash string `json:"hash"` Height uint64 `json:"height"` Timestamp uint64 `json:"timestamp"` From string `json:"from"` TxTo string `json:"txto"` To string `json:"to"` Bind string `json:"bind"` Value *big.Int `json:"value"` }
TxSwapInfo struct
Directories ¶
Path | Synopsis |
---|---|
btc
|
|
electrs
Package electrs get or post RPC queries to electrs server.
|
Package electrs get or post RPC queries to electrs server. |
Package colx implements the bridge interfaces for colx blockchain.
|
Package colx implements the bridge interfaces for colx blockchain. |
colxdev
Package colxdev dev tools to output compressed public key.
|
Package colxdev dev tools to output compressed public key. |
Package fsn implements the bridge interfaces for fsn blockchain.
|
Package fsn implements the bridge interfaces for fsn blockchain. |
Package ltc implements the bridge interfaces for ltc blockchain.
|
Package ltc implements the bridge interfaces for ltc blockchain. |
Package okex implements the bridge interfaces for okex blockchain.
|
Package okex implements the bridge interfaces for okex blockchain. |
Package tools provides tools for scanning and registering swaps.
|
Package tools provides tools for scanning and registering swaps. |