From 7c1ce2b19eea8186935dc4217cbc5b522dbc2cb0 Mon Sep 17 00:00:00 2001
From: joshemb <josh@elixxir.io>
Date: Thu, 25 Aug 2022 10:47:47 -0700
Subject: [PATCH] Have search return JSON of already marshaled contacts

---
 bindings/single.go |  4 ++--
 bindings/ud.go     | 28 ++++++++++++++++++++++++----
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/bindings/single.go b/bindings/single.go
index ca0e855cb..a3bacbce2 100644
--- a/bindings/single.go
+++ b/bindings/single.go
@@ -166,7 +166,7 @@ type Stopper interface {
 // Parameters:
 //  - callbackReport - the JSON marshalled bytes of the SingleUseCallbackReport
 //    object, which can be passed into Cmix.WaitForRoundResult to see if the
-//    send succeeded.
+//    send operation succeeded.
 type SingleUseCallback interface {
 	Callback(callbackReport []byte, err error)
 }
@@ -177,7 +177,7 @@ type SingleUseCallback interface {
 // Parameters:
 //  - callbackReport - the JSON marshalled bytes of the SingleUseResponseReport
 //    object, which can be passed into Cmix.WaitForRoundResult to see if the
-//    send succeeded.
+//    send operation succeeded.
 type SingleUseResponse interface {
 	Callback(responseReport []byte, err error)
 }
diff --git a/bindings/ud.go b/bindings/ud.go
index 217fb964b..3a3f21a0d 100644
--- a/bindings/ud.go
+++ b/bindings/ud.go
@@ -429,8 +429,15 @@ func LookupUD(e2eID int, udContact []byte, cb UdLookupCallback,
 //
 // Parameters:
 //  - contactListJSON - the JSON marshalled bytes of []contact.Contact, or nil
-//    if an error occurs
-//  - err - any errors that occurred in the search
+//    if an error occurs.
+//
+//   JSON Example:
+//   {
+//  	"<xxc(2)F8dL9EC6gy+RMJuk3R+Au6eGExo02Wfio5cacjBcJRwDEgB7Ugdw/BAr6RkCABkWAFV1c2VybmFtZTA7c4LzV05sG+DMt+rFB0NIJg==xxc>",
+//  	"<xxc(2)eMhAi/pYkW5jCmvKE5ZaTglQb+fTo1D8NxVitr5CCFADEgB7Ugdw/BAr6RoCABkWAFV1c2VybmFtZTE7fElAa7z3IcrYrrkwNjMS2w==xxc>",
+//  	"<xxc(2)d7RJTu61Vy1lDThDMn8rYIiKSe1uXA/RCvvcIhq5Yg4DEgB7Ugdw/BAr6RsCABkWAFV1c2VybmFtZTI7N3XWrxIUpR29atpFMkcR6A==xxc>"
+//	}
+//  - err - any errors that occurred in the search.
 type UdSearchCallback interface {
 	Callback(contactListJSON []byte, err error)
 }
@@ -451,7 +458,7 @@ type UdSearchCallback interface {
 // Returns:
 //  - []byte - the JSON marshalled bytes of the SingleUseSendReport object,
 //    which can be passed into Cmix.WaitForRoundResult to see if the send
-//    succeeded.
+//    operation succeeded.
 func SearchUD(e2eID int, udContact []byte, cb UdSearchCallback,
 	factListJSON, singleRequestParamsJSON []byte) ([]byte, error) {
 
@@ -479,7 +486,20 @@ func SearchUD(e2eID int, udContact []byte, cb UdSearchCallback,
 	}
 
 	callback := func(contactList []contact.Contact, err error) {
-		contactListJSON, err2 := json.Marshal(contactList)
+		marshaledContactList := make([][]byte, 0)
+		// fixme: it may be wiser to change this callback interface
+		//   to simply do the work below when parsing the response from UD.
+		//   that would change ud/search.go in two places:
+		//    - searchCallback
+		//    - parseContacts
+		//  I avoid doing that as it changes interfaces w/o approval
+		for i := range contactList {
+			con := contactList[i]
+			marshaledContactList = append(
+				marshaledContactList, con.Marshal())
+		}
+
+		contactListJSON, err2 := json.Marshal(marshaledContactList)
 		if err2 != nil {
 			jww.FATAL.Panicf(
 				"Failed to marshal list of contact.Contact: %+v", err2)
-- 
GitLab