@@ -15,6 +15,7 @@ import (
15
15
16
16
rhpv2 "go.sia.tech/core/rhp/v2"
17
17
18
+ "go.sia.tech/renterd/internal/prometheus"
18
19
rhp3 "go.sia.tech/renterd/internal/rhp/v3"
19
20
20
21
ibus "go.sia.tech/renterd/internal/bus"
@@ -148,15 +149,15 @@ func (b *Bus) consensusAcceptBlock(jc jape.Context) {
148
149
}
149
150
150
151
func (b * Bus ) syncerAddrHandler (jc jape.Context ) {
151
- jc . Encode (b .s .Addr ())
152
+ api . WriteResponse ( jc , http . StatusOK , api . SyncerAddrResp (b .s .Addr () ))
152
153
}
153
154
154
155
func (b * Bus ) syncerPeersHandler (jc jape.Context ) {
155
156
var peers []string
156
157
for _ , p := range b .s .Peers () {
157
158
peers = append (peers , p .String ())
158
159
}
159
- jc . Encode (peers )
160
+ api . WriteResponse ( jc , http . StatusOK , api . SyncerPeersResp (peers ) )
160
161
}
161
162
162
163
func (b * Bus ) syncerConnectHandler (jc jape.Context ) {
@@ -172,7 +173,7 @@ func (b *Bus) consensusStateHandler(jc jape.Context) {
172
173
if jc .Check ("couldn't fetch consensus state" , err ) != nil {
173
174
return
174
175
}
175
- jc . Encode ( cs )
176
+ api . WriteResponse ( jc , http . StatusOK , cs )
176
177
}
177
178
178
179
func (b * Bus ) consensusNetworkHandler (jc jape.Context ) {
@@ -182,11 +183,11 @@ func (b *Bus) consensusNetworkHandler(jc jape.Context) {
182
183
}
183
184
184
185
func (b * Bus ) txpoolFeeHandler (jc jape.Context ) {
185
- jc . Encode (b .cm .RecommendedFee ())
186
+ api . WriteResponse ( jc , http . StatusOK , api . TxPoolResp (b .cm .RecommendedFee () ))
186
187
}
187
188
188
189
func (b * Bus ) txpoolTransactionsHandler (jc jape.Context ) {
189
- jc . Encode (b .cm .PoolTransactions ())
190
+ api . WriteResponse ( jc , http . StatusOK , api . TxPoolTxResp (b .cm .PoolTransactions () ))
190
191
}
191
192
192
193
func (b * Bus ) txpoolBroadcastHandler (jc jape.Context ) {
@@ -208,7 +209,7 @@ func (b *Bus) bucketsHandlerGET(jc jape.Context) {
208
209
if jc .Check ("couldn't list buckets" , err ) != nil {
209
210
return
210
211
}
211
- jc . Encode (resp )
212
+ api . WriteResponse ( jc , http . StatusOK , prometheus . PrometheusSlice (resp ) )
212
213
}
213
214
214
215
func (b * Bus ) bucketsHandlerPOST (jc jape.Context ) {
@@ -273,7 +274,7 @@ func (b *Bus) walletHandler(jc jape.Context) {
273
274
}
274
275
275
276
tip := b .w .Tip ()
276
- jc . Encode ( api.WalletResponse {
277
+ api . WriteResponse ( jc , http . StatusOK , api.WalletResponse {
277
278
ScanHeight : tip .Height ,
278
279
Address : address ,
279
280
Confirmed : balance .Confirmed ,
@@ -362,11 +363,15 @@ func (b *Bus) walletTransactionsHandler(jc jape.Context) {
362
363
}
363
364
}
364
365
events = filtered
366
+
367
+ var txns []api.Transaction
365
368
if limit == 0 || limit == - 1 {
366
- jc . Encode ( convertToTransactions (events [offset :]) )
369
+ txns = convertToTransactions (events [offset :])
367
370
} else {
368
- jc . Encode ( convertToTransactions (events [offset : offset + limit ]) )
371
+ txns = convertToTransactions (events [offset : offset + limit ])
369
372
}
373
+
374
+ api .WriteResponse (jc , http .StatusOK , prometheus .PrometheusSlice (txns ))
370
375
}
371
376
372
377
func (b * Bus ) walletOutputsHandler (jc jape.Context ) {
@@ -384,7 +389,7 @@ func (b *Bus) walletOutputsHandler(jc jape.Context) {
384
389
MaturityHeight : sce .MaturityHeight ,
385
390
}
386
391
}
387
- jc . Encode (elements )
392
+ api . WriteResponse ( jc , http . StatusOK , api . WalletOutputsResp (elements ) )
388
393
}
389
394
}
390
395
@@ -602,7 +607,7 @@ func (b *Bus) hostsHandlerGETDeprecated(jc jape.Context) {
602
607
if jc .Check (fmt .Sprintf ("couldn't fetch hosts %d-%d" , offset , offset + limit ), err ) != nil {
603
608
return
604
609
}
605
- jc . Encode (hosts )
610
+ api . WriteResponse ( jc , http . StatusOK , prometheus . PrometheusSlice (hosts ) )
606
611
}
607
612
608
613
func (b * Bus ) searchHostsHandlerPOST (jc jape.Context ) {
@@ -619,7 +624,7 @@ func (b *Bus) searchHostsHandlerPOST(jc jape.Context) {
619
624
if jc .Check (fmt .Sprintf ("couldn't fetch hosts %d-%d" , req .Offset , req .Offset + req .Limit ), err ) != nil {
620
625
return
621
626
}
622
- jc . Encode (hosts )
627
+ api . WriteResponse ( jc , http . StatusOK , prometheus . PrometheusSlice (hosts ) )
623
628
}
624
629
625
630
func (b * Bus ) hostsRemoveHandlerPOST (jc jape.Context ) {
@@ -711,7 +716,7 @@ func (b *Bus) contractsSpendingHandlerPOST(jc jape.Context) {
711
716
func (b * Bus ) hostsAllowlistHandlerGET (jc jape.Context ) {
712
717
allowlist , err := b .hs .HostAllowlist (jc .Request .Context ())
713
718
if jc .Check ("couldn't load allowlist" , err ) == nil {
714
- jc . Encode (allowlist )
719
+ api . WriteResponse ( jc , http . StatusOK , api . AllowListResp (allowlist ) )
715
720
}
716
721
}
717
722
@@ -731,7 +736,7 @@ func (b *Bus) hostsAllowlistHandlerPUT(jc jape.Context) {
731
736
func (b * Bus ) hostsBlocklistHandlerGET (jc jape.Context ) {
732
737
blocklist , err := b .hs .HostBlocklist (jc .Request .Context ())
733
738
if jc .Check ("couldn't load blocklist" , err ) == nil {
734
- jc . Encode (blocklist )
739
+ api . WriteResponse ( jc , http . StatusOK , api . BlockListResp (blocklist ) )
735
740
}
736
741
}
737
742
@@ -757,7 +762,7 @@ func (b *Bus) contractsHandlerGET(jc jape.Context) {
757
762
ContractSet : cs ,
758
763
})
759
764
if jc .Check ("couldn't load contracts" , err ) == nil {
760
- jc . Encode (contracts )
765
+ api . WriteResponse ( jc , http . StatusOK , prometheus . PrometheusSlice (contracts ) )
761
766
}
762
767
}
763
768
@@ -1014,7 +1019,7 @@ func (b *Bus) contractsPrunableDataHandlerGET(jc jape.Context) {
1014
1019
return contracts [i ].Prunable > contracts [j ].Prunable
1015
1020
})
1016
1021
1017
- jc . Encode ( api.ContractsPrunableDataResponse {
1022
+ api . WriteResponse ( jc , http . StatusOK , api.ContractsPrunableDataResponse {
1018
1023
Contracts : contracts ,
1019
1024
TotalPrunable : totalPrunable ,
1020
1025
TotalSize : totalSize ,
@@ -1240,7 +1245,7 @@ func (b *Bus) searchObjectsHandlerGET(jc jape.Context) {
1240
1245
if jc .Check ("couldn't list objects" , err ) != nil {
1241
1246
return
1242
1247
}
1243
- jc . Encode (keys )
1248
+ api . WriteResponse ( jc , http . StatusOK , api . SearchObjectsResp (keys ) )
1244
1249
}
1245
1250
1246
1251
func (b * Bus ) objectsHandlerGET (jc jape.Context ) {
@@ -1422,7 +1427,7 @@ func (b *Bus) slabbuffersHandlerGET(jc jape.Context) {
1422
1427
if jc .Check ("couldn't get slab buffers info" , err ) != nil {
1423
1428
return
1424
1429
}
1425
- jc . Encode (buffers )
1430
+ api . WriteResponse ( jc , http . StatusOK , api . SlabBuffersResp (buffers ) )
1426
1431
}
1427
1432
1428
1433
func (b * Bus ) objectsStatshandlerGET (jc jape.Context ) {
@@ -1434,7 +1439,7 @@ func (b *Bus) objectsStatshandlerGET(jc jape.Context) {
1434
1439
if jc .Check ("couldn't get objects stats" , err ) != nil {
1435
1440
return
1436
1441
}
1437
- jc . Encode ( info )
1442
+ api . WriteResponse ( jc , http . StatusOK , info )
1438
1443
}
1439
1444
1440
1445
func (b * Bus ) packedSlabsHandlerFetchPOST (jc jape.Context ) {
@@ -1815,7 +1820,7 @@ func (b *Bus) paramsHandlerUploadGET(jc jape.Context) {
1815
1820
uploadPacking = pus .Enabled
1816
1821
}
1817
1822
1818
- jc . Encode ( api.UploadParams {
1823
+ api . WriteResponse ( jc , http . StatusOK , api.UploadParams {
1819
1824
ContractSet : contractSet ,
1820
1825
CurrentHeight : b .cm .TipState ().Index .Height ,
1821
1826
GougingParams : gp ,
@@ -1847,7 +1852,7 @@ func (b *Bus) paramsHandlerGougingGET(jc jape.Context) {
1847
1852
if jc .Check ("could not get gouging parameters" , err ) != nil {
1848
1853
return
1849
1854
}
1850
- jc . Encode ( gp )
1855
+ api . WriteResponse ( jc , http . StatusOK , gp )
1851
1856
}
1852
1857
1853
1858
func (b * Bus ) gougingParams (ctx context.Context ) (api.GougingParams , error ) {
@@ -1883,7 +1888,7 @@ func (b *Bus) handleGETAlertsDeprecated(jc jape.Context) {
1883
1888
if jc .Check ("failed to fetch alerts" , err ) != nil {
1884
1889
return
1885
1890
}
1886
- jc . Encode (ar .Alerts )
1891
+ api . WriteResponse ( jc , http . StatusOK , prometheus . PrometheusSlice (ar .Alerts ) )
1887
1892
}
1888
1893
1889
1894
func (b * Bus ) handleGETAlerts (jc jape.Context ) {
@@ -2046,7 +2051,7 @@ func (b *Bus) contractTaxHandlerGET(jc jape.Context) {
2046
2051
}
2047
2052
2048
2053
func (b * Bus ) stateHandlerGET (jc jape.Context ) {
2049
- jc . Encode ( api.BusStateResponse {
2054
+ api . WriteResponse ( jc , http . StatusOK , api.BusStateResponse {
2050
2055
StartTime : api .TimeRFC3339 (b .startTime ),
2051
2056
BuildState : api.BuildState {
2052
2057
Version : build .Version (),
0 commit comments