-
Notifications
You must be signed in to change notification settings - Fork 16
/
grpc_query_find_file.go
47 lines (35 loc) · 1 KB
/
grpc_query_find_file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package keeper
import (
"context"
"encoding/json"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackalLabs/canine-chain/v3/x/storage/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (k Keeper) ListFiles(ctx sdk.Context, fid string) []string {
allDeals := k.GetAllActiveDeals(ctx)
providers := []string{}
for i := 0; i < len(allDeals); i++ {
if allDeals[i].Fid == fid {
provider, ok := k.GetProviders(ctx, allDeals[i].Provider)
if !ok {
continue
}
providers = append(providers, provider.Ip)
}
}
return providers
}
func (k Keeper) FindFile(goCtx context.Context, req *types.QueryFindFileRequest) (*types.QueryFindFileResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
ls := k.ListFiles(ctx, req.Fid)
ProviderIps, err := json.Marshal(ls)
if err != nil {
return nil, err
}
return &types.QueryFindFileResponse{ProviderIps: string(ProviderIps)}, nil
}