aboutsummaryrefslogtreecommitdiff
path: root/bidder/auction.go
blob: a22f005bc8fb21251530218180add14b322d4af0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package bidder

import (
	"fmt"
	"log"
	"os"

	"kesim.org/seal"
	"kesim.org/seal/nizk/commit"
)

// Auction is the simple interface for the engine
type Auction interface {
	Join(bidder Bidder)                   // A bidder calls this to join the auction
	GotMessage(msg []byte, sig []byte) error // A bidder uses this method to publish a message
}

// Bidder is the interface that the Auction engine uses to communicate
type Bidder interface {
	Commitment() *commit.Commitment
	Start(map[string]*commit.Commitment)
	Result()
	Receive(msg []byte) error
}

type auction struct {
	description *seal.Description

	bidder Bidder

	log     func(string, ...any)
	verbose func(string, ...any)
	debug   func(string, ...any)
}

func nullf(string, ...any) {}

func NewAuction(description *seal.Description, options ...Option) (a *auction, e error) {
	if description.BitLength > 63 {
		return nil, fmt.Errorf("Invalid BitLength in description: %d", description.BitLength)
	}

	logger := log.New(os.Stdout, "[seal::client] ", log.LstdFlags)

	a = &auction{
		description: description,
		log:         logger.Printf,
		verbose:     nullf,
		debug:       nullf,
	}

	for _, opt := range options {
		opt(a)
	}

	return a, nil
}

func (a *auction) Join(bidder Bidder) {
	a.bidder = bidder
}

// Received is called by the bidder whenever a message came in for the auction via the dashboard
// or other means of communication.
func (a *auction) Received(msg []byte) error {
	return fmt.Errorf("Auction.Received not implemented")
}