Skip to content

Commit

Permalink
bus: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Aug 22, 2024
1 parent 8cc1e0f commit 0869172
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions bus/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,19 +947,17 @@ func (b *Bus) contractIDHandlerPOST(jc jape.Context) {
var req api.ContractAddRequest
if jc.DecodeParam("id", &id) != nil || jc.Decode(&req) != nil {
return
}
if req.Contract.ID() != id {
} else if req.Contract.ID() != id {
http.Error(jc.ResponseWriter, "contract ID mismatch", http.StatusBadRequest)
return
}
if req.TotalCost.IsZero() {
} else if req.TotalCost.IsZero() {
http.Error(jc.ResponseWriter, "TotalCost can not be zero", http.StatusBadRequest)
return
}

a, err := b.ms.AddContract(jc.Request.Context(), req.Contract, req.ContractPrice, req.TotalCost, req.StartHeight, req.State)
if jc.Check("couldn't store contract", err) == nil {
jc.Encode(a)
if jc.Check("couldn't store contract", err) != nil {
return
}

b.broadcastAction(webhooks.Event{
Expand All @@ -970,6 +968,8 @@ func (b *Bus) contractIDHandlerPOST(jc jape.Context) {
Timestamp: time.Now().UTC(),
},
})

jc.Encode(a)
}

func (b *Bus) contractIDRenewedHandlerPOST(jc jape.Context) {
Expand Down
2 changes: 1 addition & 1 deletion internal/worker/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestEventSubscriber(t *testing.T) {

// assert webhook was registered
if webhooks := w.Webhooks(); len(webhooks) != 6 {
t.Fatal("expected 5 webhooks, got", len(webhooks))
t.Fatal("expected 6 webhooks, got", len(webhooks))
}

// send the same event again
Expand Down

0 comments on commit 0869172

Please sign in to comment.