Documentation ¶
Index ¶
- Constants
- Variables
- func CalcSwappedValue(value *big.Int, isSrc bool) *big.Int
- func CheckSwapValue(value *big.Int, isSrc bool) bool
- func FromBits(value *big.Int, decimals uint8) float64
- func SetLatestBlockHeight(latest uint64, isSrc bool)
- func ShouldRegisterSwapForError(err error) bool
- func ToBits(value float64, decimals uint8) *big.Int
- type AllExtras
- type BtcExtraArgs
- type BtcExtraConfig
- type BtcOutPoint
- type BuildTxArgs
- type CrossChainBridge
- type CrossChainBridgeBase
- type EthExtraArgs
- type GatewayConfig
- type P2shAddressInfo
- type SwapInfo
- type SwapTxType
- type SwapType
- type TokenConfig
- type TxStatus
- type TxSwapInfo
Constants ¶
const ( LockMemoPrefix = "SWAPTO:" UnlockMemoPrefix = "SWAPTX:" RecallMemoPrefix = "RECALL:" )
transaction memo prefix
Variables ¶
var ( SrcBridge CrossChainBridge DstBridge CrossChainBridge SrcLatestBlockHeight uint64 DstLatestBlockHeight uint64 )
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") ErrWrongRawTx = errors.New("wrong raw tx") ErrWrongExtraArgs = errors.New("wrong extra args") ErrWrongP2shSwapin = errors.New("wrong p2sh swapin (only btc supports)") 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") 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") // errors should register ErrTxWithWrongMemo = errors.New("tx with wrong memo") ErrTxWithWrongValue = errors.New("tx with wrong value") ErrTxWithWrongReceipt = errors.New("tx with wrong receipt") ErrTxWithWrongSender = errors.New("tx with wrong sender") )
common errors
var ( BtcMinRelayFee int64 = 400 BtcRelayFeePerKb int64 = 2000 BtcFromPublicKey string BtcUtxoAggregateMinCount = 20 BtcUtxoAggregateMinValue = uint64(1000000) )
btc extra default values
Functions ¶
func CalcSwappedValue ¶
CalcSwappedValue calc swapped value (get rid of fee)
func CheckSwapValue ¶
CheckSwapValue check swap value is in right range
func SetLatestBlockHeight ¶
SetLatestBlockHeight set latest block height
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 BtcExtraArgs ¶
type BtcExtraArgs struct { RelayFeePerKb *int64 `json:"relayFeePerKb,omitempty"` ChangeAddress *string `json:"changeAddress,omitempty"` FromPublicKey *string `json:"fromPublickey,omitempty"` PreviousOutPoints []*BtcOutPoint `json:"previousOutPoints,omitempty"` }
BtcExtraArgs struct
type BtcExtraConfig ¶
type BtcExtraConfig struct { MinRelayFee int64 RelayFeePerKb int64 FromPublicKey string UtxoAggregateMinCount int UtxoAggregateMinValue uint64 }
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"` Memo string `json:"memo,omitempty"` Input *[]byte `json:"input,omitempty"` Extra *AllExtras `json:"extra,omitempty"` }
BuildTxArgs struct
func (*BuildTxArgs) GetExtraArgs ¶
func (args *BuildTxArgs) GetExtraArgs() *BuildTxArgs
GetExtraArgs get extra args
type CrossChainBridge ¶
type CrossChainBridge interface { IsSrcEndpoint() bool GetTokenAndGateway() (*TokenConfig, *GatewayConfig) SetTokenAndGateway(*TokenConfig, *GatewayConfig) IsValidAddress(address string) bool GetTransaction(txHash string) (interface{}, error) GetTransactionStatus(txHash string) *TxStatus VerifyTransaction(txHash string, allowUnstable bool) (*TxSwapInfo, error) VerifyMsgHash(rawTx interface{}, msgHash []string, extra interface{}) error BuildRawTransaction(args *BuildTxArgs) (rawTx interface{}, err error) DcrmSignTransaction(rawTx interface{}, args *BuildTxArgs) (signedTx interface{}, txHash string, err error) SendTransaction(signedTx interface{}) (txHash string, err error) GetLatestBlockNumber() (uint64, error) StartPoolTransactionScanJob() StartChainTransactionScanJob() StartSwapHistoryScanJob() }
CrossChainBridge interface
func GetCrossChainBridge ¶
func GetCrossChainBridge(isSrc bool) CrossChainBridge
GetCrossChainBridge get bridge of specified endpoint
type CrossChainBridgeBase ¶
type CrossChainBridgeBase struct { TokenConfig *TokenConfig GatewayConfig *GatewayConfig IsSrc bool }
CrossChainBridgeBase base bridge
func NewCrossChainBridgeBase ¶
func NewCrossChainBridgeBase(isSrc bool) *CrossChainBridgeBase
NewCrossChainBridgeBase new base bridge
func (*CrossChainBridgeBase) GetTokenAndGateway ¶
func (b *CrossChainBridgeBase) GetTokenAndGateway() (*TokenConfig, *GatewayConfig)
GetTokenAndGateway get token and gateway config
func (*CrossChainBridgeBase) IsSrcEndpoint ¶
func (b *CrossChainBridgeBase) IsSrcEndpoint() bool
IsSrcEndpoint returns if bridge is at the source endpoint
func (*CrossChainBridgeBase) SetTokenAndGateway ¶
func (b *CrossChainBridgeBase) SetTokenAndGateway(tokenCfg *TokenConfig, gatewayCfg *GatewayConfig)
SetTokenAndGateway set token and gateway config
type EthExtraArgs ¶
type EthExtraArgs struct { Gas *uint64 `json:"gas,omitempty"` GasPrice *big.Int `json:"gasPrice,omitempty"` Nonce *uint64 `json:"nonce,omitempty"` }
EthExtraArgs struct
type P2shAddressInfo ¶
type P2shAddressInfo struct { BindAddress string P2shAddress string RedeemScript string RedeemScriptDisasm string }
P2shAddressInfo struct
type SwapInfo ¶
type SwapInfo struct { 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"` }
SwapInfo struct
type SwapTxType ¶
type SwapTxType uint32
SwapTxType type
const ( SwapinTx SwapTxType = iota // 0 SwapoutTx // 1 P2shSwapinTx // 2 )
SwapTxType constants
type TokenConfig ¶
type TokenConfig struct { BlockChain string NetID string ID string `json:",omitempty"` Name string Symbol string Decimals *uint8 Description string `json:",omitempty"` DcrmAddress string ContractAddress string `json:",omitempty"` Confirmations *uint64 MaximumSwap *float64 // whole unit (eg. BTC, ETH, FSN), not Satoshi MinimumSwap *float64 // whole unit SwapFeeRate *float64 InitialHeight uint64 }
TokenConfig struct
func GetTokenConfig ¶
func GetTokenConfig(isSrc bool) *TokenConfig
GetTokenConfig get token config of specified endpoint
func (*TokenConfig) CheckConfig ¶
func (c *TokenConfig) CheckConfig(isSrc bool) error
CheckConfig check config