forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
contract_bytecode_query.go
55 lines (43 loc) · 1.91 KB
/
contract_bytecode_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
package hedera
import (
"github.com/hashgraph/hedera-sdk-go/proto"
)
// ContractBytcodeQuery retrieves the bytecode for a smart contract instance
type ContractBytecodeQuery struct {
QueryBuilder
pb *proto.ContractGetBytecodeQuery
}
// NewContractBytecodeQuery creates a ContractBytecodeQuery builder which can be used to construct and execute a
// Contract Get Bytecode Query.
func NewContractBytecodeQuery() *ContractBytecodeQuery {
pb := &proto.ContractGetBytecodeQuery{Header: &proto.QueryHeader{}}
inner := newQueryBuilder(pb.Header)
inner.pb.Query = &proto.Query_ContractGetBytecode{ContractGetBytecode: pb}
return &ContractBytecodeQuery{inner, pb}
}
// SetContractID sets the contract for which the bytecode is requested
func (builder *ContractBytecodeQuery) SetContractID(id ContractID) *ContractBytecodeQuery {
builder.pb.ContractID = id.toProto()
return builder
}
// Execute executes the ContractByteCodeQuery using the provided client
func (builder *ContractBytecodeQuery) Execute(client *Client) ([]byte, error) {
resp, err := builder.execute(client)
if err != nil {
return []byte{}, err
}
return resp.GetContractGetBytecodeResponse().Bytecode, 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 *ContractBytecodeQuery) SetMaxQueryPayment(maxPayment Hbar) *ContractBytecodeQuery {
return &ContractBytecodeQuery{*builder.QueryBuilder.SetMaxQueryPayment(maxPayment), builder.pb}
}
func (builder *ContractBytecodeQuery) SetQueryPayment(paymentAmount Hbar) *ContractBytecodeQuery {
return &ContractBytecodeQuery{*builder.QueryBuilder.SetQueryPayment(paymentAmount), builder.pb}
}
func (builder *ContractBytecodeQuery) SetQueryPaymentTransaction(tx Transaction) *ContractBytecodeQuery {
return &ContractBytecodeQuery{*builder.QueryBuilder.SetQueryPaymentTransaction(tx), builder.pb}
}