Skip to content

Commit

Permalink
Remove deprecated api. (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeric authored Apr 2, 2024
1 parent ef2ff72 commit d21fa11
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2,273 deletions.
132 changes: 0 additions & 132 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,141 +65,9 @@ func init() {
docs.SwaggerInfo.BasePath = BasePath
}

// dashboardHandler godoc
//
// @Summary Statistics dashboard
// @Description Query statistics dashboard includes `storage fee` and `log sync height`
// @Tags (deprecated)statistic
// @Produce json
// @Success 200 {object} api.BusinessError{Data=Dashboard}
// @Failure 600 {object} api.BusinessError
// @Router /statistic/dashboard [get]
func dashboardHandler(c *gin.Context) {
api.Wrap(dashboard)(c)
}

// listTxStatHandler godoc
//
// @Summary Transaction statistics
// @Description Query transaction statistics, including incremental and full data, and support querying at hourly or daily time intervals
// @Tags (deprecated)statistic
// @Accept json
// @Produce json
// @Param skip query int false "The number of skipped records, usually it's pageSize * (pageNumber - 1)" minimum(0) default(0)
// @Param limit query int false "The number of records displayed on the page" minimum(1) maximum(2000) default(10)
// @Param minTimestamp query int false "Timestamp in seconds"
// @Param maxTimestamp query int false "Timestamp in seconds"
// @Param intervalType query string false "Statistics interval" Enums(hour, day) default(day)
// @Param sort query string false "Sort by timestamp" Enums(asc, desc) default(desc)
// @Success 200 {object} api.BusinessError{Data=TxStatList}
// @Failure 600 {object} api.BusinessError
// @Router /statistic/transaction/list [get]
func listTxStatHandler(c *gin.Context) {
api.Wrap(listTxStat)(c)
}

// listDataStatHandler godoc
//
// @Summary Data storage statistics
// @Description Query data storage statistics, including incremental and full data, and support querying at hourly or daily time intervals
// @Tags (deprecated)statistic
// @Accept json
// @Produce json
// @Param skip query int false "The number of skipped records, usually it's pageSize * (pageNumber - 1)" minimum(0) default(0)
// @Param limit query int false "The number of records displayed on the page" minimum(1) maximum(2000) default(10)
// @Param minTimestamp query int false "Timestamp in seconds"
// @Param maxTimestamp query int false "Timestamp in seconds"
// @Param intervalType query string false "Statistics interval" Enums(hour, day) default(day)
// @Param sort query string false "Sort by timestamp" Enums(asc, desc) default(desc)
// @Success 200 {object} api.BusinessError{Data=DataStatList}
// @Failure 600 {object} api.BusinessError
// @Router /statistic/storage/list [get]
func listDataStatHandler(c *gin.Context) {
api.Wrap(listDataStat)(c)
}

// listFeeStatHandler godoc
//
// @Summary fee statistics
// @Description Query fee statistics, including incremental and full data, and support querying at hourly or daily time intervals
// @Tags (deprecated)statistic
// @Accept json
// @Produce json
// @Param skip query int false "The number of skipped records, usually it's pageSize * (pageNumber - 1)" minimum(0) default(0)
// @Param limit query int false "The number of records displayed on the page" minimum(1) maximum(2000) default(10)
// @Param minTimestamp query int false "Timestamp in seconds"
// @Param maxTimestamp query int false "Timestamp in seconds"
// @Param intervalType query string false "Statistics interval" Enums(hour, day) default(day)
// @Param sort query string false "Sort by timestamp" Enums(asc, desc) default(desc)
// @Success 200 {object} api.BusinessError{Data=FeeStatList}
// @Failure 600 {object} api.BusinessError
// @Router /statistic/fee/list [get]
func listFeeStatHandler(c *gin.Context) {
api.Wrap(listFeeStat)(c)
}

// listTxHandler godoc
//
// @Summary Layer2 transaction list
// @Description Query layer2 transactions, support address and root hash filter
// @Tags (deprecated)transaction
// @Accept json
// @Produce json
// @Param skip query int false "The number of skipped records, usually it's pageSize * (pageNumber - 1)" minimum(0) default(0)
// @Param limit query int false "The number of records displayed on the page" minimum(1) maximum(100) default(10)
// @Param address query string false "The submitter address of the uploaded file"
// @Param rootHash query string false "The merkle root hash of the uploaded file"
// @Success 200 {object} api.BusinessError{Data=TxList}
// @Failure 600 {object} api.BusinessError
// @Router /transaction/list [get]
func listTxHandler(c *gin.Context) {
api.Wrap(listTx)(c)
}

// getTxBriefHandler godoc
//
// @Summary Layer2 transaction overview
// @Description Query layer2 transaction overview by txSeq
// @Tags (deprecated)transaction
// @Accept json
// @Produce json
// @Param txSeq query string true "Lay2 transaction sequence number"
// @Success 200 {object} api.BusinessError{Data=TxBrief}
// @Failure 600 {object} api.BusinessError
// @Router /transaction/brief [get]
func getTxBriefHandler(c *gin.Context) {
api.Wrap(getTxBrief)(c)
}

// getTxDetailHandler godoc
//
// @Summary Layer2 transaction advanced info
// @Description Query layer2 transaction advanced info by txSeq
// @Tags (deprecated)transaction
// @Accept json
// @Produce json
// @Param txSeq query string true "Lay2 transaction sequence number"
// @Success 200 {object} api.BusinessError{Data=TxDetail}
// @Failure 600 {object} api.BusinessError
// @Router /transaction/detail [get]
func getTxDetailHandler(c *gin.Context) {
api.Wrap(getTxDetail)(c)
}

func RegisterRouter(router *gin.Engine) {
apiRoute := router.Group(BasePath)

statRoute := apiRoute.Group("/statistic")
statRoute.GET("dashboard", dashboardHandler)
statRoute.GET("transaction/list", listTxStatHandler)
statRoute.GET("storage/list", listDataStatHandler)
statRoute.GET("fee/list", listFeeStatHandler)

txRoute := apiRoute.Group("/transaction")
txRoute.GET("list", listTxHandler)
txRoute.GET("brief", getTxBriefHandler)
txRoute.GET("detail", getTxDetailHandler)

statsRoute := apiRoute.Group("/stats")
statsRoute.GET("summary", summaryHandler)
statsRoute.GET("layer1-tx", listTxStatsHandler)
Expand Down
34 changes: 0 additions & 34 deletions api/stat_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,6 @@ const (
FeeStatType
)

func dashboard(_ *gin.Context) (interface{}, error) {
value, exist, err := db.ConfigStore.Get(store.KeyLogSyncInfo)
if err != nil {
return nil, commonApi.ErrInternal(err)
}
if !exist {
return nil, ErrConfigNotFound
}

var logSyncInfo stat.LogSyncInfo
if err := json.Unmarshal([]byte(value), &logSyncInfo); err != nil {
return nil, commonApi.ErrInternal(err)
}

submitStat, err := db.SubmitStatStore.LastByType(store.Day)
if err != nil {
return nil, commonApi.ErrInternal(err)
}
if submitStat == nil {
return nil, ErrStorageBaseFeeNotStat
}

storageBasicCost := StorageBasicCost{
TokenInfo: *chargeToken,
BasicCostTotal: submitStat.BaseFeeTotal,
}
result := Dashboard{
StorageBasicCost: storageBasicCost,
LogSyncInfo: logSyncInfo,
}

return result, nil
}

func listDataStat(c *gin.Context) (interface{}, error) {
return getSubmitStatByType(c, StorageStatType)
}
Expand Down
145 changes: 0 additions & 145 deletions api/tx_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"strconv"

"github.com/0glabs/0g-storage-client/core"
"github.com/0glabs/0g-storage-scan/store"
commonApi "github.com/Conflux-Chain/go-conflux-util/api"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -13,150 +12,6 @@ import (
"github.com/sirupsen/logrus"
)

func listTx(c *gin.Context) (interface{}, error) {
var param listTxParam
if err := c.ShouldBind(&param); err != nil {
return nil, err
}

var addrIDPtr *uint64
if param.Address != nil {
addr, exist, err := db.AddressStore.Get(*param.Address)
if err != nil {
return nil, commonApi.ErrInternal(err)
}
if !exist {
return TxList{}, nil
}
addrIDPtr = &addr.ID
}

total, submits, err := listSubmits(addrIDPtr, param.RootHash, param.isDesc(), param.Skip, param.Limit)
if err != nil {
return nil, err
}

addrIDs := make([]uint64, 0)
for _, submit := range submits {
addrIDs = append(addrIDs, submit.SenderID)
}
addrMap, err := db.BatchGetAddresses(addrIDs)
if err != nil {
return nil, err
}

storageTxs := make([]StorageTx, 0)
for _, submit := range submits {
storageTx := StorageTx{
TxSeq: submit.SubmissionIndex,
BlockNum: submit.BlockNumber,
TxHash: submit.TxHash,
RootHash: submit.RootHash,
Address: addrMap[submit.SenderID].Address,
Method: "submit",
Status: submit.Status,
Timestamp: submit.BlockTime.Unix(),
DataSize: submit.Length,
BaseFee: submit.Fee,
}
storageTxs = append(storageTxs, storageTx)
}

return TxList{
Total: total,
List: storageTxs,
}, nil
}

func getTxBrief(c *gin.Context) (interface{}, error) {
var param queryTxParam
if err := c.ShouldBind(&param); err != nil {
return nil, err
}

var submit store.Submit
exist, err := db.Store.Exists(&submit, "submission_index = ?", param.TxSeq)
if err != nil {
logrus.WithError(err).Error("Failed to query databases")
return nil, errors.Errorf("Biz error, txSeq %v", *param.TxSeq)
}
if !exist {
return nil, errors.Errorf("Record not found, txSeq %v", *param.TxSeq)
}

addrIDs := []uint64{submit.SenderID}
addrMap, err := db.BatchGetAddresses(addrIDs)
if err != nil {
return nil, err
}

result := TxBrief{
TxSeq: strconv.FormatUint(submit.SubmissionIndex, 10),
From: addrMap[submit.SenderID].Address,
Method: "submit",
RootHash: submit.RootHash,
Status: submit.Status,
DataSize: submit.Length,
CostInfo: &CostInfo{
TokenInfo: *chargeToken,
BasicCost: submit.Fee,
},
BlockNumber: submit.BlockNumber,
TxHash: submit.TxHash,
Timestamp: uint64(submit.BlockTime.Unix()),
}

hash := common.HexToHash(submit.TxHash)
tx, err := sdk.Eth.TransactionByHash(hash)
if err != nil {
logrus.WithError(err).WithField("txSeq", param.TxSeq).Error("Failed to get transaction")
return nil, errors.Errorf("Get tx error, txSeq %v", param.TxSeq)
}
rcpt, err := sdk.Eth.TransactionReceipt(hash)
if err != nil {
logrus.WithError(err).WithField("txSeq", param.TxSeq).Error("Failed to get receipt")
return nil, errors.Errorf("Get receitp error, txSeq %v", param.TxSeq)
}
result.GasFee = tx.GasPrice.Uint64() * rcpt.GasUsed
result.GasUsed = rcpt.GasUsed
result.GasLimit = tx.Gas

return result, nil
}

func getTxDetail(c *gin.Context) (interface{}, error) {
var param queryTxParam
if err := c.ShouldBind(&param); err != nil {
return nil, err
}

var submit store.Submit
exist, err := db.Exists(&submit, "submission_index = ?", param.TxSeq)
if err != nil {
logrus.WithError(err).Error("Failed to query databases")
return nil, errors.Errorf("Biz error, txSeq %v", *param.TxSeq)
}
if !exist {
return nil, errors.Errorf("Record not found, txSeq %v", *param.TxSeq)
}

var extra store.SubmitExtra
if err := json.Unmarshal(submit.Extra, &extra); err != nil {
logrus.WithError(err).Error("Failed to unmarshal submit extra")
return nil, errors.Errorf("Unmarshal submit extra error, txSeq %v", *param.TxSeq)
}

result := TxDetail{
TxSeq: strconv.FormatUint(submit.SubmissionIndex, 10),
RootHash: submit.RootHash,
StartPos: extra.StartPos.Uint64(),
EndPos: extra.StartPos.Uint64() + submit.Length,
PieceCounts: (submit.Length-1)/core.DefaultSegmentSize + 1,
}

return result, nil
}

func listSubmits(addressID *uint64, rootHash *string, idDesc bool, skip, limit int) (int64, []store.Submit, error) {
if addressID == nil {
return db.SubmitStore.List(rootHash, idDesc, skip, limit)
Expand Down
Loading

0 comments on commit d21fa11

Please sign in to comment.