Pablo Lopez 3f19972c8e
enable custom community storenodes (#4532)
* enable custom community store nodes

* fix

* fix

* fix

* fix

* cleanup

* fix

* migration

* fix

* cleanup

* fix

* cleanup

* fix

* fix

* cleanup

* message to update the community storenodes

* rename

* fix test

* wait for availability only if global storenode

* fix test

* fix typo

* sync community storenodes

* remove unused

* add tests

* fix imports

* fix todo

* unused

* pr comments

* pr feedback

* revert merge deleted

* fix lint

* fix db and perform ms request

* typo

* fix log

* fix go imports

* refactor handle message

* cleanup public message

* add tests

* fix test

* cleanup test

* fix test

* avoid making one file to big to keep codeclimate from complaining

* fix lint

* revert

* Update protocol/storenodes/database.go

Co-authored-by: richΛrd <info@richardramos.me>

* Update protocol/messenger_mailserver_cycle.go

Co-authored-by: richΛrd <info@richardramos.me>

* PR comment

* fix tx

* proto files

* pr comment

---------

Co-authored-by: richΛrd <info@richardramos.me>
2024-02-20 17:49:39 +02:00

70 lines
1.8 KiB
Go

package storenodes
import (
"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 {
CommunityID types.HexBytes `json:"community_id"`
StorenodeID string `json:"storenode_id"`
Name string `json:"name"`
Address string `json:"address"`
Fleet string `json:"fleet"`
Version uint `json:"version"`
Clock uint64 `json:"-"` // used to sync
Removed bool `json:"-"`
DeletedAt int64 `json:"-"`
}
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,
Address: n.Address,
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 {
result = append(result, Storenode{
CommunityID: s.CommunityId,
StorenodeID: s.StorenodeId,
Name: s.Name,
Address: s.Address,
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,
Address: m.Address,
Fleet: m.Fleet,
Version: m.Version,
}
}