Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine file status. #15

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions api/tx_api.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package api

import (
"encoding/hex"
"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 Down Expand Up @@ -48,16 +48,18 @@ func listTx(c *gin.Context) (interface{}, error) {
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,
TxSeq: submit.SubmissionIndex,
BlockNum: submit.BlockNumber,
TxHash: submit.TxHash,
RootHash: submit.RootHash,
Address: addrMap[submit.SenderID].Address,
Method: "submit",
Status: submit.Status,
TotalSegNum: submit.TotalSegNum,
UploadedSegNum: submit.UploadedSegNum,
Timestamp: submit.BlockTime.Unix(),
DataSize: submit.Length,
BaseFee: submit.Fee,
}
storageTxs = append(storageTxs, storageTx)
}
Expand Down Expand Up @@ -146,21 +148,12 @@ func getTxDetail(c *gin.Context) (interface{}, error) {
return nil, errors.Errorf("Unmarshal submit extra error, txSeq %v", *param.TxSeq)
}

nodes := make([]SubmissionNode, 0)
for _, n := range extra.Submission.Nodes {
nodes = append(nodes, SubmissionNode{
Root: "0x" + hex.EncodeToString(n.Root[:]),
Height: n.Height,
})
}

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

return result, nil
Expand All @@ -187,6 +180,8 @@ func listSubmits(addressID *uint64, rootHash *string, idDesc bool, skip, limit i
BlockTime: as.BlockTime,
TxHash: as.TxHash,
Status: as.Status,
TotalSegNum: as.TotalSegNum,
UploadedSegNum: as.UploadedSegNum,
Fee: as.Fee,
})
}
Expand Down
165 changes: 94 additions & 71 deletions api/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"math/big"
"strings"
"time"

Expand Down Expand Up @@ -41,111 +40,135 @@ type queryTxParam struct {
TxSeq *uint64 `form:"txSeq" binding:"required,number,gte=0"`
}

// StorageTx model info
// @Description Submission information
type StorageTx struct {
TxSeq uint64 `json:"txSeq"`
BlockNum uint64 `json:"blockNum"`
TxHash string `json:"txHash"`
RootHash string `json:"rootHash"`
Address string `json:"address"`
Method string `json:"method"`
Status uint64 `json:"status"`
Timestamp int64 `json:"timestamp"`
DataSize uint64 `json:"dataSize"`
BaseFee decimal.Decimal `json:"baseFee"`
}

TxSeq uint64 `json:"txSeq"` // Submission index in submit event
BlockNum uint64 `json:"blockNum"` // The block where the submit event is emitted
TxHash string `json:"txHash"` // The transaction where the submit event is emitted
RootHash string `json:"rootHash"` // Merkle root of the file to upload
Address string `json:"address"` // File uploader address
Method string `json:"method"` // The name of the submit event is always `submit`
Status uint8 `json:"status"` // File upload status, 0-not uploaded,1-uploading,2-uploaded
TotalSegNum uint64 `json:"totalSegNum"` // The total number of segments the file is split into
UploadedSegNum uint64 `json:"uploadedSegNum"` // The number of segments the file has been uploaded
Timestamp int64 `json:"timestamp"` // The block time when submit event emits
DataSize uint64 `json:"dataSize"` // File size in bytes
BaseFee decimal.Decimal `json:"baseFee"` // The token fee required to upload the file
}

