Skip to content

Commit

Permalink
converting store responses
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer committed Jan 30, 2025
1 parent 8df9d9c commit c2f6e64
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
53 changes: 53 additions & 0 deletions wakuv2/nwaku_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,56 @@ func PbToBindingsStoreRequest(pbStoreRequest *storepb.StoreQueryRequest) (*commo
}
return &bindingsQueryRequest, nil
}

func BindingsToPbStoreResponse(bindingsStoreResponse *common.StoreQueryResponse) (*storepb.StoreQueryResponse, error) {

paginationCursor, err := bindingsStoreResponse.PaginationCursor.Bytes()
if err != nil {
return nil, err
}

pbQueryResponse := storepb.StoreQueryResponse{
RequestId: bindingsStoreResponse.RequestId,
StatusCode: bindingsStoreResponse.StatusCode,
StatusDesc: &bindingsStoreResponse.StatusDesc,
PaginationCursor: paginationCursor,
}

if bindingsStoreResponse.Messages == nil {
return &pbQueryResponse, nil
}

var messages []*storepb.WakuMessageKeyValue

for _, message := range *bindingsStoreResponse.Messages {

msgHash, err := message.MessageHash.Bytes()

if err != nil {
return nil, err
}

wakuMessage := pb.WakuMessage{
Payload: message.WakuMessage.Payload,
ContentTopic: message.WakuMessage.ContentTopic,
Version: message.WakuMessage.Version,
Timestamp: message.WakuMessage.Timestamp,
Meta: message.WakuMessage.Meta,
Ephemeral: message.WakuMessage.Ephemeral,
RateLimitProof: message.WakuMessage.RateLimitProof,
}

pbMessage := storepb.WakuMessageKeyValue{
MessageHash: msgHash,
PubsubTopic: &message.PubsubTopic,
Message: &wakuMessage,
}

messages = append(messages, &pbMessage)
}

pbQueryResponse.Messages = messages

return &pbQueryResponse, nil

}
8 changes: 7 additions & 1 deletion wakuv2/storenode_message_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ func (d *storenodeMessageVerifier) MessageHashesExist(ctx context.Context, reque
(*storeRequest.MessageHashes)[i] = common.MessageHash(mhash.String())
}

response, err := d.node.StoreQuery(ctx, storeRequest, peerInfo)
bindingsResponse, err := d.node.StoreQuery(ctx, storeRequest, peerInfo)
if err != nil {
return nil, err
}

response, err := BindingsToPbStoreResponse(bindingsResponse)

if err != nil {
return nil, err
}
Expand Down
17 changes: 15 additions & 2 deletions wakuv2/storenode_requestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ func (s *storenodeRequestor) GetMessagesByHash(ctx context.Context, peerInfo pee
return nil, err
}

storeResponse, err := s.node.StoreQuery(ctx, bindingsStoreRequest, peerInfo)
bindingsResponse, err := s.node.StoreQuery(ctx, bindingsStoreRequest, peerInfo)
if err != nil {
return nil, err
}

storeResponse, err := BindingsToPbStoreResponse(bindingsResponse)

if err != nil {
return nil, err
}
Expand All @@ -78,7 +84,14 @@ func (s *storenodeRequestor) Query(ctx context.Context, peerInfo peer.AddrInfo,
return nil, err
}

storeResponse, err := s.node.StoreQuery(ctx, bindingsStoreRequest, peerInfo)
bindingsResponse, err := s.node.StoreQuery(ctx, bindingsStoreRequest, peerInfo)

if err != nil {
return nil, err
}

storeResponse, err := BindingsToPbStoreResponse(bindingsResponse)

if err != nil {
return nil, err
}
Expand Down

0 comments on commit c2f6e64

Please sign in to comment.