From b36de8768dd4d40bb8d522d58af4e899c9f2ad33 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 28 Nov 2015 18:16:00 -0600 Subject: [PATCH] lnwallet: directly get change add for now, not connected to real node --- wallet/wallet.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wallet/wallet.go b/wallet/wallet.go index 962697e6..469d57a0 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -3,6 +3,7 @@ package wallet import ( "errors" "fmt" + "math" "os" "path/filepath" "sync" @@ -368,21 +369,22 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg } // Create some possibly neccessary change outputs. - selectedTotalValue := coinset.NewCoinSet(coins).TotalValue() + selectedTotalValue := coinset.NewCoinSet(selectedCoins.Coins()).TotalValue() partialState.ourChange = make([]*wire.TxOut, 0, len(selectedCoins.Coins())) if selectedTotalValue > req.fundingAmount { // Change is necessary. Query for an available change address to // send the remainder to. changeAmount := selectedTotalValue - req.fundingAmount - changeAddr, err := l.wallet.NewChangeAddress(waddrmgr.DefaultAccountNum) + addrs, err := l.wallet.Manager.NextInternalAddresses(waddrmgr.DefaultAccountNum, 1) if err != nil { req.err <- err req.resp <- nil return } + changeAddrScript := addrs[0].AddrHash() partialState.ourChange = append(partialState.ourChange, - wire.NewTxOut(int64(changeAmount), changeAddr.ScriptAddress())) + wire.NewTxOut(int64(changeAmount), changeAddrScript)) } // TODO(roasbeef): re-calculate fees here to minFeePerKB, may need more inputs