aboutsummaryrefslogtreecommitdiff
path: root/auction.go
diff options
context:
space:
mode:
Diffstat (limited to 'auction.go')
-rw-r--r--auction.go37
1 files changed, 26 insertions, 11 deletions
diff --git a/auction.go b/auction.go
index 4cdbe82..9dd7da5 100644
--- a/auction.go
+++ b/auction.go
@@ -22,16 +22,32 @@ const (
TypSecondHighest
)
+type Duration time.Duration
+
+func (d *Duration) UnmarshalJSON(data []byte) error {
+ data = bytes.Trim(data, `"`)
+ dur, e := time.ParseDuration(string(data))
+ if e != nil {
+ return e
+ }
+ *d = Duration(dur)
+ return nil
+}
+
+func (d Duration) MarshalJSON() ([]byte, error) {
+ return []byte((time.Duration(d)).String()), nil
+}
+
// Auction describes the asset of an auction and other
// relevant meta-data
type Description struct {
- Start time.Time
- End time.Time
- RoundTimeout time.Duration // Timeout per round by which all responses must have arrived
- BitLength uint8 // Length of the price encoding
- Currency string
- Type Type
- SellerPublicKey ed25519.PublicKey // Public key of the Seller
+ Start time.Time `json:"start"`
+ End time.Time `json:"end"`
+ Timeout Duration `json:"timeout"` // Timeout per round by which all responses must have arrived
+ Bitlength uint8 `json:"bitlength"` // Length of the price encoding
+ Currency string `json:"currency"`
+ Type Type `json:"type"`
+ Seller ed25519.PublicKey `json:"seller"` // Public key of the Seller
}
// The SignedAuction contains an Auction and the signature,
@@ -49,7 +65,7 @@ func (sd *SignedDescription) Verify() (bool, error) {
if e != nil {
return false, e
}
- r := ed25519.Verify(sd.SellerPublicKey, buf.Bytes(), sd.SellerSignature)
+ r := ed25519.Verify(sd.Seller, buf.Bytes(), sd.SellerSignature)
return r, nil
}
@@ -67,8 +83,8 @@ func (d *Description) validate() error {
if d == nil {
return fmt.Errorf("description is nil")
}
- if d.BitLength > MAXBITLENGTH {
- return fmt.Errorf("invalid BitLength in description: %d", d.BitLength)
+ if d.Bitlength > MAXBITLENGTH {
+ return fmt.Errorf("invalid BitLength in description: %d", d.Bitlength)
}
return nil
}
@@ -115,7 +131,6 @@ func (a *auction) Cancel() error {
return errors.New("Cancel not implemented")
}
-
// Message is called by the Bidder or Observer
// whenever a message came in for the auction via the dashboard
// or other means of communication.