aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@kesim.org>2024-11-10 17:22:54 +0100
committerÖzgür Kesim <oec@kesim.org>2024-11-10 17:22:54 +0100
commitb8a1ae8aca5e36ffa90316a66bf826e020c73ef7 (patch)
tree0be27add95d2c8ede0d3145316748a0c5a357f4e
parent9f43ed15415f5063f2d7b2e14f407875ac7bc660 (diff)
refactor: slight renaming; added (empty) doc.go to nizk
-rw-r--r--auction.go37
-rw-r--r--auction_test.go34
-rw-r--r--nizk/doc.go7
3 files changed, 64 insertions, 14 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.
diff --git a/auction_test.go b/auction_test.go
index 93d9830..04c2590 100644
--- a/auction_test.go
+++ b/auction_test.go
@@ -1,8 +1,36 @@
package seal
-import "testing"
+import (
+ "encoding/json"
+ "strings"
+ "testing"
+ "time"
+)
-func TestAuction(t *testing.T) {
+func TestParseDescription(t *testing.T) {
+ var d Description
+ var desc = `
+ {
+ "start": "2024-11-10T15:04:05Z",
+ "end": "2024-11-10T18:04:05Z",
+ "timeout": "10s",
+ "bitlength": 8,
+ "currency": "KUDOS",
+ "type": 0,
+ "seller": "1234"
+ }
+`
+ e := json.NewDecoder(strings.NewReader(desc)).
+ Decode(&d)
+ if e != nil {
+ t.Fatal(e)
+ }
-}
+ if time.Duration(d.Timeout) != 10*time.Second {
+ t.Fatalf("expected timeout 10s, but got: %v", time.Duration(d.Timeout))
+ }
+ if d.Bitlength != 8 {
+ t.Fatalf("expected bitlength %d, but got: %d", 8, d.Bitlength)
+ }
+}
diff --git a/nizk/doc.go b/nizk/doc.go
new file mode 100644
index 0000000..1df58d4
--- /dev/null
+++ b/nizk/doc.go
@@ -0,0 +1,7 @@
+package nizk
+
+/*
+
+This is an implementation of... TODO
+
+*/