Skip to content

Commit 94ebab7

Browse files
committed
refactor: change to txhash
1 parent a181811 commit 94ebab7

File tree

5 files changed

+147
-134
lines changed

5 files changed

+147
-134
lines changed

pkg/api/postage.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,32 +100,32 @@ func (s *Service) postageCreateHandler(w http.ResponseWriter, r *http.Request) {
100100
)
101101
if err != nil {
102102
if errors.Is(err, postagecontract.ErrChainDisabled) {
103-
logger.Debug("create batch: no chain backend", "error", err)
103+
logger.Debug("create batch: no chain backend", "error", err, "txHash", txHash)
104104
logger.Error(nil, "create batch: no chain backend")
105105
jsonhttp.MethodNotAllowed(w, "no chain backend")
106106
return
107107
}
108108
if errors.Is(err, postagecontract.ErrInsufficientFunds) {
109-
logger.Debug("create batch: out of funds", "error", err)
109+
logger.Debug("create batch: out of funds", "error", err, "txHash", txHash)
110110
logger.Error(nil, "create batch: out of funds")
111111
jsonhttp.BadRequest(w, "out of funds")
112112
return
113113
}
114114
if errors.Is(err, postagecontract.ErrInvalidDepth) {
115-
logger.Debug("create batch: invalid depth", "error", err)
115+
logger.Debug("create batch: invalid depth", "error", err, "txHash", txHash)
116116
logger.Error(nil, "create batch: invalid depth")
117117
jsonhttp.BadRequest(w, "invalid depth")
118118
return
119119
}
120-
logger.Debug("create batch: create failed", "error", err)
120+
logger.Debug("create batch: create failed", "error", err, "txHash", txHash)
121121
logger.Error(nil, "create batch: create failed")
122122
jsonhttp.InternalServerError(w, "cannot create batch")
123123
return
124124
}
125125

126126
jsonhttp.Created(w, &postageCreateResponse{
127127
BatchID: batchID,
128-
TxHash: txHash,
128+
TxHash: txHash.String(),
129129
})
130130
}
131131

@@ -463,28 +463,29 @@ func (s *Service) postageTopUpHandler(w http.ResponseWriter, r *http.Request) {
463463
}
464464
hexBatchID := hex.EncodeToString(paths.BatchID)
465465

466-
_, err := s.postageContract.TopUpBatch(r.Context(), paths.BatchID, paths.Amount)
466+
txHash, err := s.postageContract.TopUpBatch(r.Context(), paths.BatchID, paths.Amount)
467467
if err != nil {
468468
if errors.Is(err, postagecontract.ErrInsufficientFunds) {
469-
logger.Debug("topup batch: out of funds", "batch_id", hexBatchID, "amount", paths.Amount, "error", err)
469+
logger.Debug("topup batch: out of funds", "batch_id", hexBatchID, "amount", paths.Amount, "error", err, "tx_hash", txHash)
470470
logger.Error(nil, "topup batch: out of funds")
471471
jsonhttp.PaymentRequired(w, "out of funds")
472472
return
473473
}
474474
if errors.Is(err, postagecontract.ErrNotImplemented) {
475-
logger.Debug("topup batch: not implemented", "error", err)
475+
logger.Debug("topup batch: not implemented", "error", err, "tx_hash", txHash)
476476
logger.Error(nil, "topup batch: not implemented")
477477
jsonhttp.NotImplemented(w, nil)
478478
return
479479
}
480-
logger.Debug("topup batch: topup failed", "batch_id", hexBatchID, "amount", paths.Amount, "error", err)
480+
logger.Debug("topup batch: topup failed", "batch_id", hexBatchID, "amount", paths.Amount, "error", err, "tx_hash", txHash)
481481
logger.Error(nil, "topup batch: topup failed")
482482
jsonhttp.InternalServerError(w, "cannot topup batch")
483483
return
484484
}
485485

486486
jsonhttp.Accepted(w, &postageCreateResponse{
487487
BatchID: paths.BatchID,
488+
TxHash: txHash.String(),
488489
})
489490
}
490491

@@ -501,27 +502,28 @@ func (s *Service) postageDiluteHandler(w http.ResponseWriter, r *http.Request) {
501502
}
502503
hexBatchID := hex.EncodeToString(paths.BatchID)
503504

504-
_, err := s.postageContract.DiluteBatch(r.Context(), paths.BatchID, paths.Depth)
505+
txHash, err := s.postageContract.DiluteBatch(r.Context(), paths.BatchID, paths.Depth)
505506
if err != nil {
506507
if errors.Is(err, postagecontract.ErrInvalidDepth) {
507-
logger.Debug("dilute batch: invalid depth", "error", err)
508+
logger.Debug("dilute batch: invalid depth", "error", err, "tx_hash", txHash)
508509
logger.Error(nil, "dilute batch: invalid depth")
509510
jsonhttp.BadRequest(w, "invalid depth")
510511
return
511512
}
512513
if errors.Is(err, postagecontract.ErrNotImplemented) {
513-
logger.Debug("dilute batch: not implemented", "error", err)
514+
logger.Debug("dilute batch: not implemented", "error", "tx_hash", txHash)
514515
logger.Error(nil, "dilute batch: not implemented")
515516
jsonhttp.NotImplemented(w, nil)
516517
return
517518
}
518-
logger.Debug("dilute batch: dilute failed", "batch_id", hexBatchID, "depth", paths.Depth, "error", err)
519+
logger.Debug("dilute batch: dilute failed", "batch_id", hexBatchID, "depth", paths.Depth, "error", err, "tx_hash", txHash)
519520
logger.Error(nil, "dilute batch: dilute failed")
520521
jsonhttp.InternalServerError(w, "cannot dilute batch")
521522
return
522523
}
523524

524525
jsonhttp.Accepted(w, &postageCreateResponse{
525526
BatchID: paths.BatchID,
527+
TxHash: txHash.String(),
526528
})
527529
}

0 commit comments

Comments
 (0)