2024-02-20 15:49:39 +00:00
|
|
|
package storenodes
|
|
|
|
|
|
|
|
import (
|
2024-08-16 18:24:21 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
|
2024-02-20 15:49:39 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
"github.com/status-im/status-go/services/mailservers"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Storenode is a struct that represents a storenode, it is very closely related to `mailservers.Mailserver`
|
|
|
|
type Storenode struct {
|
2024-08-16 18:24:21 +00:00
|
|
|
CommunityID types.HexBytes `json:"community_id"`
|
|
|
|
StorenodeID string `json:"storenode_id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Address multiaddr.Multiaddr `json:"address"`
|
|
|
|
Fleet string `json:"fleet"`
|
|
|
|
Version uint `json:"version"`
|
|
|
|
Clock uint64 `json:"-"` // used to sync
|
|
|
|
Removed bool `json:"-"`
|
|
|
|
DeletedAt int64 `json:"-"`
|
2024-02-20 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Storenodes []Storenode
|
|
|
|
|
|
|
|
func (m Storenodes) ToProtobuf() []*protobuf.Storenode {
|
|
|
|
result := make([]*protobuf.Storenode, 0, len(m))
|
|
|
|
for _, n := range m {
|
|
|
|
|
|
|
|
result = append(result, &protobuf.Storenode{
|
|
|
|
CommunityId: n.CommunityID,
|
|
|
|
StorenodeId: n.StorenodeID,
|
|
|
|
Name: n.Name,
|
2024-08-16 18:24:21 +00:00
|
|
|
Address: n.Address.String(),
|
2024-02-20 15:49:39 +00:00
|
|
|
Fleet: n.Fleet,
|
|
|
|
Version: uint32(n.Version),
|
|
|
|
Removed: n.Removed,
|
|
|
|
DeletedAt: n.DeletedAt,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func FromProtobuf(storenodes []*protobuf.Storenode, clock uint64) Storenodes {
|
|
|
|
result := make(Storenodes, 0, len(storenodes))
|
|
|
|
for _, s := range storenodes {
|
2024-08-16 18:24:21 +00:00
|
|
|
sAddress, err := multiaddr.NewMultiaddr(s.Address)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2024-02-20 15:49:39 +00:00
|
|
|
result = append(result, Storenode{
|
|
|
|
CommunityID: s.CommunityId,
|
|
|
|
StorenodeID: s.StorenodeId,
|
|
|
|
Name: s.Name,
|
2024-08-16 18:24:21 +00:00
|
|
|
Address: sAddress,
|
2024-02-20 15:49:39 +00:00
|
|
|
Fleet: s.Fleet,
|
|
|
|
Version: uint(s.Version),
|
|
|
|
Removed: s.Removed,
|
|
|
|
DeletedAt: s.DeletedAt,
|
|
|
|
Clock: clock,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func toMailserver(m Storenode) mailservers.Mailserver {
|
|
|
|
return mailservers.Mailserver{
|
|
|
|
ID: m.StorenodeID,
|
|
|
|
Name: m.Name,
|
|
|
|
Custom: true,
|
2024-08-16 18:24:21 +00:00
|
|
|
Address: m.Address.String(),
|
2024-02-20 15:49:39 +00:00
|
|
|
Fleet: m.Fleet,
|
|
|
|
Version: m.Version,
|
|
|
|
}
|
|
|
|
}
|