forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
contract_execute_transaction.go
85 lines (67 loc) · 3.41 KB
/
contract_execute_transaction.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
package hedera
import (
"time"
"github.com/hashgraph/hedera-sdk-go/proto"
)
// ContractExecuteTransaction calls a function of the given smart contract instance, giving it ContractFuncionParams as
// its inputs. it can use the given amount of gas, and any unspent gas will be refunded to the paying account.
//
// If this function stores information, it is charged gas to store it. There is a fee in hbars to maintain that storage
// until the expiration time, and that fee is added as part of the transaction fee.
//
// For a cheaper but more limited method to call functions, see ContractCallQuery.
type ContractExecuteTransaction struct {
TransactionBuilder
pb *proto.ContractCallTransactionBody
}
// NewContractExecuteTransaction creates a ContractExecuteTransaction builder which can be
// used to construct and execute a Contract Call Transaction.
func NewContractExecuteTransaction() ContractExecuteTransaction {
pb := &proto.ContractCallTransactionBody{}
inner := newTransactionBuilder()
inner.pb.Data = &proto.TransactionBody_ContractCall{ContractCall: pb}
builder := ContractExecuteTransaction{inner, pb}
return builder
}
// SetContractID sets the contract instance to call.
func (builder ContractExecuteTransaction) SetContractID(id ContractID) ContractExecuteTransaction {
builder.pb.ContractID = id.toProto()
return builder
}
// SetGas sets the maximum amount of gas to use for the call.
func (builder ContractExecuteTransaction) SetGas(gas uint64) ContractExecuteTransaction {
builder.pb.Gas = int64(gas)
return builder
}
// SetPayableAmount sets the amount of Hbar sent (the function must be payable if this is nonzero)
func (builder ContractExecuteTransaction) SetPayableAmount(amount Hbar) ContractExecuteTransaction {
builder.pb.Amount = int64(amount.AsTinybar())
return builder
}
// SetFunction sets which function to call, and the ContractFunctionParams to pass to the function
func (builder ContractExecuteTransaction) SetFunction(name string, params *ContractFunctionParams) ContractExecuteTransaction {
if params == nil {
params = NewContractFunctionParams()
}
builder.pb.FunctionParameters = params.build(&name)
return builder
}
//
// The following _5_ must be copy-pasted at the bottom of **every** _transaction.go file
// We override the embedded fluent setter methods to return the outer type
//
func (builder ContractExecuteTransaction) SetMaxTransactionFee(maxTransactionFee Hbar) ContractExecuteTransaction {
return ContractExecuteTransaction{builder.TransactionBuilder.SetMaxTransactionFee(maxTransactionFee), builder.pb}
}
func (builder ContractExecuteTransaction) SetTransactionMemo(memo string) ContractExecuteTransaction {
return ContractExecuteTransaction{builder.TransactionBuilder.SetTransactionMemo(memo), builder.pb}
}
func (builder ContractExecuteTransaction) SetTransactionValidDuration(validDuration time.Duration) ContractExecuteTransaction {
return ContractExecuteTransaction{builder.TransactionBuilder.SetTransactionValidDuration(validDuration), builder.pb}
}
func (builder ContractExecuteTransaction) SetTransactionID(transactionID TransactionID) ContractExecuteTransaction {
return ContractExecuteTransaction{builder.TransactionBuilder.SetTransactionID(transactionID), builder.pb}
}
func (builder ContractExecuteTransaction) SetNodeAccountID(nodeAccountID AccountID) ContractExecuteTransaction {
return ContractExecuteTransaction{builder.TransactionBuilder.SetNodeAccountID(nodeAccountID), builder.pb}
}