mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-30 15:37:30 +00:00
68 lines
1.2 KiB
Go
68 lines
1.2 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
"github.com/waku-org/go-waku/waku/v2/protocol/store/pb"
|
|
)
|
|
|
|
// Result represents a valid response from a store node
|
|
type Result struct {
|
|
started bool
|
|
messages []*pb.WakuMessageKeyValue
|
|
store *WakuStore
|
|
storeRequest *pb.StoreQueryRequest
|
|
storeResponse *pb.StoreQueryResponse
|
|
cursor []byte
|
|
peerID peer.ID
|
|
}
|
|
|
|
func (r *Result) Cursor() []byte {
|
|
return r.cursor
|
|
}
|
|
|
|
func (r *Result) IsComplete() bool {
|
|
return r.cursor == nil
|
|
}
|
|
|
|
func (r *Result) PeerID() peer.ID {
|
|
return r.peerID
|
|
}
|
|
|
|
func (r *Result) Query() *pb.StoreQueryRequest {
|
|
return r.storeRequest
|
|
}
|
|
|
|
func (r *Result) Response() *pb.StoreQueryResponse {
|
|
return r.storeResponse
|
|
}
|
|
|
|
func (r *Result) Next(ctx context.Context) (bool, error) {
|
|
if !r.started {
|
|
r.started = true
|
|
return len(r.messages) != 0, nil
|
|
}
|
|
|
|
if r.IsComplete() {
|
|
return false, nil
|
|
}
|
|
|
|
newResult, err := r.store.next(ctx, r)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
r.cursor = newResult.cursor
|
|
r.messages = newResult.messages
|
|
|
|
return !r.IsComplete(), nil
|
|
}
|
|
|
|
func (r *Result) Messages() []*pb.WakuMessageKeyValue {
|
|
if !r.started {
|
|
return nil
|
|
}
|
|
return r.messages
|
|
}
|