diff --git a/bindings/backup.go b/bindings/backup.go index 95418357db3fbc3829b90c209452ac42ce33ebea..2c5c24560184fe5d1f121e05b8df5de98ce1fc23 100644 --- a/bindings/backup.go +++ b/bindings/backup.go @@ -10,6 +10,7 @@ package bindings import ( "encoding/json" "gitlab.com/elixxir/client/backup" + "gitlab.com/xx_network/primitives/id" ) //////////////////////////////////////////////////////////////////////////////// @@ -26,10 +27,16 @@ type Backup struct { // NewCmixFromBackup. // // Example BackupReport: -//{"RestoredContacts":["0AeVYBe87SV45A2UI4AtIe6H4AIyZSLPBPrT6eTBLycD"],"Params":""} +// { +// "RestoredContacts": [ +// "U4x/lrFkvxuXu59LtHLon1sUhPJSCcnZND6SugndnVID", +// "15tNdkKbYXoMn58NO6VbDMDWFEyIhTWEGsvgcJsHWAgD" +// ], +// "Params": "" +// } type BackupReport struct { // The list of restored E2E partner IDs - RestoredContacts IdList + RestoredContacts []*id.ID // The backup parameters found within the backup file Params string @@ -70,7 +77,7 @@ func NewCmixFromBackup(ndfJSON, storageDir, backupPassphrase string, // Construct report report := BackupReport{ - RestoredContacts: makeIdList(backupIdList), + RestoredContacts: backupIdList, Params: backupParams, } diff --git a/bindings/e2eHandler.go b/bindings/e2eHandler.go index 501b02df2387cb22dc7baa8c7ee31fb2df8bd8d6..83ca76d62341b62162fa97d19be63b5537c517d2 100644 --- a/bindings/e2eHandler.go +++ b/bindings/e2eHandler.go @@ -41,14 +41,13 @@ func (e *E2e) GetReceptionID() []byte { return e.api.GetE2E().GetReceptionID().Marshal() } -// GetAllPartnerIDs returns a marshalled list of all partner IDs that the user -// has an E2E relationship with. +// GetAllPartnerIDs returns a list of all partner IDs that the user has an E2E +// relationship with. // // Returns: -// - []byte - the marshalled bytes of the IdList object. +// - []byte - the marshalled bytes of []*id.ID. func (e *E2e) GetAllPartnerIDs() ([]byte, error) { - partnerIds := e.api.GetE2E().GetAllPartnerIDs() - return json.Marshal(makeIdList(partnerIds)) + return json.Marshal(e.api.GetE2E().GetAllPartnerIDs()) } // PayloadSize returns the max payload size for a partitionable E2E message. diff --git a/bindings/group.go b/bindings/group.go index 50bd956f044c0e382842524e9af1cf47fd3508ad..00951c269e43843fd3bd05609f1bddc9562cb844 100644 --- a/bindings/group.go +++ b/bindings/group.go @@ -125,21 +125,24 @@ func NewGroupChat(e2eID int, // group. // // Parameters: -// - membership - IDs of members the user wants in the group. +// - membershipBytes - the JSON marshalled list of []*id.ID; it contains the +// IDs of members the user wants to add to the group. // - message - the initial message sent to all members in the group. This is an // optional parameter and may be nil. -// - tag - the name of the group decided by the creator. This is an optional parameter -// and may be nil. If nil the group will be assigned the default name. +// - tag - the name of the group decided by the creator. This is an optional +// parameter and may be nil. If nil the group will be assigned the default +// name. // // Returns: // - []byte - the JSON marshalled bytes of the GroupReport object, which can be // passed into WaitForRoundResult to see if the group request message send // succeeded. -func (g *GroupChat) MakeGroup(membership IdList, message, name []byte) ( +func (g *GroupChat) MakeGroup(membershipBytes []byte, message, name []byte) ( []byte, error) { - // Construct membership list into a list of []*id.Id - members, err := deserializeIdList(membership) + // Unmarshal membership list into a list of []*id.Id + var members []*id.ID + err := json.Unmarshal(membershipBytes, &members) if err != nil { return nil, err } @@ -275,14 +278,12 @@ func (g *GroupChat) Send(groupId, return json.Marshal(sendReport) } -// GetGroups returns an IdList containing a list of group IDs that the user is a member of. +// GetGroups returns a list of group IDs that the user is a member of. // // Returns: -// - []byte - a JSON marshalled IdList representing all group ID's. +// - []byte - a JSON marshalled []*id.ID representing all group ID's. func (g *GroupChat) GetGroups() ([]byte, error) { - groupIds := makeIdList(g.m.GetGroups()) - - return json.Marshal(groupIds) + return json.Marshal(g.m.GetGroups()) } // GetGroup returns the group with the group ID. If no group exists, then the diff --git a/bindings/identity.go b/bindings/identity.go index ffb4990f9b5541ff23a03decd5f0c4db84829026..f1b56803184de8491f3c93ad43d89008f6227bd4 100644 --- a/bindings/identity.go +++ b/bindings/identity.go @@ -9,8 +9,6 @@ package bindings import ( "encoding/json" - "gitlab.com/xx_network/primitives/id" - "gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/primitives/fact" @@ -189,38 +187,3 @@ func GetFactsFromContact(marshaled []byte) ([]byte, error) { } return factsListMarshaled, nil } - -//////////////////////////////////////////////////////////////////////////////// -// IdList Functions // -//////////////////////////////////////////////////////////////////////////////// - -// IdList is a wrapper for a list of marshalled id.ID objects. -type IdList struct { - Ids [][]byte -} - -// makeIdList is a helper function which creates an IdList object -// given a list of id.ID's. It serializes each element of the -// given list of id.ID's, places that into a list of []byte's (ie [][]byte) -// and places that in the IdList. -func makeIdList(ids []*id.ID) IdList { - convertedIds := make([][]byte, len(ids)) - for i, partnerId := range ids { - convertedIds[i] = partnerId.Marshal() - } - return IdList{Ids: convertedIds} -} - -// deserializeIdList is a helper function which creates a list of id.ID's -// given an IdList. It deserializes each element of the IdList using id.Unmarshal. -func deserializeIdList(ids IdList) ([]*id.ID, error) { - convertedIds := make([]*id.ID, len(ids.Ids)) - for i, serializedId := range ids.Ids { - deserializedId, err := id.Unmarshal(serializedId) - if err != nil { - return nil, err - } - convertedIds[i] = deserializedId - } - return convertedIds, nil -}