-
Notifications
You must be signed in to change notification settings - Fork 2
/
query.go
59 lines (42 loc) · 1.45 KB
/
query.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
48
49
50
51
52
53
54
55
56
57
58
59
package storage_handler
import (
"context"
"fmt"
"github.com/JackalLabs/jackalgo/utils"
"github.com/cosmos/cosmos-sdk/types"
storagetypes "github.com/jackalLabs/canine-chain/v3/x/storage/types"
)
func (s *StorageHandler) QueryGetPayData(address string) (*storagetypes.QueryPayDataResponse, error) {
_, err := types.AccAddressFromBech32(address)
if err != nil {
return nil, err
}
req := storagetypes.QueryPayDataRequest{
Address: address,
}
queryClient := storagetypes.NewQueryClient(s.walletHandler.GetClientCtx())
res, err := queryClient.GetPayData(context.Background(), &req)
return res, err
}
func (s *StorageHandler) QueryFidCid(fid string) (*storagetypes.QueryFidCidResponse, error) {
req := storagetypes.QueryFidCidRequest{
Fid: fid,
}
queryClient := storagetypes.NewQueryClient(s.walletHandler.GetClientCtx())
res, err := queryClient.FidCid(context.Background(), &req)
return res, err
}
func (s *StorageHandler) QueryJackalPrice(bytes int64, duration int64) (*storagetypes.QueryPriceCheckResponse, error) {
tbs := utils.NumTo3xTB(bytes)
if duration <= 0 {
return nil, fmt.Errorf("cannot use less than 0 months of duration")
}
monthsAsHours := duration * 720
req := storagetypes.QueryPriceCheckRequest{
Bytes: tbs,
Duration: fmt.Sprintf("%dh", monthsAsHours),
}
queryClient := storagetypes.NewQueryClient(s.walletHandler.GetClientCtx())
res, err := queryClient.PriceCheck(context.Background(), &req)
return res, err
}