func (db *DB) AddSidecarWithBid(ticket *sidecar.Ticket, bid *order.Bid) error {
	sidecarKey, err := getSidecarKey(ticket.ID, ticket.Offer.SignPubKey)
	if err != nil {
		return err
	}
	ticket.Order = new(sidecar.Order)
	bidNonce := bid.Nonce()
	copy(ticket.Order.BidNonce[:], bidNonce[:])
	return db.Update(func(tx *bbolt.Tx) error {
		sidecarBucket, err := getBucket(tx, sidecarsBucketKey)
		if err != nil {
			return err
		}
		sidecarValue := sidecarBucket.Get(sidecarKey)
		if len(sidecarValue) != 0 {
			return fmt.Errorf("sidecar for key %x already exists",
				sidecarKey)
		}
		err = storeSidecar(sidecarBucket, sidecarKey, ticket)
		if err != nil {
			return err
		}
		bidBucket, err := sidecarBucket.CreateBucketIfNotExists(
			bidTemplateBucket,
		)
		if err != nil {
			return err
		}
		return storeBidTemplate(bidBucket, bid, bidNonce)
	})
}
AddSidecarWithBid is identical to the AddSidecar method, but it also inserts
a bid template in a special bucket to facilitate automated negotiation of
sidecar channels.
package clientdb
import (
	"bytes"
	"errors"
	"fmt"
	"github.com/btcsuite/btcd/btcec"
	"github.com/lightninglabs/pool/order"
	"github.com/lightninglabs/pool/sidecar"
	"go.etcd.io/bbolt"
)
var (
	ErrNoSidecar = errors.New("no sidecar found")
	sidecarsBucketKey = []byte("sidecars")
	bidTemplateBucket = []byte("sidecar-bids")
)
const (
	sidecarKeyLen = 8 + 33
)
var _ sidecar.Store = (*DB)(nil)
func getSidecarKey(id [8]byte, offerSignPubKey *btcec.PublicKey) ([]byte,
	error) {
	if offerSignPubKey == nil {
		return nil, fmt.Errorf("offer signing pubkey cannot be nil")
	}
	var result [sidecarKeyLen]byte
	copy(result[:], id[:])
	copy(result[8:], offerSignPubKey.SerializeCompressed())
	return result[:], nil
}
func (db *DB) AddSidecar(ticket *sidecar.Ticket) error {
	sidecarKey, err := getSidecarKey(ticket.ID, ticket.Offer.SignPubKey)
	if err != nil {
		return err
	}
	return db.Update(func(tx *bbolt.Tx) error {
		sidecarBucket, err := getBucket(tx, sidecarsBucketKey)
		if err != nil {
			return err
		}
		sidecarValue := sidecarBucket.Get(sidecarKey)
		if len(sidecarValue) != 0 {
			return fmt.Errorf("sidecar for key %x already exists",
				sidecarKey)
		}
		return storeSidecar(sidecarBucket, sidecarKey, ticket)
	})
}