-
Notifications
You must be signed in to change notification settings - Fork 64
/
resolver_ask.go
83 lines (70 loc) · 2.28 KB
/
resolver_ask.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package gql
import (
"context"
"fmt"
"time"
"github.com/filecoin-project/boost-gfm/storagemarket"
"github.com/filecoin-project/boost/gql/types"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/build"
"github.com/graph-gophers/graphql-go"
)
type storageAskResolver struct {
Price types.BigInt
VerifiedPrice types.BigInt
MinPieceSize types.Uint64
MaxPieceSize types.Uint64
ExpiryEpoch types.Uint64
ExpiryTime graphql.Time
}
func (r *resolver) StorageAsk(ctx context.Context) (*storageAskResolver, error) {
head, err := r.fullNode.ChainHead(ctx)
if err != nil {
return nil, fmt.Errorf("getting chain head: %w", err)
}
signedAsk := r.legacyProv.GetAsk()
ask := signedAsk.Ask
expTimeEpochs := ask.Expiry - head.Height()
expTime := time.Now().Add(time.Duration(expTimeEpochs) * time.Duration(build.BlockDelaySecs) * time.Second)
return &storageAskResolver{
Price: types.BigInt{Int: ask.Price},
VerifiedPrice: types.BigInt{Int: ask.VerifiedPrice},
MinPieceSize: types.Uint64(ask.MinPieceSize),
MaxPieceSize: types.Uint64(ask.MaxPieceSize),
ExpiryEpoch: types.Uint64(ask.Expiry),
ExpiryTime: graphql.Time{Time: expTime},
}, nil
}
type storageAskUpdate struct {
Price *types.BigInt
VerifiedPrice *types.BigInt
MinPieceSize *types.Uint64
MaxPieceSize *types.Uint64
}
func (r *resolver) StorageAskUpdate(args struct{ Update storageAskUpdate }) (bool, error) {
signedAsk := r.legacyProv.GetAsk()
ask := signedAsk.Ask
dur := 87660 * time.Hour // 10 years
duration := abi.ChainEpoch(dur.Seconds() / float64(build.BlockDelaySecs))
price := ask.Price
verifiedPrice := ask.VerifiedPrice
var opts []storagemarket.StorageAskOption
update := args.Update
if update.Price != nil {
price = (*update.Price).Int
}
if update.VerifiedPrice != nil {
verifiedPrice = (*update.VerifiedPrice).Int
}
if update.MinPieceSize != nil {
opts = append(opts, storagemarket.MinPieceSize(abi.PaddedPieceSize(*update.MinPieceSize)))
}
if update.MaxPieceSize != nil {
opts = append(opts, storagemarket.MaxPieceSize(abi.PaddedPieceSize(*update.MaxPieceSize)))
}
err := r.legacyProv.SetAsk(price, verifiedPrice, duration, opts...)
if err != nil {
return false, fmt.Errorf("setting ask: %w", err)
}
return true, nil
}