aboutsummaryrefslogtreecommitdiff
path: root/client/client.go
blob: 19f0d3525677a15e2d7b758469b84b2a332f83c4 (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
package client

import (
	"fmt"
	"log"
	"os"

	"kesim.org/seal"
)

type Auction struct {
	description *seal.Description

	bid *bid

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

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

func NewAuction(description *seal.Description, options ...Option) (auction *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)

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

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

	return auction, nil
}

func (a *Auction) Join(price uint64) error {
	bid, e := newBid(price, a.description.BitLength)
	if e != nil {
		return e
	}

	a.debug("created bid: %#v\n", bid)

	a.bid = bid
	return nil
}