aboutsummaryrefslogtreecommitdiff
path: root/dashboard/inmemory.go
diff options
context:
space:
mode:
Diffstat (limited to 'dashboard/inmemory.go')
-rw-r--r--dashboard/inmemory.go57
1 files changed, 56 insertions, 1 deletions
diff --git a/dashboard/inmemory.go b/dashboard/inmemory.go
index 82412cb..0548494 100644
--- a/dashboard/inmemory.go
+++ b/dashboard/inmemory.go
@@ -24,6 +24,10 @@ type auction struct {
description *seal.SignedDescription
state AuctionState
round uint8 // which bit has been completed
+ canceled struct {
+ reason SignedMessage
+ by string // bidderId
+ }
commitments map[string]SignedCommitment
messages map[string][]SignedMessage // per-bidder and per-round messages, pre-allocated.
@@ -183,5 +187,56 @@ func (m *inmemory) Publish(auctionId string, round uint8, message SignedMessage,
}
func (m *inmemory) Messages(auctionId string, round uint8) (messages map[string]SignedMessage, e error) {
- return nil, fmt.Errorf("inmemory.Messages not implemented")
+ auction, e := m.getAuction(auctionId)
+ if e != nil {
+ return nil, e
+ }
+
+ auction.RLock()
+ defer auction.RUnlock()
+
+ if auction.round <= round {
+ return nil, ErrAuctionInvalidRound
+ }
+
+ messages = make(map[string]SignedMessage)
+ for id, msgs := range auction.messages {
+ messages[id] = msgs[round]
+ }
+
+ return messages, nil
+}
+
+func (m *inmemory) Cancel(auctionId string, reason SignedMessage, publickey ed25519.PublicKey) error {
+ if !reason.Verify(publickey) {
+ return ErrBidderIncorrectSignature
+ }
+
+ bidderId := Pub2String(publickey)
+
+ auction, e := m.getAuction(auctionId)
+ if e != nil {
+ return e
+ }
+
+ auction.Lock()
+ defer auction.Unlock()
+
+ if auction.state != AuctionStateRunning {
+ return ErrAuctionNotRunning
+ }
+
+ if _, known := auction.commitments[bidderId]; !known {
+ return ErrBidderUnknown
+ }
+
+ auction.state = AuctionStateCanceled
+ auction.canceled.reason = reason
+ auction.canceled.by = bidderId
+
+ return nil
+}
+
+func (m *inmemory) Result(auctionId string) (price uint64, winner ed25519.PublicKey, e error) {
+ return 0, nil, fmt.Errorf("Result not implemented")
} \ No newline at end of file