Skip to content

Commit

Permalink
fix: asd
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Nov 2, 2023
1 parent 5225470 commit 8c64604
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions pkg/api/postage.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,21 @@ type bucketData struct {
func (s *Service) postageGetStampsHandler(w http.ResponseWriter, r *http.Request) {
logger := s.logger.WithName("get_stamps").Build()

queries := struct {
All bool `map:"all"`
}{}
if response := s.mapStructure(r.URL.Query(), &queries); response != nil {
response("invalid query params", logger, w)
return
}

resp := postageStampsResponse{}
stampIssuers := s.post.StampIssuers()
resp.Stamps = make([]postageStampResponse, 0, len(stampIssuers))
for _, v := range stampIssuers {

exists, err := s.batchStore.Exists(v.ID())
if err != nil {
logger.Debug("get stamp issuer: check batch failed", "batch_id", hex.EncodeToString(v.ID()), "error", err)
logger.Error(nil, "get stamp issuer: check batch failed")
jsonhttp.InternalServerError(w, "unable to check batch")
return
}
if !exists {
continue
}

batchTTL, err := s.estimateBatchTTLFromID(v.ID())
if err != nil {
Expand All @@ -203,21 +199,20 @@ func (s *Service) postageGetStampsHandler(w http.ResponseWriter, r *http.Request
jsonhttp.InternalServerError(w, "unable to estimate batch expiration")
return
}
if exists {
resp.Stamps = append(resp.Stamps, postageStampResponse{
BatchID: v.ID(),
Utilization: v.Utilization(),
Usable: exists && s.post.IssuerUsable(v),
Label: v.Label(),
Depth: v.Depth(),
Amount: bigint.Wrap(v.Amount()),
BucketDepth: v.BucketDepth(),
BlockNumber: v.BlockNumber(),
ImmutableFlag: v.ImmutableFlag(),
Exists: exists,
BatchTTL: batchTTL,
})
}

resp.Stamps = append(resp.Stamps, postageStampResponse{
BatchID: v.ID(),
Utilization: v.Utilization(),
Usable: s.post.IssuerUsable(v),
Label: v.Label(),
Depth: v.Depth(),
Amount: bigint.Wrap(v.Amount()),
BucketDepth: v.BucketDepth(),
BlockNumber: v.BlockNumber(),
ImmutableFlag: v.ImmutableFlag(),
Exists: true,
BatchTTL: batchTTL,
})
}

jsonhttp.OK(w, resp)
Expand Down Expand Up @@ -337,6 +332,12 @@ func (s *Service) postageGetStampHandler(w http.ResponseWriter, r *http.Request)
jsonhttp.InternalServerError(w, "unable to check batch")
return
}
if !exists {
logger.Debug("batch does not exists", "batch_id", hexBatchID)
jsonhttp.NotFound(w, "issuer does not exist")
return
}

batchTTL, err := s.estimateBatchTTLFromID(paths.BatchID)
if err != nil {
logger.Debug("estimate batch expiration failed", "batch_id", hexBatchID, "error", err)
Expand All @@ -350,10 +351,10 @@ func (s *Service) postageGetStampHandler(w http.ResponseWriter, r *http.Request)
Depth: issuer.Depth(),
BucketDepth: issuer.BucketDepth(),
ImmutableFlag: issuer.ImmutableFlag(),
Exists: exists,
Exists: true,
BatchTTL: batchTTL,
Utilization: issuer.Utilization(),
Usable: exists && s.post.IssuerUsable(issuer),
Usable: s.post.IssuerUsable(issuer),
Label: issuer.Label(),
Amount: bigint.Wrap(issuer.Amount()),
BlockNumber: issuer.BlockNumber(),
Expand Down

0 comments on commit 8c64604

Please sign in to comment.