From e14678030c57ea620071e9c77856f7562a8c4e99 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Mon, 5 Nov 2018 12:30:32 +0100 Subject: [PATCH] lnwallet: update to new SendOutputs signature --- Gopkg.lock | 5 ++-- Gopkg.toml | 2 +- lnwallet/btcwallet/btcwallet.go | 2 +- lnwallet/interface.go | 2 +- lnwallet/interface_test.go | 44 +++++++++++++++------------------ mock.go | 2 +- rpcserver.go | 8 +++++- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 37c3f1cf..4b7c2f39 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -106,7 +106,7 @@ revision = "ab6388e0c60ae4834a1f57511e20c17b5f78be4b" [[projects]] - digest = "1:ac01796bf202b80d6cb1b92d42df0fbbf3aff964451376bfa7c39bc2bf94d108" + digest = "1:2995aa2bcb95d13a8df309e1dcb6ac20786acb90df5a090bf5e07c2086219ce8" name = "github.com/btcsuite/btcwallet" packages = [ "chain", @@ -123,10 +123,11 @@ "wallet/txrules", "walletdb", "walletdb/bdb", + "walletdb/migration", "wtxmgr", ] pruneopts = "UT" - revision = "c4dd27e481f9801866cf5226bfe532084772ec2a" + revision = "6d43b2e29b5eef0f000a301ee6fbd146db75d118" [[projects]] branch = "master" diff --git a/Gopkg.toml b/Gopkg.toml index 72bd8772..ec90ab07 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -72,7 +72,7 @@ [[constraint]] name = "github.com/btcsuite/btcwallet" - revision = "c4dd27e481f9801866cf5226bfe532084772ec2a" + revision = "6d43b2e29b5eef0f000a301ee6fbd146db75d118" [[constraint]] name = "github.com/tv42/zbase32" diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 97211533..74364ec0 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -268,7 +268,7 @@ func (b *BtcWallet) IsOurAddress(a btcutil.Address) bool { // // This is a part of the WalletController interface. func (b *BtcWallet) SendOutputs(outputs []*wire.TxOut, - feeRate lnwallet.SatPerKWeight) (*chainhash.Hash, error) { + feeRate lnwallet.SatPerKWeight) (*wire.MsgTx, error) { // Convert our fee rate from sat/kw to sat/kb since it's required by // SendOutputs. diff --git a/lnwallet/interface.go b/lnwallet/interface.go index 7d9ea3f0..bd566e04 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -157,7 +157,7 @@ type WalletController interface { // This method also takes the target fee expressed in sat/kw that should // be used when crafting the transaction. SendOutputs(outputs []*wire.TxOut, - feeRate SatPerKWeight) (*chainhash.Hash, error) + feeRate SatPerKWeight) (*wire.MsgTx, error) // ListUnspentWitness returns all unspent outputs which are version 0 // witness programs. The 'minconfirms' and 'maxconfirms' parameters diff --git a/lnwallet/interface_test.go b/lnwallet/interface_test.go index eeca8962..da3240ee 100644 --- a/lnwallet/interface_test.go +++ b/lnwallet/interface_test.go @@ -1069,11 +1069,12 @@ func testListTransactionDetails(miner *rpctest.Harness, t.Fatalf("unable to make output script: %v", err) } burnOutput := wire.NewTxOut(outputAmt, outputScript) - burnTXID, err := alice.SendOutputs([]*wire.TxOut{burnOutput}, 2500) + burnTX, err := alice.SendOutputs([]*wire.TxOut{burnOutput}, 2500) if err != nil { t.Fatalf("unable to create burn tx: %v", err) } - err = waitForMempoolTx(miner, burnTXID) + burnTXID := burnTX.TxHash() + err = waitForMempoolTx(miner, &burnTXID) if err != nil { t.Fatalf("tx not relayed to miner: %v", err) } @@ -1281,11 +1282,12 @@ func testTransactionSubscriptions(miner *rpctest.Harness, t.Fatalf("unable to make output script: %v", err) } burnOutput := wire.NewTxOut(outputAmt, outputScript) - txid, err := alice.SendOutputs([]*wire.TxOut{burnOutput}, 2500) + tx, err := alice.SendOutputs([]*wire.TxOut{burnOutput}, 2500) if err != nil { t.Fatalf("unable to create burn tx: %v", err) } - err = waitForMempoolTx(miner, txid) + txid := tx.TxHash() + err = waitForMempoolTx(miner, &txid) if err != nil { t.Fatalf("tx not relayed to miner: %v", err) } @@ -1304,7 +1306,7 @@ func testTransactionSubscriptions(miner *rpctest.Harness, case <-time.After(time.Second * 10): t.Fatalf("transactions not received after 10 seconds") case unConfTx := <-txClient.UnconfirmedTransactions(): - if unConfTx.Hash != *txid { + if unConfTx.Hash != txid { t.Fatalf("wrong txn notified: expected %v got %v", txid, unConfTx.Hash) } @@ -1457,27 +1459,24 @@ func testPublishTransaction(r *rpctest.Harness, Value: btcutil.SatoshiPerBitcoin, PkScript: keyScript, } - txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 2500) + tx, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 2500) if err != nil { t.Fatalf("unable to create output: %v", err) } + txid := tx.TxHash() // Query for the transaction generated above so we can located // the index of our output. - err = waitForMempoolTx(r, txid) + err = waitForMempoolTx(r, &txid) if err != nil { t.Fatalf("tx not relayed to miner: %v", err) } - tx, err := r.Node.GetRawTransaction(txid) - if err != nil { - t.Fatalf("unable to query for tx: %v", err) - } - if err := mineAndAssert(tx.MsgTx()); err != nil { + if err := mineAndAssert(tx); err != nil { t.Fatalf("unable to mine tx: %v", err) } txFee := btcutil.Amount(0.1 * btcutil.SatoshiPerBitcoin) - tx1 := txFromOutput(tx.MsgTx(), pubKey.PubKey, txFee) + tx1 := txFromOutput(tx, pubKey.PubKey, txFee) return tx1 } @@ -1702,23 +1701,19 @@ func testSignOutputUsingTweaks(r *rpctest.Harness, Value: btcutil.SatoshiPerBitcoin, PkScript: keyScript, } - txid, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 2500) + tx, err := alice.SendOutputs([]*wire.TxOut{newOutput}, 2500) if err != nil { t.Fatalf("unable to create output: %v", err) } - + txid := tx.TxHash() // Query for the transaction generated above so we can located // the index of our output. - err = waitForMempoolTx(r, txid) + err = waitForMempoolTx(r, &txid) if err != nil { t.Fatalf("tx not relayed to miner: %v", err) } - tx, err := r.Node.GetRawTransaction(txid) - if err != nil { - t.Fatalf("unable to query for tx: %v", err) - } var outputIndex uint32 - if bytes.Equal(tx.MsgTx().TxOut[0].PkScript, keyScript) { + if bytes.Equal(tx.TxOut[0].PkScript, keyScript) { outputIndex = 0 } else { outputIndex = 1 @@ -1729,7 +1724,7 @@ func testSignOutputUsingTweaks(r *rpctest.Harness, sweepTx := wire.NewMsgTx(2) sweepTx.AddTxIn(&wire.TxIn{ PreviousOutPoint: wire.OutPoint{ - Hash: tx.MsgTx().TxHash(), + Hash: txid, Index: outputIndex, }, }) @@ -1828,11 +1823,12 @@ func testReorgWalletBalance(r *rpctest.Harness, w *lnwallet.LightningWallet, Value: 1e8, PkScript: script, } - txid, err := w.SendOutputs([]*wire.TxOut{output}, 2500) + tx, err := w.SendOutputs([]*wire.TxOut{output}, 2500) if err != nil { t.Fatalf("unable to send outputs: %v", err) } - err = waitForMempoolTx(r, txid) + txid := tx.TxHash() + err = waitForMempoolTx(r, &txid) if err != nil { t.Fatalf("tx not relayed to miner: %v", err) } diff --git a/mock.go b/mock.go index 51f10e46..34276bee 100644 --- a/mock.go +++ b/mock.go @@ -227,7 +227,7 @@ func (*mockWalletController) IsOurAddress(a btcutil.Address) bool { } func (*mockWalletController) SendOutputs(outputs []*wire.TxOut, - _ lnwallet.SatPerKWeight) (*chainhash.Hash, error) { + _ lnwallet.SatPerKWeight) (*wire.MsgTx, error) { return nil, nil } diff --git a/rpcserver.go b/rpcserver.go index d42d7c1c..7f625920 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -408,7 +408,13 @@ func (r *rpcServer) sendCoinsOnChain(paymentMap map[string]int64, return nil, err } - return r.server.cc.wallet.SendOutputs(outputs, feeRate) + tx, err := r.server.cc.wallet.SendOutputs(outputs, feeRate) + if err != nil { + return nil, err + } + + txHash := tx.TxHash() + return &txHash, err } // determineFeePerKw will determine the fee in sat/kw that should be paid given