diff options
author | Özgür Kesim <oec@codeblau.de> | 2024-04-09 22:32:39 +0200 |
---|---|---|
committer | Özgür Kesim <oec@codeblau.de> | 2024-04-09 22:32:39 +0200 |
commit | 15283cd1bf926254fad09ae04b1e04e381966c06 (patch) | |
tree | cbb51ed5c117712f3948b7127aaadf52715045d9 /dashboard/inmemory.go | |
parent | 5759f3e45ffad8f1caffbbc68c71b0455da275cb (diff) |
dashboard: Messages and Cancel implemented
Diffstat (limited to 'dashboard/inmemory.go')
-rw-r--r-- | dashboard/inmemory.go | 57 |
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 |