From 079c5cfa45f8d17a8f664ab8c3017dad832f1777 Mon Sep 17 00:00:00 2001 From: Ingar Shu Date: Tue, 7 Jul 2020 12:59:14 -0700 Subject: [PATCH] Add NewQueryV1, which has an optional PieceID param (#313) --- retrievalmarket/network/libp2p_impl_test.go | 5 +++-- retrievalmarket/types.go | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/retrievalmarket/network/libp2p_impl_test.go b/retrievalmarket/network/libp2p_impl_test.go index 759db86c..c0f3292b 100644 --- a/retrievalmarket/network/libp2p_impl_test.go +++ b/retrievalmarket/network/libp2p_impl_test.go @@ -381,8 +381,8 @@ func assertQueryReceived(inCtx context.Context, t *testing.T, fromNetwork networ require.NoError(t, err) // send query to host2 - cid := shared_testutil.GenerateCids(1)[0] - q := retrievalmarket.NewQueryV0(cid) + cids := shared_testutil.GenerateCids(2) + q := retrievalmarket.NewQueryV1(cids[0], &cids[1]) require.NoError(t, qs1.WriteQuery(q)) var inq retrievalmarket.Query @@ -393,6 +393,7 @@ func assertQueryReceived(inCtx context.Context, t *testing.T, fromNetwork networ } require.NotNil(t, inq) assert.Equal(t, q.PayloadCID, inq.PayloadCID) + assert.Equal(t, q.PieceCID, inq.PieceCID) } // assertQueryResponseReceived performs the verification that a DealStatusResponse is received diff --git a/retrievalmarket/types.go b/retrievalmarket/types.go index ad0d1a24..4a92b1d6 100644 --- a/retrievalmarket/types.go +++ b/retrievalmarket/types.go @@ -477,11 +477,21 @@ type Query struct { // QueryUndefined is a query with no values var QueryUndefined = Query{} -// NewQueryV0 creates a V0 query (which only specifies a piece) +// NewQueryV0 creates a V0 query (which only specifies a payload) func NewQueryV0(payloadCID cid.Cid) Query { return Query{PayloadCID: payloadCID} } +// NewQueryV1 creates a V1 query (which has an optional pieceCID) +func NewQueryV1(payloadCID cid.Cid, pieceCID *cid.Cid) Query { + return Query{ + PayloadCID: payloadCID, + QueryParams: QueryParams{ + PieceCID: pieceCID, + }, + } +} + // QueryResponse is a miners response to a given retrieval query type QueryResponse struct { Status QueryResponseStatus