Skip to content

Commit 5448b0b

Browse files
authored
Refine file status. (#15)
1 parent 5c209e3 commit 5448b0b

File tree

9 files changed

+457
-188
lines changed

9 files changed

+457
-188
lines changed

api/tx_api.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package api
22

33
import (
4-
"encoding/hex"
54
"encoding/json"
65
"strconv"
76

7+
"github.com/0glabs/0g-storage-client/core"
88
"github.com/0glabs/0g-storage-scan/store"
99
commonApi "github.com/Conflux-Chain/go-conflux-util/api"
1010
"github.com/ethereum/go-ethereum/common"
@@ -48,16 +48,18 @@ func listTx(c *gin.Context) (interface{}, error) {
4848
storageTxs := make([]StorageTx, 0)
4949
for _, submit := range submits {
5050
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,
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+
TotalSegNum: submit.TotalSegNum,
59+
UploadedSegNum: submit.UploadedSegNum,
60+
Timestamp: submit.BlockTime.Unix(),
61+
DataSize: submit.Length,
62+
BaseFee: submit.Fee,
6163
}
6264
storageTxs = append(storageTxs, storageTx)
6365
}
@@ -146,21 +148,12 @@ func getTxDetail(c *gin.Context) (interface{}, error) {
146148
return nil, errors.Errorf("Unmarshal submit extra error, txSeq %v", *param.TxSeq)
147149
}
148150

149-
nodes := make([]SubmissionNode, 0)
150-
for _, n := range extra.Submission.Nodes {
151-
nodes = append(nodes, SubmissionNode{
152-
Root: "0x" + hex.EncodeToString(n.Root[:]),
153-
Height: n.Height,
154-
})
155-
}
156-
157151
result := TxDetail{
158152
TxSeq: strconv.FormatUint(submit.SubmissionIndex, 10),
159153
RootHash: submit.RootHash,
160154
StartPos: extra.StartPos.Uint64(),
161155
EndPos: extra.StartPos.Uint64() + submit.Length,
162-
PieceCounts: uint64(len(nodes)),
163-
Pieces: nodes,
156+
PieceCounts: (submit.Length-1)/core.DefaultSegmentSize + 1,
164157
}
165158

166159
return result, nil
@@ -187,6 +180,8 @@ func listSubmits(addressID *uint64, rootHash *string, idDesc bool, skip, limit i
187180
BlockTime: as.BlockTime,
188181
TxHash: as.TxHash,
189182
Status: as.Status,
183+
TotalSegNum: as.TotalSegNum,
184+
UploadedSegNum: as.UploadedSegNum,
190185
Fee: as.Fee,
191186
})
192187
}

api/types.go

Lines changed: 94 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package api
22

33
import (
4-
"math/big"
54
"strings"
65
"time"
76

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

43+
// StorageTx model info
44+
// @Description Submission information
4445
type StorageTx struct {
45-
TxSeq uint64 `json:"txSeq"`
46-
BlockNum uint64 `json:"blockNum"`
47-
TxHash string `json:"txHash"`
48-
RootHash string `json:"rootHash"`
49-
Address string `json:"address"`
50-
Method string `json:"method"`
51-
Status uint64 `json:"status"`
52-
Timestamp int64 `json:"timestamp"`
53-
DataSize uint64 `json:"dataSize"`
54-
BaseFee decimal.Decimal `json:"baseFee"`
55-
}
56-
46+
TxSeq uint64 `json:"txSeq"` // Submission index in submit event
47+
BlockNum uint64 `json:"blockNum"` // The block where the submit event is emitted
48+
TxHash string `json:"txHash"` // The transaction where the submit event is emitted
49+
RootHash string `json:"rootHash"` // Merkle root of the file to upload
50+
Address string `json:"address"` // File uploader address
51+
Method string `json:"method"` // The name of the submit event is always `submit`
52+
Status uint8 `json:"status"` // File upload status, 0-not uploaded,1-uploading,2-uploaded
53+
TotalSegNum uint64 `json:"totalSegNum"` // The total number of segments the file is split into
54+
UploadedSegNum uint64 `json:"uploadedSegNum"` // The number of segments the file has been uploaded
55+
Timestamp int64 `json:"timestamp"` // The block time when submit event emits
56+
DataSize uint64 `json:"dataSize"` // File size in bytes
57+
BaseFee decimal.Decimal `json:"baseFee"` // The token fee required to upload the file
58+
}
59+
60+
// TokenInfo model info
61+
// @Description Charge token information
5762
type TokenInfo struct {
58-
Address string `json:"address"`
59-
Name string `json:"name"`
60-
Symbol string `json:"symbol"`
61-
Decimals uint8 `json:"decimals"`
63+
Address string `json:"address"` // The address of the token contract
64+
Name string `json:"name"` // Token name
65+
Symbol string `json:"symbol"` // Token symbol
66+
Decimals uint8 `json:"decimals"` // Token decimals
6267
}
6368

