-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSmartContractClient.java
More file actions
265 lines (247 loc) · 10.6 KB
/
Copy pathSmartContractClient.java
File metadata and controls
265 lines (247 loc) · 10.6 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package org.hiero.base;
import static org.hiero.base.implementation.ProtocolLayerClientImpl.DEFAULT_GAS;
import static org.hiero.base.protocol.data.ContractCreateRequest.DEFAULT_CONTRACT_CREATE_TRANSACTION_FEE;
import static org.hiero.base.protocol.data.TransactionRequest.DEFAULT_MAX_TRANSACTION_FEE;
import com.hedera.hashgraph.sdk.ContractId;
import com.hedera.hashgraph.sdk.FileId;
import com.hedera.hashgraph.sdk.Hbar;
import java.nio.file.Path;
import java.util.Objects;
import org.hiero.base.data.ContractCallResult;
import org.hiero.base.data.ContractParam;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
/**
* A client for interacting with the smart contract service on a Hiero network. An implementation of
* this interface is using an internal account to interact with a Hiero network. That account is the
* account that is used to pay for the transactions that are sent to a Hiero network and called
* 'operator account'.
*/
public interface SmartContractClient {
/**
* Create a new smart contract based on the file the given file ID. The file must contain the
* bytecode for the contract.
*
* @param fileId the ID of the file containing the contract bytecode
* @param constructorParams the parameters to pass to the contract constructor
* @return the ID of the new contract
* @throws HieroException if the contract could not be created
*/
@NonNull
default ContractId createContract(
@NonNull String fileId, @Nullable ContractParam<?>... constructorParams)
throws HieroException {
Objects.requireNonNull(fileId, "fileId must not be null");
return createContract(
FileId.fromString(fileId),
DEFAULT_CONTRACT_CREATE_TRANSACTION_FEE,
DEFAULT_GAS,
constructorParams);
}
/**
* Create a new smart contract based on the file the given file ID. The file must contain the
* bytecode for the contract.
*
* @param fileId the ID of the file containing the contract bytecode
* @param constructorParams the parameters to pass to the contract constructor
* @return the ID of the new contract
* @throws HieroException if the contract could not be created
*/
default @NonNull ContractId createContract(
@NonNull FileId fileId, @Nullable ContractParam<?>... constructorParams)
throws HieroException {
Objects.requireNonNull(fileId, "fileId must not be null");
return createContract(
fileId, DEFAULT_CONTRACT_CREATE_TRANSACTION_FEE, DEFAULT_GAS, constructorParams);
}
/**
* Create a new smart contract with the given contents. The contents must be the bytecode for the
* contract.
*
* @param contents the contents of the contract
* @param constructorParams the parameters to pass to the contract constructor
* @return the ID of the new contract
* @throws HieroException if the contract could not be created
*/
default @NonNull ContractId createContract(
@NonNull byte[] contents, @Nullable ContractParam<?>... constructorParams)
throws HieroException {
Objects.requireNonNull(contents, "contents must not be null");
return createContract(
contents, DEFAULT_CONTRACT_CREATE_TRANSACTION_FEE, DEFAULT_GAS, constructorParams);
}
/**
* Create a new smart contract based on a file. The contents of the file must be the bytecode for
* the contract.
*
* @param pathToBin the path to the file containing the contract bytecode
* @param constructorParams the parameters to pass to the contract constructor
* @return the ID of the new contract
* @throws HieroException if the contract could not be created
*/
default @NonNull ContractId createContract(
@NonNull Path pathToBin, @Nullable ContractParam<?>... constructorParams)
throws HieroException {
Objects.requireNonNull(pathToBin, "pathToBin must not be null");
return createContract(
pathToBin, DEFAULT_CONTRACT_CREATE_TRANSACTION_FEE, DEFAULT_GAS, constructorParams);
}
/**
* Create a new smart contract based on the file the given file ID, using a custom max transaction
* fee and gas. The file must contain the bytecode for the contract.
*
* @param fileId the ID of the file containing the contract bytecode
* @param maxTransactionFee the custom max transaction fee in Hbar
* @param gas the custom max gas that can be spent
* @param constructorParams the parameters to pass to the contract constructor
* @return the ID of the new contract
* @throws HieroException if the contract could not be created
*/
default @NonNull ContractId createContract(
@NonNull String fileId,
@NonNull Hbar maxTransactionFee,
int gas,
@Nullable ContractParam<?>... constructorParams)
throws HieroException {
Objects.requireNonNull(fileId, "fileId must not be null");
Objects.requireNonNull(maxTransactionFee, "maxTransactionFee must not be null");
return createContract(FileId.fromString(fileId), maxTransactionFee, gas, constructorParams);
}
/**
* Create a new smart contract based on the file with the given file ID, using a custom max
* transaction fee and gas. The file must contain the bytecode for the contract.
*
* @param fileId the ID of the file containing the contract bytecode
* @param maxTransactionFee the custom max transaction fee in Hbar
* @param gas the custom max gas that can be spent
* @param constructorParams the parameters to pass to the contract constructor
* @return the ID of the new contract
* @throws HieroException if the contract could not be created
*/
@NonNull ContractId createContract(
@NonNull FileId fileId,
@NonNull Hbar maxTransactionFee,
int gas,
@Nullable ContractParam<?>... constructorParams)
throws HieroException;
/**
* Create a new smart contract with the given contents, using a custom maximum transaction fee and
* gas. The contents must be the bytecode for the contract.
*
* @param contents the contents of the contract
* @param maxTransactionFee the custom max transaction fee in Hbar
* @param gas the custom max gas that can be spent
* @param constructorParams the parameters to pass to the contract constructor
* @return the ID of the new contract
* @throws HieroException if the contract could not be created
*/
@NonNull ContractId createContract(
@NonNull byte[] contents,
@NonNull Hbar maxTransactionFee,
int gas,
@Nullable ContractParam<?>... constructorParams)
throws HieroException;
/**
* Create a new smart contract based on a local file, using a custom maximum transaction fee and
* gas. The contents of the file must be the bytecode for the contract.
*
* @param pathToBin the path to the file containing the contract bytecode
* @param maxTransactionFee the custom max transaction fee in Hbar
* @param gas the custom max gas that can be spent
* @param constructorParams the parameters to pass to the contract constructor
* @return the ID of the new contract
* @throws HieroException if the contract could not be created
*/
@NonNull ContractId createContract(
@NonNull Path pathToBin,
@NonNull Hbar maxTransactionFee,
int gas,
@Nullable ContractParam<?>... constructorParams)
throws HieroException;
/**
* Call a function on a smart contract.
*
* @param contractId the ID of the contract
* @param functionName the name of the function to call
* @param params the parameters to pass to the function
* @return the result of the function call
* @throws HieroException if the function could not be called
*/
@NonNull
default ContractCallResult callContractFunction(
@NonNull String contractId,
@NonNull String functionName,
@Nullable ContractParam<?>... params)
throws HieroException {
Objects.requireNonNull(contractId, "contractId must not be null");
Objects.requireNonNull(functionName, "functionName must not be null");
return callContractFunction(
ContractId.fromString(contractId),
functionName,
DEFAULT_MAX_TRANSACTION_FEE,
DEFAULT_GAS,
params);
}
/**
* Call a function on a smart contract.
*
* @param contractId the ID of the contract
* @param functionName the name of the function to call
* @param params the parameters to pass to the function
* @return the result of the function call
* @throws HieroException if the function could not be called
*/
default @NonNull ContractCallResult callContractFunction(
@NonNull ContractId contractId,
@NonNull String functionName,
@Nullable ContractParam<?>... params)
throws HieroException {
Objects.requireNonNull(contractId, "contractId must not be null");
Objects.requireNonNull(functionName, "functionName must not be null");
return callContractFunction(
contractId, functionName, DEFAULT_MAX_TRANSACTION_FEE, DEFAULT_GAS, params);
}
/**
* Call a function on a smart contract with custom max transaction fee and gas.
*
* @param contractId the ID of the contract
* @param functionName the name of the function to call
* @param maxTransactionFee the custom max transaction fee in Hbar
* @param gas the custom max gas that can be spent
* @param params the parameters to pass to the function
* @return the result of the function call
* @throws HieroException if the function could not be called
*/
@NonNull
default ContractCallResult callContractFunction(
@NonNull String contractId,
@NonNull String functionName,
@NonNull Hbar maxTransactionFee,
int gas,
@Nullable ContractParam<?>... params)
throws HieroException {
Objects.requireNonNull(contractId, "contractId must not be null");
Objects.requireNonNull(functionName, "functionName must not be null");
Objects.requireNonNull(maxTransactionFee, "maxTransactionFee must not be null");
return callContractFunction(
ContractId.fromString(contractId), functionName, maxTransactionFee, gas, params);
}
/**
* Call a function on a smart contract with custom max transaction fee and gas.
*
* @param contractId the ID of the contract
* @param functionName the name of the function to call
* @param maxTransactionFee the custom max transaction fee in Hbar
* @param gas the custom max gas that can be spent
* @param params the parameters to pass to the function
* @return the result of the function call
* @throws HieroException if the function could not be called
*/
@NonNull ContractCallResult callContractFunction(
@NonNull ContractId contractId,
@NonNull String functionName,
@NonNull Hbar maxTransactionFee,
int gas,
@Nullable ContractParam<?>... params)
throws HieroException;
}