// TokenInfo model info
// @Description Charge token information
type TokenInfo struct {
Address string `json:"address"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Decimals uint8 `json:"decimals"`
Address string `json:"address"` // The address of the token contract
Name string `json:"name"` // Token name
Symbol string `json:"symbol"` // Token symbol
Decimals uint8 `json:"decimals"` // Token decimals
}

// CostInfo model info
// @Description Charge fee information
type CostInfo struct {
TokenInfo `json:"tokenInfo"`
BasicCost decimal.Decimal `json:"basicCost"`
}

type SubmissionNode struct {
Root string `json:"root"`
Height *big.Int `json:"height"`
TokenInfo `json:"tokenInfo"` // Charge token info
BasicCost decimal.Decimal `json:"basicCost"` // Charge fee
}

// TxList model info
// @Description Submission information list
type TxList struct {
Total int64 `json:"total"`
List []StorageTx `json:"list"`
Total int64 `json:"total"` // The total number of submission returned
List []StorageTx `json:"list"` // Submission list
}

// TxBrief model info
// @Description Submission brief information
type TxBrief struct {
TxSeq string `json:"txSeq"`
From string `json:"from"`
Method string `json:"method"`

RootHash string `json:"rootHash"`
DataSize uint64 `json:"dataSize"`
Expiration uint64 `json:"expiration"`
CostInfo *CostInfo `json:"costInfo"`

BlockNumber uint64 `json:"blockNumber"`
TxHash string `json:"txHash"`
Timestamp uint64 `json:"timestamp"`
Status uint64 `json:"status"`
GasFee uint64 `json:"gasFee"`
GasUsed uint64 `json:"gasUsed"`
GasLimit uint64 `json:"gasLimit"`
}

TxSeq string `json:"txSeq"` // Submission index in submit event
From string `json:"from"` // File uploader address
Method string `json:"method"` // The name of the submit event is always `submit`

RootHash string `json:"rootHash"` // Merkle root of the file to upload
DataSize uint64 `json:"dataSize"` // File size in bytes
Expiration uint64 `json:"expiration"` // Expiration date of the uploaded file
CostInfo *CostInfo `json:"costInfo"` // Charge fee information

BlockNumber uint64 `json:"blockNumber"` // The block where the submit event is emitted
TxHash string `json:"txHash"` // The transaction where the submit event is emitted
Timestamp uint64 `json:"timestamp"` // The block time when submit event emits
Status uint8 `json:"status"` // The status of the transaction on layer1
GasFee uint64 `json:"gasFee"` // The gas fee of the transaction on layer1
GasUsed uint64 `json:"gasUsed"` // The gas used of the transaction on layer1
GasLimit uint64 `json:"gasLimit"` // The gas limit of the transaction on layer1
}

// TxDetail model info
// @Description Submission detail information
type TxDetail struct {
TxSeq string `json:"txSeq"`
RootHash string `json:"rootHash"`
TxSeq string `json:"txSeq"` // Submission index in submit event
RootHash string `json:"rootHash"` // Merkle root of the file to upload

StartPos uint64 `json:"startPos"`
EndPos uint64 `json:"endPos"`
PieceCounts uint64 `json:"pieceCounts"`
Pieces []SubmissionNode `json:"pieces"`
StartPos uint64 `json:"startPos"` // The starting position of the file stored in the storage node
EndPos uint64 `json:"endPos"` // The ending position of the file stored in the storage node
PieceCounts uint64 `json:"pieceCounts"` // The total number of segments the file is split into
}

// StorageBasicCost model info
// @Description Storage fee information
type StorageBasicCost struct {
TokenInfo
BasicCostTotal decimal.Decimal `json:"basicCostTotal"`
TokenInfo // Charge token info
BasicCostTotal decimal.Decimal `json:"basicCostTotal"` // Total storage fee
}

// Dashboard model info
// @Description Storage status information
type Dashboard struct {
StorageBasicCost `json:"storageBasicCost"`
stat.LogSyncInfo `json:"logSyncInfo"`
StorageBasicCost `json:"storageBasicCost"` // Storage fee information
stat.LogSyncInfo `json:"logSyncInfo"` // Synchronization information of submit event
}

// DataStatList model info
// @Description Storage data list
type DataStatList struct {
Total int64 `json:"total"`
List []DataStat `json:"list"`
Total int64 `json:"total"` // The total number of stat returned
List []DataStat `json:"list"` // Stat list
}

// TxStatList model info
// @Description Storage transaction list
type TxStatList struct {
Total int64 `json:"total"`
List []TxStat `json:"list"`
Total int64 `json:"total"` // The total number of stat returned
List []TxStat `json:"list"` // Stat list
}

// FeeStatList model info
// @Description Storage fee list
type FeeStatList struct {
Total int64 `json:"total"`
List []FeeStat `json:"list"`
Total int64 `json:"total"` // The total number of stat returned
List []FeeStat `json:"list"` // Stat list
}

// DataStat model info
// @Description Storage data information
type DataStat struct {
StatTime time.Time `json:"statTime"`
FileCount uint64 `json:"fileCount"`
FileTotal uint64 `json:"fileTotal"`
DataSize uint64 `json:"dataSize"`
DataTotal uint64 `json:"dataTotal"`
StatTime time.Time `json:"statTime"` // Statistics time
FileCount uint64 `json:"fileCount"` // Number of files in a specific time interval
FileTotal uint64 `json:"fileTotal"` // Total number of files by a certain time
DataSize uint64 `json:"dataSize"` // Size of storage data in a specific time interval
DataTotal uint64 `json:"dataTotal"` // Total Size of storage data by a certain time
}

// TxStat model info
// @Description Storage transaction information
type TxStat struct {
StatTime time.Time `json:"statTime"`
TxCount uint64 `json:"txCount"`
TxTotal uint64 `json:"txTotal"`
StatTime time.Time `json:"statTime"` // Statistics time
TxCount uint64 `json:"txCount"` // Number of layer1 transaction in a specific time interval
TxTotal uint64 `json:"txTotal"` // Total number of layer1 transaction by a certain time
}

// FeeStat model info
// @Description Storage fee information
type FeeStat struct {
StatTime time.Time `json:"statTime"`
BaseFee decimal.Decimal `json:"baseFee"`
BaseFeeTotal decimal.Decimal `json:"baseFeeTotal"`
StatTime time.Time `json:"statTime"` // Statistics time
BaseFee decimal.Decimal `json:"baseFee"` // The base fee for storage in a specific time interval
BaseFeeTotal decimal.Decimal `json:"baseFeeTotal"` // The total base fee for storage by a certain time
}
Loading
Loading