69+
// CostInfo model info
70+
// @Description Charge fee information
6471
type CostInfo struct {
65-
TokenInfo `json:"tokenInfo"`
66-
BasicCost decimal.Decimal `json:"basicCost"`
67-
}
68-
69-
type SubmissionNode struct {
70-
Root string `json:"root"`
71-
Height *big.Int `json:"height"`
72+
TokenInfo `json:"tokenInfo"` // Charge token info
73+
BasicCost decimal.Decimal `json:"basicCost"` // Charge fee
7274
}
7375

76+
// TxList model info
77+
// @Description Submission information list
7478
type TxList struct {
75-
Total int64 `json:"total"`
76-
List []StorageTx `json:"list"`
79+
Total int64 `json:"total"` // The total number of submission returned
80+
List []StorageTx `json:"list"` // Submission list
7781
}
7882

83+
// TxBrief model info
84+
// @Description Submission brief information
7985
type TxBrief struct {
80-
TxSeq string `json:"txSeq"`
81-
From string `json:"from"`
82-
Method string `json:"method"`
83-
84-
RootHash string `json:"rootHash"`
85-
DataSize uint64 `json:"dataSize"`
86-
Expiration uint64 `json:"expiration"`
87-
CostInfo *CostInfo `json:"costInfo"`
88-
89-
BlockNumber uint64 `json:"blockNumber"`
90-
TxHash string `json:"txHash"`
91-
Timestamp uint64 `json:"timestamp"`
92-
Status uint64 `json:"status"`
93-
GasFee uint64 `json:"gasFee"`
94-
GasUsed uint64 `json:"gasUsed"`
95-
GasLimit uint64 `json:"gasLimit"`
96-
}
97-
86+
TxSeq string `json:"txSeq"` // Submission index in submit event
87+
From string `json:"from"` // File uploader address
88+
Method string `json:"method"` // The name of the submit event is always `submit`
89+
90+
RootHash string `json:"rootHash"` // Merkle root of the file to upload
91+
DataSize uint64 `json:"dataSize"` // File size in bytes
92+
Expiration uint64 `json:"expiration"` // Expiration date of the uploaded file
93+
CostInfo *CostInfo `json:"costInfo"` // Charge fee information
94+
95+
BlockNumber uint64 `json:"blockNumber"` // The block where the submit event is emitted
96+
TxHash string `json:"txHash"` // The transaction where the submit event is emitted
97+
Timestamp uint64 `json:"timestamp"` // The block time when submit event emits
98+
Status uint8 `json:"status"` // The status of the transaction on layer1
99+
GasFee uint64 `json:"gasFee"` // The gas fee of the transaction on layer1
100+
GasUsed uint64 `json:"gasUsed"` // The gas used of the transaction on layer1
101+
GasLimit uint64 `json:"gasLimit"` // The gas limit of the transaction on layer1
102+
}
103+
104+
// TxDetail model info
105+
// @Description Submission detail information
98106
type TxDetail struct {
99-
TxSeq string `json:"txSeq"`
100-
RootHash string `json:"rootHash"`
107+
TxSeq string `json:"txSeq"` // Submission index in submit event
108+
RootHash string `json:"rootHash"` // Merkle root of the file to upload
101109

102-
StartPos uint64 `json:"startPos"`
103-
EndPos uint64 `json:"endPos"`
104-
PieceCounts uint64 `json:"pieceCounts"`
105-
Pieces []SubmissionNode `json:"pieces"`
110+
StartPos uint64 `json:"startPos"` // The starting position of the file stored in the storage node
111+
EndPos uint64 `json:"endPos"` // The ending position of the file stored in the storage node
112+
PieceCounts uint64 `json:"pieceCounts"` // The total number of segments the file is split into
106113
}
107114

