forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile_contents_query.go
54 lines (42 loc) · 1.84 KB
/
file_contents_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
package hedera
import "github.com/hashgraph/hedera-sdk-go/proto"
// FileContentsQuery retrieves the contents of a file.
type FileContentsQuery struct {
QueryBuilder
pb *proto.FileGetContentsQuery
}
// NewFileContentsQuery creates a FileContentsQuery builder which can be used to construct and execute a
// File Get Contents Query.
func NewFileContentsQuery() *FileContentsQuery {
pb := &proto.FileGetContentsQuery{Header: &proto.QueryHeader{}}
inner := newQueryBuilder(pb.Header)
inner.pb.Query = &proto.Query_FileGetContents{FileGetContents: pb}
return &FileContentsQuery{inner, pb}
}
// SetFileID sets the FileID of the file whose contents are requested.
func (builder *FileContentsQuery) SetFileID(id FileID) *FileContentsQuery {
builder.pb.FileID = id.toProto()
return builder
}
// Execute executes the FileContentsQuery using the provided client. The returned byte slice will be empty if the file
// is empty.
func (builder *FileContentsQuery) Execute(client *Client) ([]byte, error) {
resp, err := builder.execute(client)
if err != nil {
return []byte{}, err
}
return resp.GetFileGetContents().FileContents.Contents, 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 *FileContentsQuery) SetMaxQueryPayment(maxPayment Hbar) *FileContentsQuery {
return &FileContentsQuery{*builder.QueryBuilder.SetMaxQueryPayment(maxPayment), builder.pb}
}
func (builder *FileContentsQuery) SetQueryPayment(paymentAmount Hbar) *FileContentsQuery {
return &FileContentsQuery{*builder.QueryBuilder.SetQueryPayment(paymentAmount), builder.pb}
}
func (builder *FileContentsQuery) SetQueryPaymentTransaction(tx Transaction) *FileContentsQuery {
return &FileContentsQuery{*builder.QueryBuilder.SetQueryPaymentTransaction(tx), builder.pb}
}