Skip to content

Commit

Permalink
Update zgs rpc (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
boqiu authored Sep 18, 2024
1 parent 343bf21 commit af5b003
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions node/client_zgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func (c *ZgsClient) GetStatus(ctx context.Context) (status Status, err error) {
return
}

// CheckFileFinalized Call zgs_checkFileFinalized to check if specified file is finalized.
// Returns nil if file not available on storage node.
func (c *ZgsClient) CheckFileFinalized(ctx context.Context, txSeqOrRoot TxSeqOrRoot) (finalized *bool, err error) {
err = c.wrapError(c.CallContext(ctx, &finalized, "zgs_checkFileFinalized", txSeqOrRoot), "zgs_checkFileFinalized")
return
}

// GetFileInfo Call zgs_getFileInfo RPC to get the information of a file by file data root from the node.
func (c *ZgsClient) GetFileInfo(ctx context.Context, root common.Hash) (file *FileInfo, err error) {
err = c.wrapError(c.CallContext(ctx, &file, "zgs_getFileInfo", root), "zgs_getFileInfo")
Expand Down
18 changes: 18 additions & 0 deletions node/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package node

import (
"encoding/json"

"github.com/0glabs/0g-storage-client/common/shard"
"github.com/0glabs/0g-storage-client/core/merkle"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -26,6 +28,7 @@ type Status struct {
ConnectedPeers uint `json:"connectedPeers"`
LogSyncHeight uint64 `json:"logSyncHeight"`
LogSyncBlock common.Hash `json:"logSyncBlock"`
NextTxSeq uint64 `json:"nextTxSeq"`
NetworkIdentity NetworkIdentity `json:"networkIdentity"`
}

Expand Down Expand Up @@ -142,3 +145,18 @@ type LocationInfo struct {
Ip string `json:"ip"`
ShardConfig shard.ShardConfig `json:"shardConfig"`
}

// TxSeqOrRoot represents a tx seq or data root.
type TxSeqOrRoot struct {
TxSeq uint64
Root common.Hash
}

// MarshalJSON implements json.Marshaler interface.
func (t TxSeqOrRoot) MarshalJSON() ([]byte, error) {
if t.Root.Cmp(common.Hash{}) == 0 {
return json.Marshal(t.TxSeq)
}

return json.Marshal(t.Root)
}

0 comments on commit af5b003

Please sign in to comment.