multi: move GetChanPointFundingTxid from lnd to lnrpc

This refactor-only change makes the GetChanPointFundingTxid helper
function available from sub-systems outside of the root lnd package.
This commit is contained in:
Elliott Jin
2021-02-13 00:05:33 -08:00
parent db76b970ac
commit ce2796257e
11 changed files with 82 additions and 89 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
"sort"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/lightningnetwork/lnd/lnwallet"
)
@@ -88,3 +89,26 @@ func ExtractMinConfs(minConfs int32, spendUnconfirmed bool) (int32, error) {
return minConfs, nil
}
}
// GetChanPointFundingTxid returns the given channel point's funding txid in
// raw bytes.
func GetChanPointFundingTxid(chanPoint *ChannelPoint) (*chainhash.Hash, error) {
var txid []byte
// A channel point's funding txid can be get/set as a byte slice or a
// string. In the case it is a string, decode it.
switch chanPoint.GetFundingTxid().(type) {
case *ChannelPoint_FundingTxidBytes:
txid = chanPoint.GetFundingTxidBytes()
case *ChannelPoint_FundingTxidStr:
s := chanPoint.GetFundingTxidStr()
h, err := chainhash.NewHashFromStr(s)
if err != nil {
return nil, err
}
txid = h[:]
}
return chainhash.NewHash(txid)
}