multi: update WalletController PublishTransaction to include label
Add label parameter to PublishTransaction in WalletController interface. A labels package is added to store generic labels that are used for the different types of transactions that are published by lnd. To keep commit size down, the two endpoints that require a label parameter be passed down have a todo added, which will be removed in subsequent commits.
This commit is contained in:
25 files changed
+74
-52
No files matched your search
@@ -433,8 +433,8 @@ func (b *BtcWallet) ListUnspentWitness(minConfs, maxConfs int32) (
|
||||
// publishing the transaction fails, an error describing the reason is returned
|
||||
// (currently ErrDoubleSpend). If the transaction is already published to the
|
||||
// network (either in the mempool or chain) no error will be returned.
|
||||
func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx) error {
|
||||
if err := b.wallet.PublishTransaction(tx, ""); err != nil {
|
||||
func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx, label string) error {
|
||||
if err := b.wallet.PublishTransaction(tx, label); err != nil {
|
||||
|
||||
// If we failed to publish the transaction, check whether we
|
||||
// got an error of known type.
|
||||
|
||||
@@ -224,8 +224,9 @@ type WalletController interface {
|
||||
// already known transaction, ErrDoubleSpend is returned. If the
|
||||
// transaction is already known (published already), no error will be
|
||||
// returned. Other error returned depends on the currently active chain
|
||||
// backend.
|
||||
PublishTransaction(tx *wire.MsgTx) error
|
||||
// backend. It takes an optional label which will save a label with the
|
||||
// published transaction.
|
||||
PublishTransaction(tx *wire.MsgTx, label string) error
|
||||
|
||||
// SubscribeTransactions returns a TransactionSubscription client which
|
||||
// is capable of receiving async notifications as new transactions
|
||||
|
||||
+20
-11
@@ -38,6 +38,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb/kvdb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/labels"
|
||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
||||
@@ -529,7 +530,8 @@ func testDualFundingReservationWorkflow(miner *rpctest.Harness,
|
||||
}
|
||||
|
||||
// Let Alice publish the funding transaction.
|
||||
if err := alice.PublishTransaction(fundingTx); err != nil {
|
||||
err = alice.PublishTransaction(fundingTx, "")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish funding tx: %v", err)
|
||||
}
|
||||
|
||||
@@ -1024,7 +1026,8 @@ func testSingleFunderReservationWorkflow(miner *rpctest.Harness,
|
||||
}
|
||||
|
||||
// Let Alice publish the funding transaction.
|
||||
if err := alice.PublishTransaction(fundingTx); err != nil {
|
||||
err = alice.PublishTransaction(fundingTx, "")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish funding tx: %v", err)
|
||||
}
|
||||
|
||||
@@ -1721,7 +1724,8 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
tx1 := newTx(t, r, keyDesc.PubKey, alice, false)
|
||||
|
||||
// Publish the transaction.
|
||||
if err := alice.PublishTransaction(tx1); err != nil {
|
||||
err = alice.PublishTransaction(tx1, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
|
||||
@@ -1733,7 +1737,8 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
|
||||
// Publish the exact same transaction again. This should not return an
|
||||
// error, even though the transaction is already in the mempool.
|
||||
if err := alice.PublishTransaction(tx1); err != nil {
|
||||
err = alice.PublishTransaction(tx1, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
|
||||
@@ -1752,7 +1757,8 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
tx2 := newTx(t, r, keyDesc.PubKey, alice, false)
|
||||
|
||||
// Publish this tx.
|
||||
if err := alice.PublishTransaction(tx2); err != nil {
|
||||
err = alice.PublishTransaction(tx2, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
|
||||
@@ -1763,7 +1769,8 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
|
||||
// Publish the transaction again. It is already mined, and we don't
|
||||
// expect this to return an error.
|
||||
if err := alice.PublishTransaction(tx2); err != nil {
|
||||
err = alice.PublishTransaction(tx2, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
|
||||
@@ -1779,7 +1786,8 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
// transaction. Create a new tx and publish it. This is the
|
||||
// output we'll try to double spend.
|
||||
tx3 = newTx(t, r, keyDesc.PubKey, alice, false)
|
||||
if err := alice.PublishTransaction(tx3); err != nil {
|
||||
err := alice.PublishTransaction(tx3, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
|
||||
@@ -1799,7 +1807,8 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
}
|
||||
|
||||
// This should be accepted into the mempool.
|
||||
if err := alice.PublishTransaction(tx4); err != nil {
|
||||
err = alice.PublishTransaction(tx4, labels.External)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to publish: %v", err)
|
||||
}
|
||||
|
||||
@@ -1833,7 +1842,7 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = alice.PublishTransaction(tx5)
|
||||
err = alice.PublishTransaction(tx5, labels.External)
|
||||
if err != lnwallet.ErrDoubleSpend {
|
||||
t.Fatalf("expected ErrDoubleSpend, got: %v", err)
|
||||
}
|
||||
@@ -1861,7 +1870,7 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
expErr = nil
|
||||
tx3Spend = tx6
|
||||
}
|
||||
err = alice.PublishTransaction(tx6)
|
||||
err = alice.PublishTransaction(tx6, labels.External)
|
||||
if err != expErr {
|
||||
t.Fatalf("expected ErrDoubleSpend, got: %v", err)
|
||||
}
|
||||
@@ -1896,7 +1905,7 @@ func testPublishTransaction(r *rpctest.Harness,
|
||||
}
|
||||
|
||||
// Expect rejection.
|
||||
err = alice.PublishTransaction(tx7)
|
||||
err = alice.PublishTransaction(tx7, labels.External)
|
||||
if err != lnwallet.ErrDoubleSpend {
|
||||
t.Fatalf("expected ErrDoubleSpend, got: %v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user