forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_info_query.go
89 lines (71 loc) · 2.41 KB
/
file_info_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package hedera
import (
"github.com/hashgraph/hedera-sdk-go/proto"
"time"
)
type FileInfoQuery struct {
QueryBuilder
pb *proto.FileGetInfoQuery
}
type FileInfo struct {
FileID FileID
Size int64
ExpirationTime time.Time
IsDeleted bool
Keys []PublicKey
}
func NewFileInfoQuery() *FileInfoQuery {
pb := &proto.FileGetInfoQuery{Header: &proto.QueryHeader{}}
inner := newQueryBuilder(pb.Header)
inner.pb.Query = &proto.Query_FileGetInfo{FileGetInfo: pb}
return &FileInfoQuery{inner, pb}
}
func (builder *FileInfoQuery) SetFileID(id FileID) *FileInfoQuery {
builder.pb.FileID = id.toProto()
return builder
}
func (builder *FileInfoQuery) Execute(client *Client) (FileInfo, error) {
resp, err := builder.execute(client)
if err != nil {
return FileInfo{}, err
}
pbKeys := resp.GetFileGetInfo().FileInfo.Keys
keys, err := publicKeyListFromProto(pbKeys)
if err != nil {
return FileInfo{}, err
}
return FileInfo{
FileID: fileIDFromProto(resp.GetFileGetInfo().FileInfo.FileID),
Size: resp.GetFileGetInfo().FileInfo.Size,
ExpirationTime: timeFromProto(resp.GetFileGetInfo().FileInfo.ExpirationTime),
IsDeleted: resp.GetFileGetInfo().FileInfo.Deleted,
Keys: keys,
}, nil
}
func (builder *FileInfoQuery) Cost(client *Client) (Hbar, error) {
// deleted files return a COST_ANSWER of zero which triggers `INSUFFICIENT_TX_FEE`
// if you set that as the query payment; 25 tinybar seems to be enough to get
// `FILE_DELETED` back instead.
cost, err := builder.QueryBuilder.GetCost(client)
if err != nil {
return ZeroHbar, err
}
// math.Min requires float64 and returns float64
if cost.AsTinybar() > 25 {
return cost, nil
}
return HbarFromTinybar(25), nil
}
//
// The following _3_ must be copy-pasted at the bottom of **every** _query.go file
// We override the embedded fluent setter methods to return the outer type
//
func (builder *FileInfoQuery) SetMaxQueryPayment(maxPayment Hbar) *FileInfoQuery {
return &FileInfoQuery{*builder.QueryBuilder.SetMaxQueryPayment(maxPayment), builder.pb}
}
func (builder *FileInfoQuery) SetQueryPayment(paymentAmount Hbar) *FileInfoQuery {
return &FileInfoQuery{*builder.QueryBuilder.SetQueryPayment(paymentAmount), builder.pb}
}
func (builder *FileInfoQuery) SetQueryPaymentTransaction(tx Transaction) *FileInfoQuery {
return &FileInfoQuery{*builder.QueryBuilder.SetQueryPaymentTransaction(tx), builder.pb}
}