From af5b003aa10e1455496f8e5cfffbb812a96a6b57 Mon Sep 17 00:00:00 2001 From: Bo QIU <35757521+boqiu@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:04:36 +0800 Subject: [PATCH] Update zgs rpc (#58) --- node/client_zgs.go | 7 +++++++ node/types.go | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/node/client_zgs.go b/node/client_zgs.go index fae7624..9c9bd3a 100644 --- a/node/client_zgs.go +++ b/node/client_zgs.go @@ -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") diff --git a/node/types.go b/node/types.go index a1ffdf2..95a8aca 100644 --- a/node/types.go +++ b/node/types.go @@ -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" @@ -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"` } @@ -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) +}