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

Update zgs rpc #58

Merged
merged 1 commit into from
Sep 18, 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
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)
}
Loading