From ce2796257e543c142a3b30e8cdfddae18b6417ec Mon Sep 17 00:00:00 2001 From: Elliott Jin Date: Sat, 13 Feb 2021 00:05:33 -0800 Subject: [PATCH] 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. --- lnrpc/rpc_utils.go | 24 ++++++ lntest/itest/lnd_forward_interceptor_test.go | 3 +- lntest/itest/lnd_mpp_test.go | 3 +- lntest/itest/lnd_multi-hop-payments_test.go | 9 +- .../lnd_multi-hop_htlc_aggregation_test.go | 3 +- ...d_multi-hop_htlc_local_chain_claim_test.go | 3 +- .../lnd_multi-hop_htlc_local_timeout_test.go | 3 +- ...ulti-hop_htlc_receiver_chain_claim_test.go | 3 +- ..._multi-hop_htlc_remote_chain_claim_test.go | 3 +- lntest/itest/lnd_test.go | 82 +++++++++---------- rpcserver.go | 35 ++------ 11 files changed, 82 insertions(+), 89 deletions(-) diff --git a/lnrpc/rpc_utils.go b/lnrpc/rpc_utils.go index 5dfb87d7..db3126d6 100644 --- a/lnrpc/rpc_utils.go +++ b/lnrpc/rpc_utils.go @@ -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) +} diff --git a/lntest/itest/lnd_forward_interceptor_test.go b/lntest/itest/lnd_forward_interceptor_test.go index ba18eb2f..4dbc29af 100644 --- a/lntest/itest/lnd_forward_interceptor_test.go +++ b/lntest/itest/lnd_forward_interceptor_test.go @@ -9,7 +9,6 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/chainreg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" @@ -341,7 +340,7 @@ func (c *interceptorTestContext) waitForChannels() { // Wait for all nodes to have seen all channels. for _, chanPoint := range c.networkChans { 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") point := wire.OutPoint{ diff --git a/lntest/itest/lnd_mpp_test.go b/lntest/itest/lnd_mpp_test.go index 5a5e8ece..7ccca9e4 100644 --- a/lntest/itest/lnd_mpp_test.go +++ b/lntest/itest/lnd_mpp_test.go @@ -8,7 +8,6 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/chainreg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" @@ -376,7 +375,7 @@ func (c *mppTestContext) waitForChannels() { // Wait for all nodes to have seen all channels. for _, chanPoint := range c.networkChans { for _, node := range c.nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { c.t.Fatalf("unable to get txid: %v", err) } diff --git a/lntest/itest/lnd_multi-hop-payments_test.go b/lntest/itest/lnd_multi-hop-payments_test.go index afacc481..decd8cc2 100644 --- a/lntest/itest/lnd_multi-hop-payments_test.go +++ b/lntest/itest/lnd_multi-hop-payments_test.go @@ -6,7 +6,6 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/chainreg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" @@ -30,7 +29,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { ) networkChans = append(networkChans, chanPointAlice) - aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) + aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -71,7 +70,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { }, ) networkChans = append(networkChans, chanPointDave) - daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) + daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -106,7 +105,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { ) networkChans = append(networkChans, chanPointCarol) - carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) + carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol) if err != nil { 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"} for _, chanPoint := range networkChans { for i, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } diff --git a/lntest/itest/lnd_multi-hop_htlc_aggregation_test.go b/lntest/itest/lnd_multi-hop_htlc_aggregation_test.go index fa6a46b5..1e01b505 100644 --- a/lntest/itest/lnd_multi-hop_htlc_aggregation_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_aggregation_test.go @@ -7,7 +7,6 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" - "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" @@ -187,7 +186,7 @@ func testMultiHopHtlcAggregation(net *lntest.NetworkHarness, t *harnessTest, expectedTxes = 2 } - bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) + bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint) require.NoError(t.t, err) _, err = waitForNTxsInMempool( net.Miner.Node, expectedTxes, minerMempoolTimeout, diff --git a/lntest/itest/lnd_multi-hop_htlc_local_chain_claim_test.go b/lntest/itest/lnd_multi-hop_htlc_local_chain_claim_test.go index 44a07456..2e50337e 100644 --- a/lntest/itest/lnd_multi-hop_htlc_local_chain_claim_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_local_chain_claim_test.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/btcsuite/btcd/wire" - "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" @@ -132,7 +131,7 @@ func testMultiHopHtlcLocalChainClaim(net *lntest.NetworkHarness, t *harnessTest, net.Miner.Node, expectedTxes, minerMempoolTimeout, ) require.NoError(t.t, err) - bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) + bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint) require.NoError(t.t, err) carolFundingPoint := wire.OutPoint{ Hash: *bobFundingTxid, diff --git a/lntest/itest/lnd_multi-hop_htlc_local_timeout_test.go b/lntest/itest/lnd_multi-hop_htlc_local_timeout_test.go index e1230b95..858d969a 100644 --- a/lntest/itest/lnd_multi-hop_htlc_local_timeout_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_local_timeout_test.go @@ -7,7 +7,6 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" - "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" @@ -109,7 +108,7 @@ func testMultiHopHtlcLocalTimeout(net *lntest.NetworkHarness, t *harnessTest, expectedTxes = 2 } - bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) + bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint) require.NoError(t.t, err) _, err = waitForNTxsInMempool( net.Miner.Node, expectedTxes, minerMempoolTimeout, diff --git a/lntest/itest/lnd_multi-hop_htlc_receiver_chain_claim_test.go b/lntest/itest/lnd_multi-hop_htlc_receiver_chain_claim_test.go index 1aace16d..57856c82 100644 --- a/lntest/itest/lnd_multi-hop_htlc_receiver_chain_claim_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_receiver_chain_claim_test.go @@ -5,7 +5,6 @@ import ( "time" "github.com/btcsuite/btcd/wire" - "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" @@ -122,7 +121,7 @@ func testMultiHopReceiverChainClaim(net *lntest.NetworkHarness, t *harnessTest, ) require.NoError(t.t, err) - bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) + bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint) require.NoError(t.t, err) carolFundingPoint := wire.OutPoint{ diff --git a/lntest/itest/lnd_multi-hop_htlc_remote_chain_claim_test.go b/lntest/itest/lnd_multi-hop_htlc_remote_chain_claim_test.go index 72a3c63c..36b98e38 100644 --- a/lntest/itest/lnd_multi-hop_htlc_remote_chain_claim_test.go +++ b/lntest/itest/lnd_multi-hop_htlc_remote_chain_claim_test.go @@ -4,7 +4,6 @@ import ( "context" "github.com/btcsuite/btcd/wire" - "github.com/lightningnetwork/lnd" "github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" @@ -160,7 +159,7 @@ func testMultiHopHtlcRemoteChainClaim(net *lntest.NetworkHarness, t *harnessTest net.Miner.Node, expectedTxes, minerMempoolTimeout, ) require.NoError(t.t, err) - bobFundingTxid, err := lnd.GetChanPointFundingTxid(bobChanPoint) + bobFundingTxid, err := lnrpc.GetChanPointFundingTxid(bobChanPoint) require.NoError(t.t, err) carolFundingPoint := wire.OutPoint{ Hash: *bobFundingTxid, diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index 721ea4d7..3e53acf3 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -120,7 +120,7 @@ func getTestCaseSplitTranche() ([]*testCase, uint, uint) { } func rpcPointToWirePoint(t *harnessTest, chanPoint *lnrpc.ChannelPoint) wire.OutPoint { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -179,7 +179,7 @@ func openChannelAndAssert(ctx context.Context, t *harnessTest, if err != nil { t.Fatalf("error while waiting for channel open: %v", err) } - fundingTxID, err := lnd.GetChanPointFundingTxid(fundingChanPoint) + fundingTxID, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -291,7 +291,7 @@ func assertChannelClosed(ctx context.Context, t *harnessTest, fundingChanPoint *lnrpc.ChannelPoint, anchors bool, closeUpdates lnrpc.Lightning_CloseChannelClient) *chainhash.Hash { - txid, err := lnd.GetChanPointFundingTxid(fundingChanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -387,7 +387,7 @@ func assertChannelClosed(ctx context.Context, t *harnessTest, func waitForChannelPendingForceClose(ctx context.Context, node *lntest.HarnessNode, fundingChanPoint *lnrpc.ChannelPoint) error { - txid, err := lnd.GetChanPointFundingTxid(fundingChanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint) if err != nil { return err } @@ -1722,7 +1722,7 @@ func testPaymentFollowingChannelOpen(net *lntest.NetworkHarness, t *harnessTest) // txStr returns the string representation of the channel's funding transaction. func txStr(chanPoint *lnrpc.ChannelPoint) string { - fundingTxID, err := lnd.GetChanPointFundingTxid(chanPoint) + fundingTxID, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { return "" } @@ -3692,7 +3692,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest, // Compute the outpoint of the channel, which we will use repeatedly to // locate the pending channel information in the rpc responses. - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -5534,7 +5534,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest, ) networkChans = append(networkChans, chanPointCarol) - carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) + carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -5547,7 +5547,7 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest, nodes := []*lntest.HarnessNode{carol, dave} for _, chanPoint := range networkChans { for _, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -5870,7 +5870,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) { ) networkChans = append(networkChans, chanPointAlice) - aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) + aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -5905,7 +5905,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) { }, ) networkChans = append(networkChans, chanPointBob) - bobChanTXID, err := lnd.GetChanPointFundingTxid(chanPointBob) + bobChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointBob) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -5919,7 +5919,7 @@ func testMultiHopSendToRoute(net *lntest.NetworkHarness, t *harnessTest) { nodeNames := []string{"Alice", "Bob", "Carol"} for _, chanPoint := range networkChans { for i, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -6302,7 +6302,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { ) networkChans = append(networkChans, chanPointAlice) - aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) + aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -6335,7 +6335,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { }, ) networkChans = append(networkChans, chanPointDave) - daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) + daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -6370,7 +6370,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { ) networkChans = append(networkChans, chanPointCarol) - carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) + carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol) if err != nil { 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"} for _, chanPoint := range networkChans { for i, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -6430,7 +6430,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { if err != nil { t.Fatalf("error while waiting for channel open: %v", err) } - fundingTxID, err := lnd.GetChanPointFundingTxid(chanPointPrivate) + fundingTxID, err := lnrpc.GetChanPointFundingTxid(chanPointPrivate) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -6876,7 +6876,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) } // Retrieve Alice's funding outpoint. - aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) + aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -6925,7 +6925,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) } // Retrieve Bob's funding outpoint. - bobChanTXID, err := lnd.GetChanPointFundingTxid(chanPointBob) + bobChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointBob) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -6980,7 +6980,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) } // Retrieve Carol's funding point. - carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) + carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol) if err != nil { 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) } - fundingTxID, err := lnd.GetChanPointFundingTxid(fundingChanPoint) + fundingTxID, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -10529,11 +10529,11 @@ out: "expected %v, got %v", blockHeight+1, closedChan.ClosedHeight) } - chanPointTxid, err := lnd.GetChanPointFundingTxid(chanPoint) + chanPointTxid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } - closedChanTxid, err := lnd.GetChanPointFundingTxid( + closedChanTxid, err := lnrpc.GetChanPointFundingTxid( closedChan.ChanPoint, ) if err != nil { @@ -11339,7 +11339,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { ) networkChans = append(networkChans, chanPointAlice) - aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) + aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -11379,7 +11379,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { }, ) networkChans = append(networkChans, chanPointDave) - daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) + daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -11416,7 +11416,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { ) networkChans = append(networkChans, chanPointCarol) - carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) + carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol) if err != nil { 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"} for _, chanPoint := range networkChans { for i, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -11659,7 +11659,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { ) networkChans = append(networkChans, chanPointAlice) - aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) + aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -11699,7 +11699,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { }, ) networkChans = append(networkChans, chanPointDave) - daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) + daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -11736,7 +11736,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { ) networkChans = append(networkChans, chanPointCarol) - carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) + carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol) if err != nil { 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"} for _, chanPoint := range networkChans { for i, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -11980,7 +11980,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness ) networkChans = append(networkChans, chanPointAlice) - aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) + aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -12021,7 +12021,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness ) networkChans = append(networkChans, chanPointDave) - daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) + daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -12058,7 +12058,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness ) networkChans = append(networkChans, chanPointCarol) - carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) + carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol) if err != nil { 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"} for _, chanPoint := range networkChans { for i, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -12313,7 +12313,7 @@ func testSwitchOfflineDeliveryOutgoingOffline( ) networkChans = append(networkChans, chanPointAlice) - aliceChanTXID, err := lnd.GetChanPointFundingTxid(chanPointAlice) + aliceChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointAlice) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -12353,7 +12353,7 @@ func testSwitchOfflineDeliveryOutgoingOffline( }, ) networkChans = append(networkChans, chanPointDave) - daveChanTXID, err := lnd.GetChanPointFundingTxid(chanPointDave) + daveChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointDave) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -12388,7 +12388,7 @@ func testSwitchOfflineDeliveryOutgoingOffline( ) networkChans = append(networkChans, chanPointCarol) - carolChanTXID, err := lnd.GetChanPointFundingTxid(chanPointCarol) + carolChanTXID, err := lnrpc.GetChanPointFundingTxid(chanPointCarol) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -12402,7 +12402,7 @@ func testSwitchOfflineDeliveryOutgoingOffline( nodeNames := []string{"Alice", "Bob", "Carol", "Dave"} for _, chanPoint := range networkChans { for i, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { 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"} for _, chanPoint := range networkChans { for i, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -12904,7 +12904,7 @@ func testRouteFeeCutoff(net *lntest.NetworkHarness, t *harnessTest) { } for _, chanPoint := range networkChans { for i, node := range nodes { - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } @@ -13345,7 +13345,7 @@ func testAbandonChannel(net *lntest.NetworkHarness, t *harnessTest) { chanPoint := openChannelAndAssert( ctxt, t, net, net.Alice, net.Bob, channelParam, ) - txid, err := lnd.GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { t.Fatalf("unable to get txid: %v", err) } diff --git a/rpcserver.go b/rpcserver.go index ea3fc8a0..21ddd81b 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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. index := chanPointShim.ChanPoint.OutputIndex - txid, err := GetChanPointFundingTxid(chanPointShim.ChanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPointShim.ChanPoint) if err != nil { return nil, err } @@ -2086,7 +2086,7 @@ out: update, ok := fundingUpdate.Update.(*lnrpc.OpenStatusUpdate_ChanOpen) if ok { chanPoint := update.ChanOpen.ChannelPoint - txid, err := GetChanPointFundingTxid(chanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(chanPoint) if err != nil { 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 // 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. @@ -2201,7 +2178,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest, force := in.Force index := in.ChannelPoint.OutputIndex - txid, err := GetChanPointFundingTxid(in.GetChannelPoint()) + txid, err := lnrpc.GetChanPointFundingTxid(in.GetChannelPoint()) if err != nil { rpcsLog.Errorf("[closechannel] unable to get funding txid: %v", 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 // target channel. - txid, err := GetChanPointFundingTxid(in.GetChannelPoint()) + txid, err := lnrpc.GetChanPointFundingTxid(in.GetChannelPoint()) if err != nil { return nil, err } @@ -5997,7 +5974,7 @@ func (r *rpcServer) UpdateChannelPolicy(ctx context.Context, // Otherwise, we're targeting an individual channel by its channel // point. case *lnrpc.PolicyUpdateRequest_ChanPoint: - txid, err := GetChanPointFundingTxid(scope.ChanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(scope.ChanPoint) if err != nil { 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 // that we can manipulate. - txid, err := GetChanPointFundingTxid(in.ChanPoint) + txid, err := lnrpc.GetChanPointFundingTxid(in.ChanPoint) if err != nil { return nil, err }