Skip to content

Commit

Permalink
export required methods
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Jan 28, 2024
1 parent 266f189 commit 47a5a61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
25 changes: 18 additions & 7 deletions libwallet/assets/btc/dex-wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (dl dexLogger) SubLogger(string) dex.Logger {
}

var _ dexbtc.CustomWallet = (*DEXWallet)(nil)
var _ dexbtc.BlockInfoReader = (*DEXWallet)(nil)

// NewDEXWallet returns a new *DEXWallet.
func NewDEXWallet(w *wallet.Wallet, acctNum int32, nc *chain.NeutrinoClient, isSyncing func() bool) *DEXWallet {
Expand Down Expand Up @@ -121,6 +122,7 @@ func (dw *DEXWallet) SendRawTransaction(tx *wire.MsgTx) (*chainhash.Hash, error)
}

// Part of dexbtc.TipRedemptionWallet interface.
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetBlock(blockHash chainhash.Hash) (*wire.MsgBlock, error) {
block, err := dw.cl.CS.GetBlock(blockHash)
if err != nil {
Expand All @@ -131,15 +133,22 @@ func (dw *DEXWallet) GetBlock(blockHash chainhash.Hash) (*wire.MsgBlock, error)
}

// Part of dexbtc.Wallet interface.
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
return dw.cl.CS.GetBlockHash(blockHeight)
}

// Part of dexbtc.TipRedemptionWallet interface.
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetBlockHeight(h *chainhash.Hash) (int32, error) {
return dw.cl.CS.GetBlockHeight(h)
}

// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
return dw.cl.CS.GetBlockHeader(blockHash)
}

