feat: Waku v2 bridge

Issue #12610
This commit is contained in:
Michal Iskierko
2023-11-12 13:29:38 +01:00
parent 56e7bd01ca
commit 6d31343205
6716 changed files with 1982502 additions and 5891 deletions

View File

@@ -0,0 +1,30 @@
package wakusync
import (
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/protocol/identity"
"github.com/status-im/status-go/services/ens"
)
type BackedUpProfile struct {
DisplayName string `json:"displayName,omitempty"`
Images []images.IdentityImage `json:"images,omitempty"`
SocialLinks []*identity.SocialLink `json:"socialLinks,omitempty"`
EnsUsernameDetails []*ens.UsernameDetail `json:"ensUsernameDetails,omitempty"`
}
func (sfwr *WakuBackedUpDataResponse) SetDisplayName(displayName string) {
sfwr.Profile.DisplayName = displayName
}
func (sfwr *WakuBackedUpDataResponse) SetImages(images []images.IdentityImage) {
sfwr.Profile.Images = images
}
func (sfwr *WakuBackedUpDataResponse) SetSocialLinks(socialLinks []*identity.SocialLink) {
sfwr.Profile.SocialLinks = socialLinks
}
func (sfwr *WakuBackedUpDataResponse) SetEnsUsernameDetails(ensUsernameDetails []*ens.UsernameDetail) {
sfwr.Profile.EnsUsernameDetails = ensUsernameDetails
}

View File

@@ -0,0 +1,36 @@
package wakusync
import (
"github.com/status-im/status-go/protocol/protobuf"
)
type FetchingBackupedDataDetails struct {
DataNumber uint32 `json:"dataNumber,omitempty"`
TotalNumber uint32 `json:"totalNumber,omitempty"`
}
func (sfwr *WakuBackedUpDataResponse) AddFetchingBackedUpDataDetails(section string, details *protobuf.FetchingBackedUpDataDetails) {
if details == nil {
return
}
if sfwr.FetchingDataProgress == nil {
sfwr.FetchingDataProgress = make(map[string]*protobuf.FetchingBackedUpDataDetails)
}
sfwr.FetchingDataProgress[section] = details
}
func (sfwr *WakuBackedUpDataResponse) FetchingBackedUpDataDetails() map[string]FetchingBackupedDataDetails {
if len(sfwr.FetchingDataProgress) == 0 {
return nil
}
result := make(map[string]FetchingBackupedDataDetails)
for section, details := range sfwr.FetchingDataProgress {
result[section] = FetchingBackupedDataDetails{
DataNumber: details.DataNumber,
TotalNumber: details.TotalNumber,
}
}
return result
}

View File

@@ -0,0 +1,39 @@
package wakusync
import (
"encoding/json"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/protocol/protobuf"
)
type WakuBackedUpDataResponse struct {
Clock uint64
FetchingDataProgress map[string]*protobuf.FetchingBackedUpDataDetails // key represents the data/section backup details refer to
Profile *BackedUpProfile
Setting *settings.SyncSettingField
Keypair *accounts.Keypair
WatchOnlyAccount *accounts.Account
}
func (sfwr *WakuBackedUpDataResponse) MarshalJSON() ([]byte, error) {
responseItem := struct {
Clock uint64 `json:"clock,omitempty"`
FetchingDataProgress map[string]FetchingBackupedDataDetails `json:"fetchingBackedUpDataProgress,omitempty"`
Profile *BackedUpProfile `json:"backedUpProfile,omitempty"`
Setting *settings.SyncSettingField `json:"backedUpSettings,omitempty"`
Keypair *accounts.Keypair `json:"backedUpKeypair,omitempty"`
WatchOnlyAccount *accounts.Account `json:"backedUpWatchOnlyAccount,omitempty"`
}{
Clock: sfwr.Clock,
Profile: sfwr.Profile,
Setting: sfwr.Setting,
Keypair: sfwr.Keypair,
WatchOnlyAccount: sfwr.WatchOnlyAccount,
}
responseItem.FetchingDataProgress = sfwr.FetchingBackedUpDataDetails()
return json.Marshal(responseItem)
}