<commit_before>package wallet

import (
	"sync"

	"github.com/btcsuite/btcd/btcec"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcutil"
)

// ChannelReservation...
type ChannelReservation struct {
	FundingType FundingType

	FundingAmount btcutil.Amount
	ReserveAmount btcutil.Amount
	MinFeePerKb   btcutil.Amount

	sync.RWMutex // All fields below owned by the lnwallet.

	theirInputs []*wire.TxIn
	ourInputs   []*wire.TxIn

	theirChange []*wire.TxOut
	ourChange   []*wire.TxOut

	ourKey   *btcec.PrivateKey
	theirKey *btcec.PublicKey

	// In order of sorted inputs. Sorting is done in accordance
	// to BIP-69: https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki.
	theirSigs [][]byte
	ourSigs   [][]byte

	normalizedTxID wire.ShaHash

	fundingTx *wire.MsgTx
	// TODO(roasbef): time locks, who pays fee etc.
	// TODO(roasbeef): record Bob's ln-ID?

	completedFundingTx *btcutil.Tx

	reservationID uint64
	wallet        *LightningWallet
}

// newChannelReservation...
func newChannelReservation(t FundingType, fundingAmt btcutil.Amount,
	minFeeRate btcutil.Amount, wallet *LightningWallet, id uint64) *ChannelReservation {
	return &ChannelReservation{
		FundingType:   t,
		FundingAmount: fundingAmt,
		MinFeePerKb:   minFeeRate,
		wallet:        wallet,
		reservationID: id,
	}
}

// OurFunds...
func (r *ChannelReservation) OurFunds() ([]*wire.TxIn, []*wire.TxOut, *btcec.PublicKey) {
	r.RLock()
	defer r.RUnlock()
	return r.ourInputs, r.ourChange, r.ourKey.PubKey()
}

// AddCounterPartyFunds...
func (r *ChannelReservation) AddFunds(theirInputs []*wire.TxIn, theirChangeOutputs []*wire.TxOut, multiSigKey *btcec.PublicKey) error {
	errChan := make(chan error, 1)

	r.wallet.msgChan <- &addCounterPartyFundsMsg{<commit_msg>add "future" open channel to reservation<commit_after>package wallet

import (
	"sync"

	"github.com/btcsuite/btcd/btcec"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcutil"
)

// ChannelReservation...
type ChannelReservation struct {
	FundingType FundingType

	FundingAmount btcutil.Amount
	ReserveAmount btcutil.Amount
	MinFeePerKb   btcutil.Amount

	sync.RWMutex // All fields below owned by the lnwallet.

	theirInputs []*wire.TxIn
	ourInputs   []*wire.TxIn

	theirChange []*wire.TxOut
	ourChange   []*wire.TxOut

	ourKey   *btcec.PrivateKey
	theirKey *btcec.PublicKey

	// In order of sorted inputs. Sorting is done in accordance
	// to BIP-69: https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki.
	theirSigs [][]byte
	ourSigs   [][]byte

	normalizedTxID wire.ShaHash

	fundingTx *wire.MsgTx
	// TODO(roasbef): time locks, who pays fee etc.
	// TODO(roasbeef): record Bob's ln-ID?

	completedFundingTx *btcutil.Tx

	reservationID uint64
	wallet        *LightningWallet

	chanOpen chan *LightningChannel
}

// newChannelReservation...
func newChannelReservation(t FundingType, fundingAmt btcutil.Amount,
	minFeeRate btcutil.Amount, wallet *LightningWallet, id uint64) *ChannelReservation {
	return &ChannelReservation{
		FundingType:   t,
		FundingAmount: fundingAmt,
		MinFeePerKb:   minFeeRate,
		wallet:        wallet,
		reservationID: id,
	}
}

// OurFunds...
func (r *ChannelReservation) OurFunds() ([]*wire.TxIn, []*wire.TxOut, *btcec.PublicKey) {
	r.RLock()
	defer r.RUnlock()
	return r.ourInputs, r.ourChange, r.ourKey.PubKey()
}

// AddCounterPartyFunds...
func (r *ChannelReservation) AddFunds(theirInputs []*wire.TxIn, theirChangeOutputs []*wire.TxOut, multiSigKey *btcec.PublicKey) error {
	errChan := make(chan error, 1)

	r.wallet.msgChan <- &addCounterPartyFundsMsg{
{'fraction_non_alphanumeric': 0.1189873417721519, 'fraction_numerical': 0.006188466947960619, 'mean_word_length': 4.299552906110283, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1268052', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1310, 'n_words': 275}