Documentation ¶
Index ¶
- Constants
- Variables
- type B2ExplorerStatus
- type Bridge
- func (b *Bridge) ABIPack(abiData string, method string, args ...interface{}) ([]byte, error)
- func (b *Bridge) BitcoinAddressToEthAddress(bitcoinAddress b2types.BitcoinFrom) (string, error)
- func (b *Bridge) Deposit(hash string, bitcoinAddress b2types.BitcoinFrom, amount int64, ...) (*types.Transaction, []byte, string, string, error)
- func (b *Bridge) EnableEoaTransfer() bool
- func (b *Bridge) FromAddress() string
- func (b *Bridge) TransactionByHash(hash string) (*types.Transaction, bool, error)
- func (b *Bridge) TransactionReceipt(hash string) (*types.Receipt, error)
- func (b *Bridge) Transfer(bitcoinAddress b2types.BitcoinFrom, amount int64, oldTx *types.Transaction, ...) (*types.Transaction, string, error)
- func (b *Bridge) WaitMined(ctx context.Context, tx *types.Transaction, _ []byte) (*types.Receipt, error)
- type BridgeDepositService
- func (bis *BridgeDepositService) CheckDeposit()
- func (bis *BridgeDepositService) Deposit()
- func (bis *BridgeDepositService) EoaTransfer(deposit model.Deposit, oldTx *ethTypes.Transaction, nonce uint64, ...) error
- func (bis *BridgeDepositService) HandleDeposit(deposit model.Deposit, oldTx *ethTypes.Transaction, nonce uint64, ...) error
- func (bis *BridgeDepositService) HandleEoaTransfer() error
- func (bis *BridgeDepositService) HandleUnconfirmedDeposit(deposit model.Deposit) error
- func (bis *BridgeDepositService) HandleUnconfirmedEoa(deposit model.Deposit) error
- func (bis *BridgeDepositService) OnStart() error
- func (bis *BridgeDepositService) OnStop()
- func (bis *BridgeDepositService) UnconfirmedDeposit() error
- func (bis *BridgeDepositService) UnconfirmedEoa() error
- func (bis *BridgeDepositService) WaitMined(ctx1 context.Context, b2Tx *ethTypes.Transaction, deposit model.Deposit) error
- type BridgeWithdrawService
- type DepositData
- type EpsResponse
- type EpsService
- type EthRequest
- type EthResponse
- type EthTransactionResponse
- type Indexer
- func (b *Indexer) BlockChainInfo() (*btcjson.GetBlockChainInfoResult, error)
- func (b *Indexer) CheckConfirmations(hash string) error
- func (b *Indexer) LatestBlock() (int64, error)
- func (b *Indexer) ParseAddress(pkScript []byte) (string, error)
- func (b *Indexer) ParseBlock(height int64, txIndex int64) ([]*types.BitcoinTxParseResult, *wire.BlockHeader, error)
- type IndexerService
- func (bis *IndexerService) HandleResults(txResults []*types.BitcoinTxParseResult, btcIndex model.BtcIndex, ...) (int64, int64, error)
- func (bis *IndexerService) OnStart() error
- func (bis *IndexerService) SaveParsedResult(parseResult *types.BitcoinTxParseResult, btcBlockNumber int64, b2TxStatus int, ...) error
- func (bis *IndexerService) ToInFroms(a []types.BitcoinFrom, s string) bool
- type TransferService
- func (bis *TransferService) GetFeeRate() (*model.FeeRates, error)
- func (bis *TransferService) GetMempoolURL() string
- func (bis *TransferService) HandleTransfer()
- func (bis *TransferService) IsBTCLiveNetAddress(address string) bool
- func (bis *TransferService) IsBTCTestNetAddress(address string) bool
- func (bis *TransferService) OnStart() error
- func (bis *TransferService) OnStop()
- func (bis *TransferService) QueryTransactionsByRequestIDs(requestID string) (bool, error)
- func (bis *TransferService) Transfer(requestID string, to string, amount string) (*common.CreateSettlementTxResData, string, error)
Constants ¶
const ( BridgeDepositServiceName = "BitcoinBridgeDepositService" BatchDepositWaitTimeout = 10 * time.Second DepositErrTimeout = 20 * time.Second BatchDepositLimit = 100 WaitMinedTimeout = 20 * time.Minute HandleDepositTimeout = 1 * time.Second DepositRetry = 10 // temp fix, Increase retry times )
const ( BridgeWithdrawServiceName = "BitcoinBridgeWithdrawService" WithdrawHandleTime = 10 WithdrawTXConfirmTime = 60 * 5 )
const ( // tx type TxTypeTransfer = "transfer" // btc transfer TxTypeWithdraw = "withdraw" // btc withdraw )
const ( ServiceName = "BitcoinIndexerService" NewBlockWaitTimeout = 60 * time.Second IndexTxTimeout = 100 * time.Millisecond IndexBlockTimeout = 2 * time.Second )
const ( TransferServiceName = "BitcoinBridgeTransferService" BatchTransferWaitTimeout = 60 * time.Second )
Variables ¶
var ( ErrBridgeDepositTxHashExist = errors.New("non-repeatable processing") ErrBridgeDepositContractInsufficientBalance = errors.New("insufficient balance") ErrBridgeWaitMinedStatus = errors.New("tx wait mined status failed") ErrBridgeFromGasInsufficient = errors.New("gas required exceeds allowanc") ErrAAAddressNotFound = errors.New("address not found") ErrOldNonceToHeight = errors.New("old nonce params to height") ErrBridgeBtcAddressWhiteList = errors.New("whitelist btc address") )
var ( ErrParsePkScript = errors.New("parse pkscript err") ErrDecodeListenAddress = errors.New("decode listen address err") ErrTargetConfirmations = errors.New("target confirmation number was not reached") ErrParsePubKey = errors.New("parse pubkey failed, not found pubkey or nonsupport ") ErrParsePkScriptNullData = errors.New("parse pkscript null data err") ErrParsePkScriptNotNullData = errors.New("parse pkscript not null data err") )
var ErrServerStop = errors.New("server stop")
Functions ¶
This section is empty.
Types ¶
type B2ExplorerStatus ¶
type Bridge ¶
type Bridge struct { EthRPCURL string EthPrivKey *ecdsa.PrivateKey ContractAddress common.Address ABI string BaseGasPriceMultiple int64 B2ExplorerURL string // aa server AAPubKeyAPI string // whitelist not bridge BtcAddressWhiteList []string // contains filtered or unexported fields }
Bridge bridge TODO: only L1 -> L2, More calls may be supported later
func NewBridge ¶
func NewBridge(bridgeCfg config.BridgeConfig, abiFileDir string, log log.Logger, bitcoinParam *chaincfg.Params) (*Bridge, error)
NewBridge new bridge
func (*Bridge) BitcoinAddressToEthAddress ¶
func (b *Bridge) BitcoinAddressToEthAddress(bitcoinAddress b2types.BitcoinFrom) (string, error)
BitcoinAddressToEthAddress bitcoin address to eth address if OP_RETURN existed, use OP_RETURN EVM address
func (*Bridge) Deposit ¶
func (b *Bridge) Deposit( hash string, bitcoinAddress b2types.BitcoinFrom, amount int64, oldTx *types.Transaction, nonce uint64, resetNonce bool, ) (*types.Transaction, []byte, string, string, error)
Deposit to ethereum
func (*Bridge) EnableEoaTransfer ¶
func (*Bridge) FromAddress ¶
func (*Bridge) TransactionByHash ¶
func (*Bridge) TransactionReceipt ¶
func (*Bridge) Transfer ¶
func (b *Bridge) Transfer(bitcoinAddress b2types.BitcoinFrom, amount int64, oldTx *types.Transaction, nonce uint64, resetNonce bool, ) (*types.Transaction, string, error)
Transfer to ethereum TODO: temp handle, future remove
type BridgeDepositService ¶
type BridgeDepositService struct { service.BaseService // contains filtered or unexported fields }
BridgeDepositService l1->l2
func NewBridgeDepositService ¶
func NewBridgeDepositService( bridge types.BITCOINBridge, btcIndexer types.BITCOINTxIndexer, db *gorm.DB, logger log.Logger, ) *BridgeDepositService
NewBridgeDepositService returns a new service instance.
func (*BridgeDepositService) CheckDeposit ¶
func (bis *BridgeDepositService) CheckDeposit()
func (*BridgeDepositService) Deposit ¶
func (bis *BridgeDepositService) Deposit()
func (*BridgeDepositService) EoaTransfer ¶
func (bis *BridgeDepositService) EoaTransfer(deposit model.Deposit, oldTx *ethTypes.Transaction, nonce uint64, resetNonce bool) error
func (*BridgeDepositService) HandleDeposit ¶
func (bis *BridgeDepositService) HandleDeposit(deposit model.Deposit, oldTx *ethTypes.Transaction, nonce uint64, resetNonce bool) error
func (*BridgeDepositService) HandleEoaTransfer ¶
func (bis *BridgeDepositService) HandleEoaTransfer() error
func (*BridgeDepositService) HandleUnconfirmedDeposit ¶
func (bis *BridgeDepositService) HandleUnconfirmedDeposit(deposit model.Deposit) error
HandleUnconfirmedDeposit 1. tx mined, update status 2. tx not mined, isPending, need reset gasprice 3. tx not mined, tx not mempool, need retry send tx
func (*BridgeDepositService) HandleUnconfirmedEoa ¶
func (bis *BridgeDepositService) HandleUnconfirmedEoa(deposit model.Deposit) error
HandleUnconfirmedEoa
func (*BridgeDepositService) OnStop ¶
func (bis *BridgeDepositService) OnStop()
func (*BridgeDepositService) UnconfirmedDeposit ¶
func (bis *BridgeDepositService) UnconfirmedDeposit() error
func (*BridgeDepositService) UnconfirmedEoa ¶
func (bis *BridgeDepositService) UnconfirmedEoa() error
func (*BridgeDepositService) WaitMined ¶
func (bis *BridgeDepositService) WaitMined(ctx1 context.Context, b2Tx *ethTypes.Transaction, deposit model.Deposit) error
type BridgeWithdrawService ¶
type BridgeWithdrawService struct { service.BaseService // contains filtered or unexported fields }
BridgeWithdrawService indexes transactions for json-rpc service.
func NewBridgeWithdrawService ¶
func NewBridgeWithdrawService( btcCli *rpcclient.Client, ethCli *ethclient.Client, config *config.BitcoinConfig, db *gorm.DB, auditDB *gorm.DB, log log.Logger, ) *BridgeWithdrawService
NewBridgeWithdrawService returns a new service instance.
func (*BridgeWithdrawService) HandleWithdraw ¶ added in v1.1.0
func (bis *BridgeWithdrawService) HandleWithdraw()
OnStart implements service.Service
func (*BridgeWithdrawService) OnStart ¶
func (bis *BridgeWithdrawService) OnStart() error
OnStart implements service.Service
func (*BridgeWithdrawService) OnStop ¶ added in v1.1.0
func (bis *BridgeWithdrawService) OnStop()
type DepositData ¶
type EpsResponse ¶
type EpsService ¶
type EpsService struct { EthRPCURL string // contains filtered or unexported fields }
EpsService eps service
func NewEpsService ¶
func NewEpsService( bridgeCfg config.BridgeConfig, config config.EpsConfig, log log.Logger, db *gorm.DB, ) (*EpsService, error)
NewEpsService new eps
func (*EpsService) Deposit ¶
func (e *EpsService) Deposit(data DepositData) error
func (*EpsService) GetTransactionByHash ¶
func (e *EpsService) GetTransactionByHash(txHash string) (*EthTransactionResponse, error)
func (*EpsService) OnStart ¶
func (e *EpsService) OnStart() error
type EthRequest ¶
type EthResponse ¶
type EthResponse struct { Jsonrpc string `json:"jsonrpc"` ID int `json:"id"` Result EthTransactionResponse `json:"result"` }
type EthTransactionResponse ¶
type Indexer ¶
type Indexer struct {
// contains filtered or unexported fields
}
Indexer bitcoin indexer, parse and forward data
func NewBitcoinIndexer ¶
func NewBitcoinIndexer( log log.Logger, client *rpcclient.Client, chainParams *chaincfg.Params, listenAddress string, targetConfirmations uint64, ) (*Indexer, error)
NewBitcoinIndexer new bitcoin indexer
func (*Indexer) BlockChainInfo ¶
func (b *Indexer) BlockChainInfo() (*btcjson.GetBlockChainInfoResult, error)
BlockChainInfo get block chain info
func (*Indexer) CheckConfirmations ¶
func (*Indexer) LatestBlock ¶
LatestBlock get latest block height in the longest block chain.
func (*Indexer) ParseAddress ¶
parseAddress from pkscript parse address
func (*Indexer) ParseBlock ¶
func (b *Indexer) ParseBlock(height int64, txIndex int64) ([]*types.BitcoinTxParseResult, *wire.BlockHeader, error)
ParseBlock parse block data by block height NOTE: Currently, only transfer transactions are supported.
type IndexerService ¶
type IndexerService struct { service.BaseService // contains filtered or unexported fields }
IndexerService indexes transactions for json-rpc service.
func NewIndexerService ¶
func NewIndexerService( txIdxr types.BITCOINTxIndexer, db *gorm.DB, logger log.Logger, ) *IndexerService
NewIndexerService returns a new service instance.
func (*IndexerService) HandleResults ¶
func (*IndexerService) SaveParsedResult ¶
func (bis *IndexerService) SaveParsedResult( parseResult *types.BitcoinTxParseResult, btcBlockNumber int64, b2TxStatus int, btcBlockTime time.Time, btcIndex model.BtcIndex, ) error
save index tx to db
func (*IndexerService) ToInFroms ¶
func (bis *IndexerService) ToInFroms(a []types.BitcoinFrom, s string) bool
type TransferService ¶ added in v1.1.0
type TransferService struct { service.BaseService // contains filtered or unexported fields }
TransferService for btc transfer
func NewTransferService ¶ added in v1.1.0
func NewTransferService( cfg *config.TransferConfig, db *gorm.DB, log log.Logger, sinohopeAPI features.TransactionAPI, ) *TransferService
NewTransferService returns a new service instance.
func (*TransferService) GetFeeRate ¶ added in v1.1.0
func (bis *TransferService) GetFeeRate() (*model.FeeRates, error)
func (*TransferService) GetMempoolURL ¶ added in v1.1.0
func (bis *TransferService) GetMempoolURL() string
func (*TransferService) HandleTransfer ¶ added in v1.1.0
func (bis *TransferService) HandleTransfer()
func (*TransferService) IsBTCLiveNetAddress ¶ added in v1.1.0
func (bis *TransferService) IsBTCLiveNetAddress(address string) bool
func (*TransferService) IsBTCTestNetAddress ¶ added in v1.1.0
func (bis *TransferService) IsBTCTestNetAddress(address string) bool
func (*TransferService) OnStart ¶ added in v1.1.0
func (bis *TransferService) OnStart() error
OnStart implements service.Service
func (*TransferService) OnStop ¶ added in v1.1.0
func (bis *TransferService) OnStop()
func (*TransferService) QueryTransactionsByRequestIDs ¶ added in v1.1.0
func (bis *TransferService) QueryTransactionsByRequestIDs(requestID string) (bool, error)
func (*TransferService) Transfer ¶ added in v1.1.0
func (bis *TransferService) Transfer(requestID string, to string, amount string) (*common.CreateSettlementTxResData, string, error)