From 2062fc663f73318274ed71db6fc4fedc7fb5e6c9 Mon Sep 17 00:00:00 2001 From: Ivan Folgueira Bande Date: Tue, 24 Sep 2024 10:34:22 +0200 Subject: [PATCH] add missing shard.go --- wakuv2/shard.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 wakuv2/shard.go diff --git a/wakuv2/shard.go b/wakuv2/shard.go new file mode 100644 index 000000000..fc8686755 --- /dev/null +++ b/wakuv2/shard.go @@ -0,0 +1,59 @@ +package wakuv2 + +import ( + wakuproto "github.com/waku-org/go-waku/waku/v2/protocol" + + "github.com/status-im/status-go/protocol/protobuf" +) + +type Shard struct { + Cluster uint16 `json:"cluster"` + Index uint16 `json:"index"` +} + +func FromProtobuff(p *protobuf.Shard) *Shard { + if p == nil { + return nil + } + + return &Shard{ + Cluster: uint16(p.Cluster), + Index: uint16(p.Index), + } +} + +func (s *Shard) Protobuffer() *protobuf.Shard { + if s == nil { + return nil + } + + return &protobuf.Shard{ + Cluster: int32(s.Cluster), + Index: int32(s.Index), + } +} +func (s *Shard) PubsubTopic() string { + if s != nil { + return wakuproto.NewStaticShardingPubsubTopic(s.Cluster, s.Index).String() + } + return "" +} + +const MainStatusShardCluster = 16 +const DefaultShardIndex = 32 +const NonProtectedShardIndex = 64 + +func DefaultShardPubsubTopic() string { + return wakuproto.NewStaticShardingPubsubTopic(MainStatusShardCluster, DefaultShardIndex).String() +} + +func DefaultNonProtectedShard() *Shard { + return &Shard{ + Cluster: MainStatusShardCluster, + Index: NonProtectedShardIndex, + } +} + +func DefaultNonProtectedPubsubTopic() string { + return DefaultNonProtectedShard().PubsubTopic() +}