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

@ -5,6 +5,7 @@ import (
"errors" "errors"
"sort" "sort"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
) )
@ -88,3 +89,26 @@ func ExtractMinConfs(minConfs int32, spendUnconfirmed bool) (int32, error) {
return minConfs, nil 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)
}

@ -9,7 +9,6 @@ import (
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/chainreg" "github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@ -341,7 +340,7 @@ func (c *interceptorTestContext) waitForChannels() {
// Wait for all nodes to have seen all channels. // Wait for all nodes to have seen all channels.
for _, chanPoint := range c.networkChans { for _, chanPoint := range c.networkChans {
for _, node := range c.nodes { for _, node := range c.nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
require.NoError(c.t.t, err, "unable to get txid") require.NoError(c.t.t, err, "unable to get txid")
point := wire.OutPoint{ point := wire.OutPoint{

@ -8,7 +8,6 @@ import (
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/chainreg" "github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@ -376,7 +375,7 @@ func (c *mppTestContext) waitForChannels() {
// Wait for all nodes to have seen all channels. // Wait for all nodes to have seen all channels.
for _, chanPoint := range c.networkChans { for _, chanPoint := range c.networkChans {
for _, node := range c.nodes { for _, node := range c.nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
c.t.Fatalf("unable to get txid: %v", err) c.t.Fatalf("unable to get txid: %v", err)
} }

@ -6,7 +6,6 @@ import (
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/chainreg" "github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@ -30,7 +29,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
) )
networkChans = append(networkChans, chanPointAlice) networkChans = append(networkChans, chanPointAlice)
aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -71,7 +70,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
}, },
) )
networkChans = append(networkChans, chanPointDave) networkChans = append(networkChans, chanPointDave)
daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -106,7 +105,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
) )
networkChans = append(networkChans, chanPointCarol) networkChans = append(networkChans, chanPointCarol)
carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -120,7 +119,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) {
nodeNames := []string{"Alice", "Bob", "Carol", "Dave"} nodeNames := []string{"Alice", "Bob", "Carol", "Dave"}
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for i, node := range nodes { for i, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }

@ -7,7 +7,6 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
@ -187,7 +186,7 @@ func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest,
expectedTxes = 2 expectedTxes = 2
} }
bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint)
require.NoError(t.t, err) require.NoError(t.t, err)
_, err = waitForNTxsInMempool( _, err = waitForNTxsInMempool(
net.Miner.Node, expectedTxes, minerMempoolTimeout, net.Miner.Node, expectedTxes, minerMempoolTimeout,

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
@ -132,7 +131,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest,
net.Miner.Node, expectedTxes, minerMempoolTimeout, net.Miner.Node, expectedTxes, minerMempoolTimeout,
) )
require.NoError(t.t, err) require.NoError(t.t, err)
bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint)
require.NoError(t.t, err) require.NoError(t.t, err)
carolFundingPoint := wire.OutPoint{ carolFundingPoint := wire.OutPoint{
Hash: *bobFundingTxid, Hash: *bobFundingTxid,

@ -7,7 +7,6 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@ -109,7 +108,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest,
expectedTxes = 2 expectedTxes = 2
} }
bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint)
require.NoError(t.t, err) require.NoError(t.t, err)
_, err = waitForNTxsInMempool( _, err = waitForNTxsInMempool(
net.Miner.Node, expectedTxes, minerMempoolTimeout, net.Miner.Node, expectedTxes, minerMempoolTimeout,

@ -5,7 +5,6 @@ import (
"time" "time"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
@ -122,7 +121,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest,
) )
require.NoError(t.t, err) require.NoError(t.t, err)
bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint)
require.NoError(t.t, err) require.NoError(t.t, err)
carolFundingPoint := wire.OutPoint{ carolFundingPoint := wire.OutPoint{

@ -4,7 +4,6 @@ import (
"context" "context"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
@ -160,7 +159,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest
net.Miner.Node, expectedTxes, minerMempoolTimeout, net.Miner.Node, expectedTxes, minerMempoolTimeout,
) )
require.NoError(t.t, err) require.NoError(t.t, err)
bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint)
require.NoError(t.t, err) require.NoError(t.t, err)
carolFundingPoint := wire.OutPoint{ carolFundingPoint := wire.OutPoint{
Hash: *bobFundingTxid, Hash: *bobFundingTxid,

@ -120,7 +120,7 @@ func getTestCaseSplitTranche() ([]*testCase, uint, uint) {
} }
func rpcPointToWirePoint(t *harnessTest, chanPoint *lnrpc.ChannelPoint) wire.OutPoint { func rpcPointToWirePoint(t *harnessTest, chanPoint *lnrpc.ChannelPoint) wire.OutPoint {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -179,7 +179,7 @@ func openChannelAndAssert(ctx context.Context, t *harnessTest,
if err != nil { if err != nil {
t.Fatalf("error while waiting for channel open: %v", err) t.Fatalf("error while waiting for channel open: %v", err)
} }
fundingTxID, err := lnd.GetChanPointFundingTxid(fundingChanPoint) fundingTxID, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -291,7 +291,7 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
fundingChanPoint *lnrpc.ChannelPoint, anchors bool, fundingChanPoint *lnrpc.ChannelPoint, anchors bool,
closeUpdates lnrpc.Lightning_CloseChannelClient) *chainhash.Hash { closeUpdates lnrpc.Lightning_CloseChannelClient) *chainhash.Hash {
txid, err := lnd.GetChanPointFundingTxid(fundingChanPoint) txid, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -387,7 +387,7 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
func waitForChannelPendingForceClose(ctx context.Context, func waitForChannelPendingForceClose(ctx context.Context,
node *lntest.HarnessNode, fundingChanPoint *lnrpc.ChannelPoint) error { node *lntest.HarnessNode, fundingChanPoint *lnrpc.ChannelPoint) error {
txid, err := lnd.GetChanPointFundingTxid(fundingChanPoint) txid, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint)
if err != nil { if err != nil {
return err return err
} }
@ -1722,7 +1722,7 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest)
// txStr returns the string representation of the channel's funding transaction. // txStr returns the string representation of the channel's funding transaction.
func txStr(chanPoint *lnrpc.ChannelPoint) string { func txStr(chanPoint *lnrpc.ChannelPoint) string {
fundingTxID, err := lnd.GetChanPointFundingTxid(chanPoint) fundingTxID, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
return "" return ""
} }
@ -3692,7 +3692,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
// Compute the outpoint of the channel, which we will use repeatedly to // Compute the outpoint of the channel, which we will use repeatedly to
// locate the pending channel information in the rpc responses. // locate the pending channel information in the rpc responses.
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -5534,7 +5534,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
) )
networkChans = append(networkChans, chanPointCarol) networkChans = append(networkChans, chanPointCarol)
carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -5547,7 +5547,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest,
nodes := []*lntest.HarnessNode{carol, dave} nodes := []*lntest.HarnessNode{carol, dave}
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for _, node := range nodes { for _, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -5870,7 +5870,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
) )
networkChans = append(networkChans, chanPointAlice) networkChans = append(networkChans, chanPointAlice)
aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -5905,7 +5905,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
}, },
) )
networkChans = append(networkChans, chanPointBob) networkChans = append(networkChans, chanPointBob)
bobChanTXID, err := lnd.GetChanPointFundingTxid(chanPointBob) bobChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointBob)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -5919,7 +5919,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) {
nodeNames := []string{"Alice", "Bob", "Carol"} nodeNames := []string{"Alice", "Bob", "Carol"}
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for i, node := range nodes { for i, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -6302,7 +6302,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
) )
networkChans = append(networkChans, chanPointAlice) networkChans = append(networkChans, chanPointAlice)
aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -6335,7 +6335,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
}, },
) )
networkChans = append(networkChans, chanPointDave) networkChans = append(networkChans, chanPointDave)
daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -6370,7 +6370,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
) )
networkChans = append(networkChans, chanPointCarol) networkChans = append(networkChans, chanPointCarol)
carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -6385,7 +6385,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
nodeNames := []string{"Alice", "Bob", "Carol", "Dave"} nodeNames := []string{"Alice", "Bob", "Carol", "Dave"}
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for i, node := range nodes { for i, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -6430,7 +6430,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
if err != nil { if err != nil {
t.Fatalf("error while waiting for channel open: %v", err) t.Fatalf("error while waiting for channel open: %v", err)
} }
fundingTxID, err := lnd.GetChanPointFundingTxid(chanPointPrivate) fundingTxID, err := lnrpc.GetChanPointFundingTxid(chanPointPrivate)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -6876,7 +6876,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
} }
// Retrieve Alice's funding outpoint. // Retrieve Alice's funding outpoint.
aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -6925,7 +6925,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
} }
// Retrieve Bob's funding outpoint. // Retrieve Bob's funding outpoint.
bobChanTXID, err := lnd.GetChanPointFundingTxid(chanPointBob) bobChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointBob)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -6980,7 +6980,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest)
} }
// Retrieve Carol's funding point. // Retrieve Carol's funding point.
carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -7651,7 +7651,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) {
t.Fatalf("error while waiting for channel open: %v", err) t.Fatalf("error while waiting for channel open: %v", err)
} }
fundingTxID, err := lnd.GetChanPointFundingTxid(fundingChanPoint) fundingTxID, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -10529,11 +10529,11 @@ out:
"expected %v, got %v", blockHeight+1, "expected %v, got %v", blockHeight+1,
closedChan.ClosedHeight) closedChan.ClosedHeight)
} }
chanPointTxid, err := lnd.GetChanPointFundingTxid(chanPoint) chanPointTxid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
closedChanTxid, err := lnd.GetChanPointFundingTxid( closedChanTxid, err := lnrpc.GetChanPointFundingTxid(
closedChan.ChanPoint, closedChan.ChanPoint,
) )
if err != nil { if err != nil {
@ -11339,7 +11339,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
) )
networkChans = append(networkChans, chanPointAlice) networkChans = append(networkChans, chanPointAlice)
aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -11379,7 +11379,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
}, },
) )
networkChans = append(networkChans, chanPointDave) networkChans = append(networkChans, chanPointDave)
daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -11416,7 +11416,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
) )
networkChans = append(networkChans, chanPointCarol) networkChans = append(networkChans, chanPointCarol)
carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -11430,7 +11430,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
nodeNames := []string{"Alice", "Bob", "Carol", "Dave"} nodeNames := []string{"Alice", "Bob", "Carol", "Dave"}
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for i, node := range nodes { for i, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -11659,7 +11659,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
) )
networkChans = append(networkChans, chanPointAlice) networkChans = append(networkChans, chanPointAlice)
aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -11699,7 +11699,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
}, },
) )
networkChans = append(networkChans, chanPointDave) networkChans = append(networkChans, chanPointDave)
daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -11736,7 +11736,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
) )
networkChans = append(networkChans, chanPointCarol) networkChans = append(networkChans, chanPointCarol)
carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -11750,7 +11750,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
nodeNames := []string{"Alice", "Bob", "Carol", "Dave"} nodeNames := []string{"Alice", "Bob", "Carol", "Dave"}
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for i, node := range nodes { for i, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -11980,7 +11980,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
) )
networkChans = append(networkChans, chanPointAlice) networkChans = append(networkChans, chanPointAlice)
aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -12021,7 +12021,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
) )
networkChans = append(networkChans, chanPointDave) networkChans = append(networkChans, chanPointDave)
daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -12058,7 +12058,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
) )
networkChans = append(networkChans, chanPointCarol) networkChans = append(networkChans, chanPointCarol)
carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -12072,7 +12072,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
nodeNames := []string{"Alice", "Bob", "Carol", "Dave"} nodeNames := []string{"Alice", "Bob", "Carol", "Dave"}
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for i, node := range nodes { for i, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -12313,7 +12313,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
) )
networkChans = append(networkChans, chanPointAlice) networkChans = append(networkChans, chanPointAlice)
aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -12353,7 +12353,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
}, },
) )
networkChans = append(networkChans, chanPointDave) networkChans = append(networkChans, chanPointDave)
daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -12388,7 +12388,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
) )
networkChans = append(networkChans, chanPointCarol) networkChans = append(networkChans, chanPointCarol)
carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -12402,7 +12402,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
nodeNames := []string{"Alice", "Bob", "Carol", "Dave"} nodeNames := []string{"Alice", "Bob", "Carol", "Dave"}
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for i, node := range nodes { for i, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -12643,7 +12643,7 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) {
nodeNames := []string{"Alice", "Bob", "Carol", "Dave"} nodeNames := []string{"Alice", "Bob", "Carol", "Dave"}
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for i, node := range nodes { for i, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -12904,7 +12904,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) {
} }
for _, chanPoint := range networkChans { for _, chanPoint := range networkChans {
for i, node := range nodes { for i, node := range nodes {
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }
@ -13345,7 +13345,7 @@ func testAbandonChannel(net *lntest.NetworkHarness, t *harnessTest) {
chanPoint := openChannelAndAssert( chanPoint := openChannelAndAssert(
ctxt, t, net, net.Alice, net.Bob, channelParam, ctxt, t, net, net.Alice, net.Bob, channelParam,
) )
txid, err := lnd.GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
t.Fatalf("unable to get txid: %v", err) t.Fatalf("unable to get txid: %v", err)
} }

@ -1737,7 +1737,7 @@ func newFundingShimAssembler(chanPointShim *lnrpc.ChanPointShim, initiator bool,
// First, we'll map the RPC's channel point to one we can actually use. // First, we'll map the RPC's channel point to one we can actually use.
index := chanPointShim.ChanPoint.OutputIndex index := chanPointShim.ChanPoint.OutputIndex
txid, err := GetChanPointFundingTxid(chanPointShim.ChanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPointShim.ChanPoint)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2086,7 +2086,7 @@ out:
update, ok := fundingUpdate.Update.(*lnrpc.OpenStatusUpdate_ChanOpen) update, ok := fundingUpdate.Update.(*lnrpc.OpenStatusUpdate_ChanOpen)
if ok { if ok {
chanPoint := update.ChanOpen.ChannelPoint chanPoint := update.ChanOpen.ChannelPoint
txid, err := GetChanPointFundingTxid(chanPoint) txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil { if err != nil {
return err return err
} }
@ -2154,29 +2154,6 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
} }
} }
// GetChanPointFundingTxid returns the given channel point's funding txid in
// raw bytes.
func GetChanPointFundingTxid(chanPoint *lnrpc.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 *lnrpc.ChannelPoint_FundingTxidBytes:
txid = chanPoint.GetFundingTxidBytes()
case *lnrpc.ChannelPoint_FundingTxidStr:
s := chanPoint.GetFundingTxidStr()
h, err := chainhash.NewHashFromStr(s)
if err != nil {
return nil, err
}
txid = h[:]
}
return chainhash.NewHash(txid)
}
// CloseChannel attempts to close an active channel identified by its channel // CloseChannel attempts to close an active channel identified by its channel
// point. The actions of this method can additionally be augmented to attempt // point. The actions of this method can additionally be augmented to attempt
// a force close after a timeout period in the case of an inactive peer. // a force close after a timeout period in the case of an inactive peer.
@ -2201,7 +2178,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
force := in.Force force := in.Force
index := in.ChannelPoint.OutputIndex index := in.ChannelPoint.OutputIndex
txid, err := GetChanPointFundingTxid(in.GetChannelPoint()) txid, err := lnrpc.GetChanPointFundingTxid(in.GetChannelPoint())
if err != nil { if err != nil {
rpcsLog.Errorf("[closechannel] unable to get funding txid: %v", err) rpcsLog.Errorf("[closechannel] unable to get funding txid: %v", err)
return err return err
@ -2484,7 +2461,7 @@ func (r *rpcServer) AbandonChannel(_ context.Context,
// We'll parse out the arguments to we can obtain the chanPoint of the // We'll parse out the arguments to we can obtain the chanPoint of the
// target channel. // target channel.
txid, err := GetChanPointFundingTxid(in.GetChannelPoint()) txid, err := lnrpc.GetChanPointFundingTxid(in.GetChannelPoint())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -5997,7 +5974,7 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context,
// Otherwise, we're targeting an individual channel by its channel // Otherwise, we're targeting an individual channel by its channel
// point. // point.
case *lnrpc.PolicyUpdateRequest_ChanPoint: case *lnrpc.PolicyUpdateRequest_ChanPoint:
txid, err := GetChanPointFundingTxid(scope.ChanPoint) txid, err := lnrpc.GetChanPointFundingTxid(scope.ChanPoint)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -6172,7 +6149,7 @@ func (r *rpcServer) ExportChannelBackup(ctx context.Context,
// First, we'll convert the lnrpc channel point into a wire.OutPoint // First, we'll convert the lnrpc channel point into a wire.OutPoint
// that we can manipulate. // that we can manipulate.
txid, err := GetChanPointFundingTxid(in.ChanPoint) txid, err := lnrpc.GetChanPointFundingTxid(in.ChanPoint)
if err != nil { if err != nil {
return nil, err return nil, err
} }