lnwallet: directly get change add for now, not connected to real node
This commit is contained in:
parent
627192f493
commit
b36de8768d
@ -3,6 +3,7 @@ package wallet
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
@ -368,21 +369,22 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create some possibly neccessary change outputs.
|
// 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()))
|
partialState.ourChange = make([]*wire.TxOut, 0, len(selectedCoins.Coins()))
|
||||||
if selectedTotalValue > req.fundingAmount {
|
if selectedTotalValue > req.fundingAmount {
|
||||||
// Change is necessary. Query for an available change address to
|
// Change is necessary. Query for an available change address to
|
||||||
// send the remainder to.
|
// send the remainder to.
|
||||||
changeAmount := selectedTotalValue - req.fundingAmount
|
changeAmount := selectedTotalValue - req.fundingAmount
|
||||||
changeAddr, err := l.wallet.NewChangeAddress(waddrmgr.DefaultAccountNum)
|
addrs, err := l.wallet.Manager.NextInternalAddresses(waddrmgr.DefaultAccountNum, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
req.err <- err
|
req.err <- err
|
||||||
req.resp <- nil
|
req.resp <- nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
changeAddrScript := addrs[0].AddrHash()
|
||||||
|
|
||||||
partialState.ourChange = append(partialState.ourChange,
|
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
|
// TODO(roasbeef): re-calculate fees here to minFeePerKB, may need more inputs
|
||||||
|
Loading…
Reference in New Issue
Block a user