func StateModifier(state State) Modifier {
	return func(account *Account) {
		account.State = state
	}
}
StateModifier is a functional option that modifies the state of an account.
package account
import (
	"context"
	"errors"
	"fmt"
	"math/big"
	"github.com/btcsuite/btcd/btcec"
	"github.com/btcsuite/btcd/txscript"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcutil"
	"github.com/btcsuite/btcwallet/wtxmgr"
	"github.com/lightninglabs/lndclient"
	"github.com/lightninglabs/pool/poolscript"
	"github.com/lightninglabs/pool/terms"
	"github.com/lightningnetwork/lnd/input"
	"github.com/lightningnetwork/lnd/keychain"
	"github.com/lightningnetwork/lnd/lnwallet"
	"github.com/lightningnetwork/lnd/lnwallet/chainfee"
)
var (
	ErrNoPendingBatch = errors.New("no pending batch found")
)
type Reservation struct {
	AuctioneerKey *btcec.PublicKey
	InitialBatchKey *btcec.PublicKey
}
type State uint8
const (
	StateInitiated State = 0
	StatePendingOpen State = 1
	StatePendingUpdate State = 2
	StateOpen State = 3
	StateExpired State = 4
	StatePendingClosed State = 5
	StateClosed State = 6
	StateCanceledAfterRecovery State = 7
	StatePendingBatch State = 8
	StateExpiredPendingUpdate State = 9
)
func (s State) String() string {
	switch s {
	case StateInitiated:
		return "StateInitiated"
	case StatePendingOpen:
		return "StatePendingOpen"
	case StatePendingUpdate:
		return "StatePendingUpdate"
	case StateOpen:
		return "StateOpen"
	case StateExpired:
		return "StateExpired"
	case StatePendingClosed:
		return "StatePendingClosed"
	case StateClosed:
		return "StateClosed"
	case StateCanceledAfterRecovery:
		return "StateCanceledAfterRecovery"
	case StatePendingBatch:
		return "StatePendingBatch"
	case StateExpiredPendingUpdate:
		return "StateExpiredPendingUpdate"
	default:
		return "unknown"
	}
}
func (s State) IsActive() bool {
	switch s {
	case StateClosed, StateCanceledAfterRecovery:
		return false
	default:
		return true
	}
}
type Account struct {
	Value btcutil.Amount
	Expiry uint32
	TraderKey *keychain.KeyDescriptor
	AuctioneerKey *btcec.PublicKey
	BatchKey *btcec.PublicKey
	Secret [32]byte
	State State
	HeightHint uint32
	OutPoint wire.OutPoint
	LatestTx *wire.MsgTx
}
const (
	DefaultFundingConfTarget uint32 = 144 * 7
)
func (a *Account) Output() (*wire.TxOut, error) {
	script, err := poolscript.AccountScript(
		a.Expiry, a.TraderKey.PubKey, a.AuctioneerKey, a.BatchKey,
		a.Secret,
	)
	if err != nil {
		return nil, err
	}
	return &wire.TxOut{
		Value:    int64(a.Value),
		PkScript: script,
	}, nil
}
func (a *Account) NextOutputScript() ([]byte, error) {
	nextBatchKey := poolscript.IncrementKey(a.BatchKey)
	return poolscript.AccountScript(
		a.Expiry, a.TraderKey.PubKey, a.AuctioneerKey, nextBatchKey,
		a.Secret,
	)
}
func (a *Account) Copy(modifiers ...Modifier) *Account {
	accountCopy := &Account{
		Value:  a.Value,
		Expiry: a.Expiry,
		TraderKey: &keychain.KeyDescriptor{
			KeyLocator: a.TraderKey.KeyLocator,
			PubKey: &btcec.PublicKey{
				X:     big.NewInt(0).Set(a.TraderKey.PubKey.X),
				Y:     big.NewInt(0).Set(a.TraderKey.PubKey.Y),
				Curve: a.TraderKey.PubKey.Curve,
			},
		},
		AuctioneerKey: &btcec.PublicKey{
			X:     big.NewInt(0).Set(a.AuctioneerKey.X),
			Y:     big.NewInt(0).Set(a.AuctioneerKey.Y),
			Curve: a.AuctioneerKey.Curve,
		},
		BatchKey: &btcec.PublicKey{
			X:     big.NewInt(0).Set(a.BatchKey.X),
			Y:     big.NewInt(0).Set(a.BatchKey.Y),
			Curve: a.BatchKey.Curve,
		},
		Secret:     a.Secret,
		State:      a.State,
		HeightHint: a.HeightHint,
		OutPoint:   a.OutPoint,
	}
	if a.State != StateInitiated {
		accountCopy.LatestTx = a.LatestTx.Copy()
	}
	for _, modifier := range modifiers {
		modifier(accountCopy)
	}
	return accountCopy
}
type Modifier func(*Account)