Skip to content

Commit 6252e01

Browse files
Merge pull request #160 from manishdait/topic-client
feat: Added TopicClient to work with topic
2 parents aa7d317 + e907fc1 commit 6252e01

File tree

14 files changed

+1586
-41
lines changed

14 files changed

+1586
-41
lines changed
Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
package com.openelements.hiero.base;
2+
3+
import com.hedera.hashgraph.sdk.PrivateKey;
4+
import com.hedera.hashgraph.sdk.TopicId;
5+
import org.jspecify.annotations.NonNull;
6+
7+
import java.util.Objects;
8+
9+
/**
10+
* Interface for interacting with a Hiero network. This interface provides methods for interacting with Hiero Topic,
11+
* like creating, updating and deleting topic. An implementation of this interface is using an internal account to
12+
* interact with a Hiero network. That account is the account that is used to pay for the transactions that are sent to
13+
* the Hiero network and called 'operator account'.
14+
*/
15+
public interface TopicClient {
16+
/**
17+
* Create a new Topic. The operator account privateKey is used as adminKey for topic.
18+
*
19+
* @return the ID of the new Topic
20+
* @throws HieroException if the Topic could not be created
21+
*/
22+
@NonNull
23+
TopicId createTopic() throws HieroException;
24+
25+
/**
26+
* Create a new Topic. With an adminKey.
27+
*
28+
* @param adminKey the adminKey for the topic
29+
* @return the ID of the new Topic
30+
* @throws HieroException if the Topic could not be created
31+
*/
32+
@NonNull
33+
TopicId createTopic(@NonNull PrivateKey adminKey) throws HieroException;
34+
35+
/**
36+
* Create a new Topic.
37+
*
38+
* @param memo the memo for the topic
39+
* @return the ID of the new Topic
40+
* @throws HieroException if the Topic could not be created
41+
*/
42+
@NonNull
43+
TopicId createTopic(@NonNull String memo) throws HieroException;
44+
45+
/**
46+
* Create a new Topic.
47+
*
48+
* @param adminKey the adminKey for the topic
49+
* @param memo the memo for the topic
50+
* @return the ID of the new Topic
51+
* @throws HieroException if the Topic could not be created
52+
*/
53+
@NonNull
54+
TopicId createTopic(@NonNull PrivateKey adminKey, @NonNull String memo) throws HieroException;
55+
56+
/**
57+
* Create a new private Topic.
58+
*
59+
* @param submitKey the submitKey for the topic
60+
* @return the ID of the new Topic
61+
* @throws HieroException if the Topic could not be created
62+
*/
63+
@NonNull
64+
TopicId createPrivateTopic(@NonNull PrivateKey submitKey) throws HieroException;
65+
66+
/**
67+
* Create a new private Topic.
68+
*
69+
* @param adminKey the adminKey for the topic
70+
* @param submitKey the submitKey for the topic
71+
* @return the ID of the new Topic
72+
* @throws HieroException if the Topic could not be created
73+
*/
74+
@NonNull
75+
TopicId createPrivateTopic(@NonNull PrivateKey adminKey, @NonNull PrivateKey submitKey) throws HieroException;
76+
77+
/**
78+
* Create a new private Topic.
79+
*
80+
* @param submitKey the submitKey for the topic
81+
* @param memo the memo for the topic
82+
* @return the ID of the new Topic
83+
* @throws HieroException if the Topic could not be created
84+
*/
85+
@NonNull
86+
TopicId createPrivateTopic(@NonNull PrivateKey submitKey, @NonNull String memo) throws HieroException;
87+
88+
/**
89+
* Create a new private Topic.
90+
*
91+
* @param adminKey the adminKey for the topic
92+
* @param submitKey the submitKey for the topic
93+
* @param memo the memo for the topic
94+
* @return the ID of the new Topic
95+
* @throws HieroException if the Topic could not be created
96+
*/
97+
@NonNull
98+
TopicId createPrivateTopic(@NonNull PrivateKey adminKey, @NonNull PrivateKey submitKey, @NonNull String memo)
99+
throws HieroException;
100+
101+
/**
102+
* Update a Topic. The operator account privateKey is used as adminKey for updating topic.
103+
*
104+
* @param topicId the topicId of topic to update
105+
* @param memo the memo for the topic
106+
* @throws HieroException if the Topic could not be created
107+
*/
108+
void updateTopic(@NonNull TopicId topicId, @NonNull String memo) throws HieroException;
109+
110+
/**
111+
* Update a Topic.
112+
*
113+
* @param topicId the topicId of topic to update
114+
* @param adminKey the adminKey for topic
115+
* @param memo the memo for the topic
116+
* @throws HieroException if the Topic could not be created
117+
*/
118+
void updateTopic(@NonNull TopicId topicId, @NonNull PrivateKey adminKey, @NonNull String memo)
119+
throws HieroException;
120+
121+
/**
122+
* Update a Topic. The operator account privateKey is used as adminKey for updating topic.
123+
*
124+
* @param topicId the topicId of topic to update
125+
* @param updatedAdminKey the new adminKey for topic
126+
* @param submitKey the new submit for topic
127+
* @param memo the memo for the topic
128+
* @throws HieroException if the Topic could not be created
129+
*/
130+
void updateTopic(@NonNull TopicId topicId, @NonNull PrivateKey updatedAdminKey, @NonNull PrivateKey submitKey,
131+
@NonNull String memo) throws HieroException;
132+
133+
/**
134+
* Update a Topic.
135+
*
136+
* @param topicId the topicId of topic to update
137+
* @param adminKey the adminKey of topic
138+
* @param updatedAdminKey the new adminKey for topic
139+
* @param submitKey the new submit for topic
140+
* @param memo the memo for the topic
141+
* @throws HieroException if the Topic could not be created
142+
*/
143+
void updateTopic(@NonNull TopicId topicId, @NonNull PrivateKey adminKey, @NonNull PrivateKey updatedAdminKey,
144+
@NonNull PrivateKey submitKey, @NonNull String memo) throws HieroException;
145+
146+
/**
147+
* Update adminKey for Topic. The operator account privateKey is used as adminKey for updating topic.
148+
*
149+
* @param topicId the topicId of topic to update
150+
* @param updatedAdminKey the new adminKey for topic
151+
* @throws HieroException if the Topic could not be created
152+
*/
153+
void updateAdminKey(@NonNull TopicId topicId, @NonNull PrivateKey updatedAdminKey) throws HieroException;
154+
155+
/**
156+
* Update adminKey for Topic.
157+
*
158+
* @param topicId the topicId of topic to update
159+
* @param adminKey the adminKey of topic
160+
* @param updatedAdminKey the new adminKey for topic
161+
* @throws HieroException if the Topic could not be created
162+
*/
163+
void updateAdminKey(@NonNull TopicId topicId, @NonNull PrivateKey adminKey, @NonNull PrivateKey updatedAdminKey)
164+
throws HieroException;
165+
166+
/**
167+
* Update submitKey for Topic. The operator account privateKey is used as adminKey for updating topic.
168+
*
169+
* @param topicId the topicId of topic to update
170+
* @param submitKey the new submitKey for topic
171+
* @throws HieroException if the Topic could not be created
172+
*/
173+
void updateSubmitKey(@NonNull TopicId topicId, @NonNull PrivateKey submitKey) throws HieroException;
174+
175+
/**
176+
* Update submitKey for Topic.
177+
*
178+
* @param topicId the topicId of topic to update
179+
* @param adminKey the adminKey of topic
180+
* @param submitKey the new submitKey for topic
181+
* @throws HieroException if the Topic could not be created
182+
*/
183+
void updateSubmitKey(@NonNull TopicId topicId, @NonNull PrivateKey adminKey, @NonNull PrivateKey submitKey)
184+
throws HieroException;
185+
186+
/**
187+
* Delete a Topic.
188+
*
189+
* @param topicId the topicId of topic
190+
* @throws HieroException if the Topic could not be created
191+
*/
192+
void deleteTopic(@NonNull TopicId topicId) throws HieroException;
193+
194+
/**
195+
* Delete a Topic.
196+
*
197+
* @param topicId the topicId of topic
198+
* @throws HieroException if the Topic could not be created
199+
*/
200+
default void deleteTopic(@NonNull String topicId) throws HieroException {
201+
Objects.requireNonNull(topicId, "topicId cannot be null");
202+
deleteTopic(TopicId.fromString(topicId));
203+
};
204+
205+
/**
206+
* Delete a Topic.
207+
*
208+
* @param topicId the topicId of topic
209+
* @throws HieroException if the Topic could not be created
210+
*/
211+
void deleteTopic(@NonNull TopicId topicId, @NonNull PrivateKey adminKey) throws HieroException;
212+
213+
/**
214+
* Delete a Topic.
215+
*
216+
* @param topicId the topicId of topic
217+
* @throws HieroException if the Topic could not be created
218+
*/
219+
default void deleteTopic(@NonNull String topicId, @NonNull String adminKey) throws HieroException {
220+
Objects.requireNonNull(topicId, "topicId cannot be null");
221+
Objects.requireNonNull(adminKey, "adminKey cannot be null");
222+
deleteTopic(TopicId.fromString(topicId), PrivateKey.fromString(adminKey));
223+
};
224+
225+
/**
226+
* Submit a message to a Topic.
227+
*
228+
* @param topicId the topicId of topic
229+
* @param message the message to send to topic
230+
* @throws HieroException if the Topic could not be created
231+
*/
232+
void submitMessage(@NonNull TopicId topicId, @NonNull byte[] message) throws HieroException;
233+
234+
/**
235+
* Submit a message to a Topic.
236+
*
237+
* @param topicId the topicId of topic
238+
* @param message the message to send to topic
239+
* @throws HieroException if the Topic could not be created
240+
*/
241+
default void submitMessage(@NonNull String topicId, @NonNull byte[] message) throws HieroException {
242+
Objects.requireNonNull(topicId, "topicId cannot be null");
243+
Objects.requireNonNull(message, "message cannot be null");
244+
submitMessage(TopicId.fromString(topicId), message);
245+
};
246+
247+
/**
248+
* Submit a message to a Topic.
249+
*
250+
* @param topicId the topicId of topic
251+
* @param message the message to send to topic
252+
* @throws HieroException if the Topic could not be created
253+
*/
254+
void submitMessage(@NonNull TopicId topicId, @NonNull String message) throws HieroException;
255+
256+
/**
257+
* Submit a message to a Topic.
258+
*
259+
* @param topicId the topicId of topic
260+
* @param message the message to send to topic
261+
* @throws HieroException if the Topic could not be created
262+
*/
263+
default void submitMessage(@NonNull String topicId, @NonNull String message) throws HieroException {
264+
Objects.requireNonNull(topicId, "topicId cannot be null");
265+
Objects.requireNonNull(message, "message cannot be null");
266+
submitMessage(TopicId.fromString(topicId), message);
267+
};
268+
269+
/**
270+
* Submit a message to a Topic.
271+
*
272+
* @param topicId the topicId of topic
273+
* @param submitKey the submit key for submitting message
274+
* @param message the message to send to topic
275+
* @throws HieroException if the Topic could not be created
276+
*/
277+
void submitMessage(@NonNull TopicId topicId, @NonNull PrivateKey submitKey, @NonNull byte[] message)
278+
throws HieroException;
279+
280+
/**
281+
* Submit a message to a Topic.
282+
*
283+
* @param topicId the topicId of topic
284+
* @param message the message to send to topic
285+
* @throws HieroException if the Topic could not be created
286+
*/
287+
default void submitMessage(@NonNull String topicId, @NonNull String submitKey, @NonNull byte[] message)
288+
throws HieroException {
289+
Objects.requireNonNull(topicId, "topicId cannot be null");
290+
Objects.requireNonNull(submitKey, "submitKey cannot be null");
291+
Objects.requireNonNull(message, "message cannot be null");
292+
submitMessage(TopicId.fromString(topicId), PrivateKey.fromString(submitKey), message);
293+
};
294+
295+
/**
296+
* Submit a message to a Topic.
297+
*
298+
* @param topicId the topicId of topic
299+
* @param submitKey the submit key for submitting message
300+
* @param message the message to send to topic
301+
* @throws HieroException if the Topic could not be created
302+
*/
303+
void submitMessage(@NonNull TopicId topicId, @NonNull PrivateKey submitKey, @NonNull String message)
304+
throws HieroException;
305+
306+
/**
307+
* Submit a message to a Topic.
308+
*
309+
* @param topicId the topicId of topic
310+
* @param message the message to send to topic
311+
* @throws HieroException if the Topic could not be created
312+
*/
313+
default void submitMessage(@NonNull String topicId, @NonNull String submitKey, @NonNull String message)
314+
throws HieroException {
315+
Objects.requireNonNull(topicId, "topicId cannot be null");
316+
Objects.requireNonNull(submitKey, "submitKey cannot be null");
317+
Objects.requireNonNull(message, "message cannot be null");
318+
submitMessage(TopicId.fromString(topicId), PrivateKey.fromString(submitKey), message);
319+
};
320+
}

0 commit comments

Comments
 (0)