Skip to content

Commit d21fa11

Browse files
authored
Remove deprecated api. (#17)
1 parent ef2ff72 commit d21fa11

File tree

7 files changed

+50
-2273
lines changed

7 files changed

+50
-2273
lines changed

api/api.go

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -65,141 +65,9 @@ func init() {
6565
docs.SwaggerInfo.BasePath = BasePath
6666
}
6767

68-
// dashboardHandler godoc
69-
//
70-
// @Summary Statistics dashboard
71-
// @Description Query statistics dashboard includes `storage fee` and `log sync height`
72-
// @Tags (deprecated)statistic
73-
// @Produce json
74-
// @Success 200 {object} api.BusinessError{Data=Dashboard}
75-
// @Failure 600 {object} api.BusinessError
76-
// @Router /statistic/dashboard [get]
77-
func dashboardHandler(c *gin.Context) {
78-
api.Wrap(dashboard)(c)
79-
}
80-
81-
// listTxStatHandler godoc
82-
//
83-
// @Summary Transaction statistics
84-
// @Description Query transaction statistics, including incremental and full data, and support querying at hourly or daily time intervals
85-
// @Tags (deprecated)statistic
86-
// @Accept json
87-
// @Produce json
88-
// @Param skip query int false "The number of skipped records, usually it's pageSize * (pageNumber - 1)" minimum(0) default(0)
89-
// @Param limit query int false "The number of records displayed on the page" minimum(1) maximum(2000) default(10)
90-
// @Param minTimestamp query int false "Timestamp in seconds"
91-
// @Param maxTimestamp query int false "Timestamp in seconds"
92-
// @Param intervalType query string false "Statistics interval" Enums(hour, day) default(day)
93-
// @Param sort query string false "Sort by timestamp" Enums(asc, desc) default(desc)
94-
// @Success 200 {object} api.BusinessError{Data=TxStatList}
95-
// @Failure 600 {object} api.BusinessError
96-
// @Router /statistic/transaction/list [get]
97-
func listTxStatHandler(c *gin.Context) {
98-
api.Wrap(listTxStat)(c)
99-
}
100-
101-
// listDataStatHandler godoc
102-
//
103-
// @Summary Data storage statistics
104-
// @Description Query data storage statistics, including incremental and full data, and support querying at hourly or daily time intervals
105-
// @Tags (deprecated)statistic
106-
// @Accept json
107-
// @Produce json
108-
// @Param skip query int false "The number of skipped records, usually it's pageSize * (pageNumber - 1)" minimum(0) default(0)
109-
// @Param limit query int false "The number of records displayed on the page" minimum(1) maximum(2000) default(10)
110-
// @Param minTimestamp query int false "Timestamp in seconds"
111-
// @Param maxTimestamp query int false "Timestamp in seconds"
112-
// @Param intervalType query string false "Statistics interval" Enums(hour, day) default(day)
113-
// @Param sort query string false "Sort by timestamp" Enums(asc, desc) default(desc)
114-
// @Success 200 {object} api.BusinessError{Data=DataStatList}
115-
// @Failure 600 {object} api.BusinessError
116-
// @Router /statistic/storage/list [get]
117-
func listDataStatHandler(c *gin.Context) {
118-
api.Wrap(listDataStat)(c)
119-
}
120-
121-
// listFeeStatHandler godoc
122-
//
123-
// @Summary fee statistics
124-
// @Description Query fee statistics, including incremental and full data, and support querying at hourly or daily time intervals
125-
// @Tags (deprecated)statistic
126-
// @Accept json
127-
// @Produce json
128-
// @Param skip query int false "The number of skipped records, usually it's pageSize * (pageNumber - 1)" minimum(0) default(0)
129-
// @Param limit query int false "The number of records displayed on the page" minimum(1) maximum(2000) default(10)
130-
// @Param minTimestamp query int false "Timestamp in seconds"
131-
// @Param maxTimestamp query int false "Timestamp in seconds"
132-
// @Param intervalType query string false "Statistics interval" Enums(hour, day) default(day)
133-
// @Param sort query string false "Sort by timestamp" Enums(asc, desc) default(desc)
134-
// @Success 200 {object} api.BusinessError{Data=FeeStatList}
135-
// @Failure 600 {object} api.BusinessError
136-
// @Router /statistic/fee/list [get]
137-
func listFeeStatHandler(c *gin.Context) {
138-
api.Wrap(listFeeStat)(c)
139-
}
140-
141-
// listTxHandler godoc
142-
//
143-
// @Summary Layer2 transaction list
144-
// @Description Query layer2 transactions, support address and root hash filter
145-
// @Tags (deprecated)transaction
146-
// @Accept json
147-
// @Produce json
148-
// @Param skip query int false "The number of skipped records, usually it's pageSize * (pageNumber - 1)" minimum(0) default(0)
149-
// @Param limit query int false "The number of records displayed on the page" minimum(1) maximum(100) default(10)
150-
// @Param address query string false "The submitter address of the uploaded file"
151-
// @Param rootHash query string false "The merkle root hash of the uploaded file"
152-
// @Success 200 {object} api.BusinessError{Data=TxList}
153-
// @Failure 600 {object} api.BusinessError
154-
// @Router /transaction/list [get]
155-
func listTxHandler(c *gin.Context) {
156-
api.Wrap(listTx)(c)
157-
}
158-
159-
// getTxBriefHandler godoc
160-
//
161-
// @Summary Layer2 transaction overview
162-
// @Description Query layer2 transaction overview by txSeq
163-
// @Tags (deprecated)transaction
164-
// @Accept json
165-
// @Produce json
166-
// @Param txSeq query string true "Lay2 transaction sequence number"
167-
// @Success 200 {object} api.BusinessError{Data=TxBrief}
168-
// @Failure 600 {object} api.BusinessError
169-
// @Router /transaction/brief [get]
170-
func getTxBriefHandler(c *gin.Context) {
171-
api.Wrap(getTxBrief)(c)
172-
}
173-
174-
// getTxDetailHandler godoc
175-
//
176-
// @Summary Layer2 transaction advanced info
177-
// @Description Query layer2 transaction advanced info by txSeq
178-
// @Tags (deprecated)transaction
179-
// @Accept json
180-
// @Produce json
181-
// @Param txSeq query string true "Lay2 transaction sequence number"
182-
// @Success 200 {object} api.BusinessError{Data=TxDetail}
183-
// @Failure 600 {object} api.BusinessError
184-
// @Router /transaction/detail [get]
185-
func getTxDetailHandler(c *gin.Context) {
186-
api.Wrap(getTxDetail)(c)
187-
}
188-
18968
func RegisterRouter(router *gin.Engine) {
19069
apiRoute := router.Group(BasePath)
19170

192-
statRoute := apiRoute.Group("/statistic")
193-
statRoute.GET("dashboard", dashboardHandler)
194-
statRoute.GET("transaction/list", listTxStatHandler)
195-
statRoute.GET("storage/list", listDataStatHandler)
196-
statRoute.GET("fee/list", listFeeStatHandler)
197-
198-
txRoute := apiRoute.Group("/transaction")
199-
txRoute.GET("list", listTxHandler)
200-
txRoute.GET("brief", getTxBriefHandler)
201-
txRoute.GET("detail", getTxDetailHandler)
202-
20371
statsRoute := apiRoute.Group("/stats")
20472
statsRoute.GET("summary", summaryHandler)
20573
statsRoute.GET("layer1-tx", listTxStatsHandler)

api/stat_api.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,6 @@ const (
1717
FeeStatType
1818
)
1919

20-
func dashboard(_ *gin.Context) (interface{}, error) {
21-
value, exist, err := db.ConfigStore.Get(store.KeyLogSyncInfo)
22-
if err != nil {
23-
return nil, commonApi.ErrInternal(err)
24-
}
25-
if !exist {
26-
return nil, ErrConfigNotFound
27-
}
28-
29-
var logSyncInfo stat.LogSyncInfo
30-
if err := json.Unmarshal([]byte(value), &logSyncInfo); err != nil {
31-
return nil, commonApi.ErrInternal(err)
32-
}
33-
34-
submitStat, err := db.SubmitStatStore.LastByType(store.Day)
35-
if err != nil {
36-
return nil, commonApi.ErrInternal(err)
37-
}
38-
if submitStat == nil {
39-
return nil, ErrStorageBaseFeeNotStat
40-
}
41-
42-
storageBasicCost := StorageBasicCost{
43-
TokenInfo: *chargeToken,
44-
BasicCostTotal: submitStat.BaseFeeTotal,
45-
}
46-
result := Dashboard{
47-
StorageBasicCost: storageBasicCost,
48-
LogSyncInfo: logSyncInfo,
49-
}
50-
51-
return result, nil
52-
}
53-
5420
func listDataStat(c *gin.Context) (interface{}, error) {
5521
return getSubmitStatByType(c, StorageStatType)
5622
}

api/tx_api.go

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"strconv"
66

7-
"github.com/0glabs/0g-storage-client/core"
87
"github.com/0glabs/0g-storage-scan/store"
98
commonApi "github.com/Conflux-Chain/go-conflux-util/api"
109
"github.com/ethereum/go-ethereum/common"
@@ -13,150 +12,6 @@ import (
1312
"github.com/sirupsen/logrus"
1413
)
1514

16-
func listTx(c *gin.Context) (interface{}, error) {
17-
var param listTxParam
18-
if err := c.ShouldBind(&param); err != nil {
19-
return nil, err
20-
}
21-
22-
var addrIDPtr *uint64
23-
if param.Address != nil {
24-
addr, exist, err := db.AddressStore.Get(*param.Address)
25-
if err != nil {
26-
return nil, commonApi.ErrInternal(err)
27-
}
28-
if !exist {
29-
return TxList{}, nil
30-
}
31-
addrIDPtr = &addr.ID
32-
}
33-
34-
total, submits, err := listSubmits(addrIDPtr, param.RootHash, param.isDesc(), param.Skip, param.Limit)
35-
if err != nil {
36-
return nil, err
37-
}
38-
39-
addrIDs := make([]uint64, 0)
40-
for _, submit := range submits {
41-
addrIDs = append(addrIDs, submit.SenderID)
42-
}
43-
addrMap, err := db.BatchGetAddresses(addrIDs)
44-
if err != nil {
45-
return nil, err
46-
}
47-
48-
storageTxs := make([]StorageTx, 0)
49-
for _, submit := range submits {
50-
storageTx := StorageTx{
51-
TxSeq: submit.SubmissionIndex,
52-
BlockNum: submit.BlockNumber,
53-
TxHash: submit.TxHash,
54-
RootHash: submit.RootHash,
55-
Address: addrMap[submit.SenderID].Address,
56-
Method: "submit",
57-
Status: submit.Status,
58-
Timestamp: submit.BlockTime.Unix(),
59-
DataSize: submit.Length,
60-
BaseFee: submit.Fee,
61-
}
62-
storageTxs = append(storageTxs, storageTx)
63-
}
64-
65-
return TxList{
66-
Total: total,
67-
List: storageTxs,
68-
}, nil
69-
}
70-
71-
func getTxBrief(c *gin.Context) (interface{}, error) {
72-
var param queryTxParam
73-
if err := c.ShouldBind(&param); err != nil {
74-
return nil, err
75-
}
76-
77-
var submit store.Submit
78-
exist, err := db.Store.Exists(&submit, "submission_index = ?", param.TxSeq)
79-
if err != nil {
80-
logrus.WithError(err).Error("Failed to query databases")
81-
return nil, errors.Errorf("Biz error, txSeq %v", *param.TxSeq)
82-
}
83-
if !exist {
84-
return nil, errors.Errorf("Record not found, txSeq %v", *param.TxSeq)
85-
}
86-
87-
addrIDs := []uint64{submit.SenderID}
88-
addrMap, err := db.BatchGetAddresses(addrIDs)
89-
if err != nil {
90-
return nil, err
91-
}
92-
93-
result := TxBrief{
94-
TxSeq: strconv.FormatUint(submit.SubmissionIndex, 10),
95-
From: addrMap[submit.SenderID].Address,
96-
Method: "submit",
97-
RootHash: submit.RootHash,
98-
Status: submit.Status,
99-
DataSize: submit.Length,
100-
CostInfo: &CostInfo{
101-
TokenInfo: *chargeToken,
102-
BasicCost: submit.Fee,
103-
},
104-
BlockNumber: submit.BlockNumber,
105-
TxHash: submit.TxHash,
106-
Timestamp: uint64(submit.BlockTime.Unix()),
107-
}
108-
109-
hash := common.HexToHash(submit.TxHash)
110-
tx, err := sdk.Eth.TransactionByHash(hash)
111-
if err != nil {
112-
logrus.WithError(err).WithField("txSeq", param.TxSeq).Error("Failed to get transaction")
113-
return nil, errors.Errorf("Get tx error, txSeq %v", param.TxSeq)
114-
}
115-
rcpt, err := sdk.Eth.TransactionReceipt(hash)
116-
if err != nil {
117-
logrus.WithError(err).WithField("txSeq", param.TxSeq).Error("Failed to get receipt")
118-
return nil, errors.Errorf("Get receitp error, txSeq %v", param.TxSeq)
119-
}
120-
result.GasFee = tx.GasPrice.Uint64() * rcpt.GasUsed
121-
result.GasUsed = rcpt.GasUsed
122-
result.GasLimit = tx.Gas
123-
124-
return result, nil
125-
}
126-
127-
func getTxDetail(c *gin.Context) (interface{}, error) {
128-
var param queryTxParam
129-
if err := c.ShouldBind(&param); err != nil {
130-
return nil, err
131-
}
132-
133-
var submit store.Submit
134-
exist, err := db.Exists(&submit, "submission_index = ?", param.TxSeq)
135-
if err != nil {
136-
logrus.WithError(err).Error("Failed to query databases")
137-
return nil, errors.Errorf("Biz error, txSeq %v", *param.TxSeq)
138-
}
139-
if !exist {
140-
return nil, errors.Errorf("Record not found, txSeq %v", *param.TxSeq)
141-
}
142-
143-
var extra store.SubmitExtra
144-
if err := json.Unmarshal(submit.Extra, &extra); err != nil {
145-
logrus.WithError(err).Error("Failed to unmarshal submit extra")
146-
return nil, errors.Errorf("Unmarshal submit extra error, txSeq %v", *param.TxSeq)
147-
}
148-
149-
result := TxDetail{
150-
TxSeq: strconv.FormatUint(submit.SubmissionIndex, 10),
151-
RootHash: submit.RootHash,
152-
StartPos: extra.StartPos.Uint64(),
153-
EndPos: extra.StartPos.Uint64() + submit.Length,
154-
PieceCounts: (submit.Length-1)/core.DefaultSegmentSize + 1,
155-
}
156-
157-
return result, nil
158-
}
159-
16015
func listSubmits(addressID *uint64, rootHash *string, idDesc bool, skip, limit int) (int64, []store.Submit, error) {
16116
if addressID == nil {
16217
return db.SubmitStore.List(rootHash, idDesc, skip, limit)

0 commit comments

Comments
 (0)