// Part of dexbtc.Wallet interface.
func (dw *DEXWallet) GetBestBlockHash() (*chainhash.Hash, error) {
blk := dw.syncedTo()
Expand Down Expand Up @@ -171,9 +180,10 @@ func (dw *DEXWallet) MedianTime() (time.Time, error) {
return dexbtc.CalcMedianTime(dw.getChainStamp, &blk.Hash)
}

// getChainHeight is only for confirmations since it does not reflect the wallet
// GetChainHeight is only for confirmations since it does not reflect the wallet
// manager's sync height, just the chain service.
func (dw *DEXWallet) getChainHeight() (int32, error) {
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetChainHeight() (int32, error) {
blk, err := dw.cl.CS.BestBlock()
if err != nil {
return -1, err
Expand Down Expand Up @@ -525,7 +535,7 @@ func (dw *DEXWallet) confirmations(txHash *chainhash.Hash, vout uint32) (blockHa

if details.Block.Hash != (chainhash.Hash{}) {
blockHash = &details.Block.Hash
height, err := dw.getChainHeight()
height, err := dw.GetChainHeight()
if err != nil {
return nil, 0, false, err
}
Expand Down Expand Up @@ -556,7 +566,7 @@ func (dw *DEXWallet) WalletUnlock(pw []byte) error {
return dw.w.Unlock(pw, nil)
}

// GetBlockHeader gets the *blockHeader for the specified block hash. It also
// GetBlockHeader gets the *dexbtc.BlockHeader for the specified block hash. It also
// returns a bool value to indicate whether this block is a part of main chain.
// For orphaned blocks header.Confirmations is negative.
// Part of dexbtc.TipRedemptionWallet interface.
Expand Down Expand Up @@ -702,7 +712,7 @@ func (dw *DEXWallet) SearchBlockForRedemptions(ctx context.Context, reqs map[dex

discovered = make(map[dexbtc.OutPoint]*dexbtc.FindRedemptionResult, len(reqs))

matchFound, err := dw.matchPkScript(&blockHash, scripts)
matchFound, err := dw.MatchPkScript(&blockHash, scripts)
if err != nil {
log.Errorf("matchPkScript error: %v", err)
return
Expand Down Expand Up @@ -780,9 +790,10 @@ func hashTx(tx *wire.MsgTx) *chainhash.Hash {
return &h
}

// matchPkScript pulls the filter for the block and attempts to match the
// MatchPkScript pulls the filter for the block and attempts to match the
// supplied scripts.
func (dw *DEXWallet) matchPkScript(blockHash *chainhash.Hash, scripts [][]byte) (bool, error) {
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) MatchPkScript(blockHash *chainhash.Hash, scripts [][]byte) (bool, error) {
filter, err := dw.cl.CS.GetCFilter(*blockHash, wire.GCSFilterRegular)
if err != nil {
return false, fmt.Errorf("GetCFilter error: %w", err)
Expand Down
25 changes: 18 additions & 7 deletions libwallet/assets/ltc/dex-wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (dl dexLogger) SubLogger(string) dex.Logger {
}

var _ dexbtc.CustomWallet = (*DEXWallet)(nil)
var _ dexbtc.BlockInfoReader = (*DEXWallet)(nil)

// NewDEXWallet returns a new *DEXWallet.
func NewDEXWallet(w *wallet.Wallet, acctNum int32, nc *chain.NeutrinoClient, btcParams *chaincfg.Params, isSyncing func() bool) *DEXWallet {
Expand Down Expand Up @@ -147,6 +148,7 @@ func (dw *DEXWallet) SendRawTransaction(tx *wire.MsgTx) (*chainhash.Hash, error)
}

// Part of dexbtc.TipRedemptionWallet interface.
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetBlock(blockHash chainhash.Hash) (*wire.MsgBlock, error) {
block, err := dw.cl.GetBlock(blockHash)
if err != nil {
Expand All @@ -157,11 +159,13 @@ func (dw *DEXWallet) GetBlock(blockHash chainhash.Hash) (*wire.MsgBlock, error)
}

// Part of dexbtc.Wallet interface.
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
return dw.cl.GetBlockHash(blockHeight)
}

// Part of dexbtc.TipRedemptionWallet interface.
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetBlockHeight(h *chainhash.Hash) (int32, error) {
return dw.cl.GetBlockHeight(h)
}
Expand All @@ -172,6 +176,11 @@ func (dw *DEXWallet) GetBestBlockHash() (*chainhash.Hash, error) {
return &blk.Hash, nil
}

// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
return dw.cl.GetBlockHeader(blockHash)
}

// GetBestBlockHeight returns the height of the best block processed by the
// wallet, which indicates the height at which the compact filters have been
// retrieved and scanned for wallet addresses. This is may be less than
Expand Down Expand Up @@ -199,9 +208,10 @@ func (dw *DEXWallet) MedianTime() (time.Time, error) {
return dexbtc.CalcMedianTime(dw.getChainStamp, &blk.Hash)
}

// getChainHeight is only for confirmations since it does not reflect the wallet
// GetChainHeight is only for confirmations since it does not reflect the wallet
// manager's sync height, just the chain service.
func (dw *DEXWallet) getChainHeight() (int32, error) {
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) GetChainHeight() (int32, error) {
blk, err := dw.cl.BestBlock()
if err != nil {
return -1, err
Expand Down Expand Up @@ -595,7 +605,7 @@ func (dw *DEXWallet) confirmations(txHash *chainhash.Hash, vout uint32) (blockHa

if details.Block.Hash != (chainhash.Hash{}) {
blockHash = &details.Block.Hash
height, err := dw.getChainHeight()
height, err := dw.GetChainHeight()
if err != nil {
return nil, 0, false, err
}
Expand Down Expand Up @@ -626,7 +636,7 @@ func (dw *DEXWallet) WalletUnlock(pw []byte) error {
return dw.w.Unlock(pw, nil)
}

// GetBlockHeader gets the *blockHeader for the specified block hash. It also
// GetBlockHeader gets the *dexbtc.BlockHeader for the specified block hash. It also
// returns a bool value to indicate whether this block is a part of main chain.
// For orphaned blocks header.Confirmations is negative.
// Part of dexbtc.TipRedemptionWallet interface.
Expand Down Expand Up @@ -772,7 +782,7 @@ func (dw *DEXWallet) SearchBlockForRedemptions(ctx context.Context, reqs map[dex

discovered = make(map[dexbtc.OutPoint]*dexbtc.FindRedemptionResult, len(reqs))

matchFound, err := dw.matchPkScript(&blockHash, scripts)
matchFound, err := dw.MatchPkScript(&blockHash, scripts)
if err != nil {
log.Errorf("matchPkScript error: %v", err)
return
Expand Down Expand Up @@ -850,9 +860,10 @@ func hashTx(tx *wire.MsgTx) *chainhash.Hash {
return &h
}

// matchPkScript pulls the filter for the block and attempts to match the
// MatchPkScript pulls the filter for the block and attempts to match the
// supplied scripts.
func (dw *DEXWallet) matchPkScript(blockHash *chainhash.Hash, scripts [][]byte) (bool, error) {
// Part of dexbtc.BlockInfoReader interface.
func (dw *DEXWallet) MatchPkScript(blockHash *chainhash.Hash, scripts [][]byte) (bool, error) {
filter, err := dw.cl.GetCFilter(*blockHash, wire.GCSFilterRegular)
if err != nil {
return false, fmt.Errorf("GetCFilter error: %w", err)
Expand Down

0 comments on commit 47a5a61

Please sign in to comment.