write completed funding tx to disk
* Will move to buckets specific to LNID’s in the future
This commit is contained in:
parent
92ff9a6bd5
commit
ad8a7cf2f2
@ -1,6 +1,9 @@
|
|||||||
package wallet
|
package wallet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
@ -32,12 +35,18 @@ var (
|
|||||||
waddrmgrNamespaceKey = []byte("waddrmgr")
|
waddrmgrNamespaceKey = []byte("waddrmgr")
|
||||||
wtxmgrNamespaceKey = []byte("wtxmgr")
|
wtxmgrNamespaceKey = []byte("wtxmgr")
|
||||||
|
|
||||||
|
openChannelBucket = []byte("o-chans")
|
||||||
|
closedChannelBucket = []byte("c-chans")
|
||||||
|
fundingTxKey = []byte("funding")
|
||||||
|
|
||||||
// Error types
|
// Error types
|
||||||
ErrInsufficientFunds = errors.New("not enough available outputs to " +
|
ErrInsufficientFunds = errors.New("not enough available outputs to " +
|
||||||
"create funding transaction")
|
"create funding transaction")
|
||||||
|
|
||||||
// Which bitcoin network are we using?
|
// Which bitcoin network are we using?
|
||||||
ActiveNetParams = &chaincfg.TestNet3Params
|
ActiveNetParams = &chaincfg.TestNet3Params
|
||||||
|
|
||||||
|
endian = binary.BigEndian
|
||||||
)
|
)
|
||||||
|
|
||||||
type FundingType uint16
|
type FundingType uint16
|
||||||
@ -578,27 +587,41 @@ func (l *LightningWallet) handleFundingCounterPartySigs(msg *addCounterPartySigs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): write the funding transaction to disk
|
// Now that all signatures are in place, and valid record the regular txid.
|
||||||
// * funding transaction bucket
|
|
||||||
// * then accessed according to non-recursive normalized txid?
|
|
||||||
// * also possibly add reverse mapping
|
|
||||||
// Now that all signatures are in place and valid record the regular txid
|
|
||||||
//completedReservation := &finalizedFundingState{
|
|
||||||
// FundingTxId: pendingReservation.fundingTx.TxSha(),
|
|
||||||
// NormalizedFundingTXID: pendingReservation.normalizedTxID,
|
|
||||||
// CompletedFundingTx: btcutil.NewTx(pendingReservation.fundingTx),
|
|
||||||
//}
|
|
||||||
|
|
||||||
pendingReservation.completedFundingTx = btcutil.NewTx(pendingReservation.fundingTx)
|
pendingReservation.completedFundingTx = btcutil.NewTx(pendingReservation.fundingTx)
|
||||||
|
txID := pendingReservation.fundingTx.TxSha()
|
||||||
// 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()
|
||||||
|
|
||||||
msg.err <- nil
|
// Add the complete funding transaction to the DB, in it's open bucket
|
||||||
|
// which will be used for the lifetime of this channel.
|
||||||
|
writeErr := l.lnNamespace.Update(func(tx walletdb.Tx) error {
|
||||||
|
// Get the bucket dedicated to storing the meta-data for open
|
||||||
|
// channels.
|
||||||
|
rootBucket := tx.RootBucket()
|
||||||
|
openChanBucket, err := rootBucket.CreateBucketIfNotExists(openChannelBucket)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new sub-bucket within the open channel bucket
|
||||||
|
// specifically for this channel.
|
||||||
|
// TODO(roasbeef): should def be indexed by LNID
|
||||||
|
chanBucket, err := openChanBucket.CreateBucketIfNotExists(txID.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(roasbeef): sync.Pool of buffers in the future.
|
||||||
|
var buf bytes.Buffer
|
||||||
|
fundingTx.Serialize(&buf)
|
||||||
|
return chanBucket.Put(fundingTxKey, buf.Bytes())
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO(roasbeef): broadcast now?
|
||||||
|
msg.err <- writeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// nextMultiSigKey...
|
// nextMultiSigKey...
|
||||||
|
Loading…
Reference in New Issue
Block a user