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
- func (bis *BridgeWithdrawService) BroadcastTx(tx *wire.MsgTx) (*chainhash.Hash, error)
- func (bis *BridgeWithdrawService) ConstructTx(destAddressList []string, amounts []int64, b2TxHashes []byte) (string, string, error)
- func (bis *BridgeWithdrawService) GetFeeRate() (*model.FeeRates, error)
- func (bis *BridgeWithdrawService) GetMempoolURL() string
- func (bis *BridgeWithdrawService) GetMultiSigScript(pubs []string, minSignNum int) ([]byte, error)
- func (bis *BridgeWithdrawService) GetMultiSigWitnessSize() int
- func (bis *BridgeWithdrawService) GetUisatURL() string
- func (bis *BridgeWithdrawService) GetUnspentList(address string, cursor int64) (int64, int64, []*model.UnspentOutput, error)
- func (bis *BridgeWithdrawService) OnStart() error
- 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
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 // P2SHSize 23 bytes. P2SHSize = 23 // P2SHOutputSize 32 bytes // - value: 8 bytes // - var_int: 1 byte (pkscript_length) // - pkscript (p2sh): 23 bytes P2SHOutputSize = 8 + 1 + P2SHSize // InputSize 41 bytes // - PreviousOutPoint: // - Hash: 32 bytes // - Index: 4 bytes // - OP_DATA: 1 byte (ScriptSigLength) // - ScriptSig: 0 bytes // - Witness <---- we use "Witness" instead of "ScriptSig" for // transaction validation, but "Witness" is stored // separately and weight for it size is smaller. So // we separate the calculation of ordinary data // from witness data. // - Sequence: 4 bytes InputSize = 32 + 4 + 1 + 4 // MultiSigSize 71 bytes // - OP_2: 1 byte // - OP_DATA: 1 byte (pubKeyAlice length) // - pubKeyAlice: 33 bytes // - OP_DATA: 1 byte (pubKeyBob length) // - pubKeyBob: 33 bytes // - OP_2: 1 byte // - OP_CHECKMULTISIG: 1 byte MultiSigSize = 1 + 1 + 33 + 1 + 33 + 1 + 1 )
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 )
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") )
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") )
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 // 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
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, log log.Logger, ) *BridgeWithdrawService
NewBridgeWithdrawService returns a new service instance.
func (*BridgeWithdrawService) BroadcastTx ¶
func (*BridgeWithdrawService) ConstructTx ¶
func (*BridgeWithdrawService) GetFeeRate ¶
func (bis *BridgeWithdrawService) GetFeeRate() (*model.FeeRates, error)
func (*BridgeWithdrawService) GetMempoolURL ¶
func (bis *BridgeWithdrawService) GetMempoolURL() string
func (*BridgeWithdrawService) GetMultiSigScript ¶
func (bis *BridgeWithdrawService) GetMultiSigScript(pubs []string, minSignNum int) ([]byte, error)
func (*BridgeWithdrawService) GetMultiSigWitnessSize ¶
func (bis *BridgeWithdrawService) GetMultiSigWitnessSize() int
func (*BridgeWithdrawService) GetUisatURL ¶
func (bis *BridgeWithdrawService) GetUisatURL() string
func (*BridgeWithdrawService) GetUnspentList ¶
func (bis *BridgeWithdrawService) GetUnspentList(address string, cursor int64) (int64, int64, []*model.UnspentOutput, error)
func (*BridgeWithdrawService) OnStart ¶
func (bis *BridgeWithdrawService) OnStart() error
OnStart implements service.Service by subscribing for new blocks and indexing them by events.
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