115+
// StorageBasicCost model info
116+
// @Description Storage fee information
108117
type StorageBasicCost struct {
109-
TokenInfo
110-
BasicCostTotal decimal.Decimal `json:"basicCostTotal"`
118+
TokenInfo // Charge token info
119+
BasicCostTotal decimal.Decimal `json:"basicCostTotal"` // Total storage fee
111120
}
112121

122+
// Dashboard model info
123+
// @Description Storage status information
113124
type Dashboard struct {
114-
StorageBasicCost `json:"storageBasicCost"`
115-
stat.LogSyncInfo `json:"logSyncInfo"`
125+
StorageBasicCost `json:"storageBasicCost"` // Storage fee information
126+
stat.LogSyncInfo `json:"logSyncInfo"` // Synchronization information of submit event
116127
}
117128

129+
// DataStatList model info
130+
// @Description Storage data list
118131
type DataStatList struct {
119-
Total int64 `json:"total"`
120-
List []DataStat `json:"list"`
132+
Total int64 `json:"total"` // The total number of stat returned
133+
List []DataStat `json:"list"` // Stat list
121134
}
122135

136+
// TxStatList model info
137+
// @Description Storage transaction list
123138
type TxStatList struct {
124-
Total int64 `json:"total"`
125-
List []TxStat `json:"list"`
139+
Total int64 `json:"total"` // The total number of stat returned
140+
List []TxStat `json:"list"` // Stat list
126141
}
127142

143+
// FeeStatList model info
144+
// @Description Storage fee list
128145
type FeeStatList struct {
129-
Total int64 `json:"total"`
130-
List []FeeStat `json:"list"`
146+
Total int64 `json:"total"` // The total number of stat returned
147+
List []FeeStat `json:"list"` // Stat list
131148
}
132149

150+
// DataStat model info
151+
// @Description Storage data information
133152
type DataStat struct {
134-
StatTime time.Time `json:"statTime"`
135-
FileCount uint64 `json:"fileCount"`
136-
FileTotal uint64 `json:"fileTotal"`
137-
DataSize uint64 `json:"dataSize"`
138-
DataTotal uint64 `json:"dataTotal"`
153+
StatTime time.Time `json:"statTime"` // Statistics time
154+
FileCount uint64 `json:"fileCount"` // Number of files in a specific time interval
155+
FileTotal uint64 `json:"fileTotal"` // Total number of files by a certain time
156+
DataSize uint64 `json:"dataSize"` // Size of storage data in a specific time interval
157+
DataTotal uint64 `json:"dataTotal"` // Total Size of storage data by a certain time
139158
}
140159

160+
// TxStat model info
161+
// @Description Storage transaction information
141162
type TxStat struct {
142-
StatTime time.Time `json:"statTime"`
143-
TxCount uint64 `json:"txCount"`
144-
TxTotal uint64 `json:"txTotal"`
163+
StatTime time.Time `json:"statTime"` // Statistics time
164+
TxCount uint64 `json:"txCount"` // Number of layer1 transaction in a specific time interval
165+
TxTotal uint64 `json:"txTotal"` // Total number of layer1 transaction by a certain time
145166
}
146167

168+
// FeeStat model info
169+
// @Description Storage fee information
147170
type FeeStat struct {
148-
StatTime time.Time `json:"statTime"`
149-
BaseFee decimal.Decimal `json:"baseFee"`
150-
BaseFeeTotal decimal.Decimal `json:"baseFeeTotal"`
171+
StatTime time.Time `json:"statTime"` // Statistics time
172+
BaseFee decimal.Decimal `json:"baseFee"` // The base fee for storage in a specific time interval
173+
BaseFeeTotal decimal.Decimal `json:"baseFeeTotal"` // The total base fee for storage by a certain time
151174
}

0 commit comments

Comments
 (0)