lnwallet: fix panic, use append to collect sigs

This commit is contained in:
Olaoluwa Osuntokun 2015-11-29 12:19:47 -08:00
parent dbc9c27758
commit 5d9b4e73ff

@ -182,7 +182,6 @@ func NewLightningWallet(privWalletPass, pubWalletPass, hdSeed []byte, dataDir st
// Wallet has never been created, perform initial set up. // Wallet has never been created, perform initial set up.
if !fileExists(dbPath) { if !fileExists(dbPath) {
fmt.Println("wallet doesn't exist, creating")
// Ensure the data directory for the network exists. // Ensure the data directory for the network exists.
if err := checkCreateDir(netDir); err != nil { if err := checkCreateDir(netDir); err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
@ -382,6 +381,8 @@ func (l *LightningWallet) handleFundingReserveRequest(req *initFundingReserveMsg
return return
} }
changeAddrScript := addrs[0].AddrHash() changeAddrScript := addrs[0].AddrHash()
// TODO(roasbeef): re-enable after test are connected to real node.
//changeAddr, err := l.wallet.NewChangeAddress(waddrmgr.DefaultAccountNum)
partialState.ourChange = append(partialState.ourChange, partialState.ourChange = append(partialState.ourChange,
wire.NewTxOut(int64(changeAmount), changeAddrScript)) wire.NewTxOut(int64(changeAmount), changeAddrScript))
@ -513,7 +514,7 @@ func (l *LightningWallet) handleFundingCounterPartyFunds(req *addCounterPartyFun
// Now, sign all inputs that are ours, collecting the signatures in // Now, sign all inputs that are ours, collecting the signatures in
// order of the inputs. // order of the inputs.
pendingReservation.ourSigs = make([][]byte, len(pendingReservation.ourInputs)) pendingReservation.ourSigs = make([][]byte, 0, len(pendingReservation.ourInputs))
for i, txIn := range pendingReservation.fundingTx.TxIn { for i, txIn := range pendingReservation.fundingTx.TxIn {
// Does the wallet know about the txin? // Does the wallet know about the txin?
txDetail, _ := l.wallet.TxStore.TxDetails(&txIn.PreviousOutPoint.Hash) txDetail, _ := l.wallet.TxStore.TxDetails(&txIn.PreviousOutPoint.Hash)
@ -552,7 +553,7 @@ func (l *LightningWallet) handleFundingCounterPartyFunds(req *addCounterPartyFun
} }
pendingReservation.fundingTx.TxIn[i].SignatureScript = sigscript pendingReservation.fundingTx.TxIn[i].SignatureScript = sigscript
pendingReservation.ourSigs[i] = sigscript pendingReservation.ourSigs = append(pendingReservation.ourSigs, sigscript)
} }
req.err <- nil req.err <- nil
@ -598,6 +599,9 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
pendingReservation.completedFundingTx = btcutil.NewTx(pendingReservation.fundingTx) pendingReservation.completedFundingTx = btcutil.NewTx(pendingReservation.fundingTx)
// Add the complete funding transactions to the TxStore for our records.
//l.wallet.TxStore.InsertTx(
l.limboMtx.Lock() l.limboMtx.Lock()
delete(l.fundingLimbo, pendingReservation.reservationID) delete(l.fundingLimbo, pendingReservation.reservationID)
l.limboMtx.Unlock() l.limboMtx.Unlock()