Skip to content

Commit ae5c1a6

Browse files
authored
Merge branch 'OpenElements:main' into issue25
2 parents 43a4e20 + b1f3219 commit ae5c1a6

File tree

18 files changed

+636
-208
lines changed

18 files changed

+636
-208
lines changed

hedera-base/src/main/java/com/openelements/hedera/base/ContractVerificationClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface ContractVerificationClient {
3737
* @param contractName contract name
3838
* @param contractSource contract source code
3939
* @param contractMetadata contract metadata
40-
* @return
40+
* @return verification state
4141
* @throws IllegalStateException if contract is already verified
4242
* @throws HederaException if an error happens in communication with the Hedera network
4343
*/

hedera-base/src/main/java/com/openelements/hedera/base/NftClient.java

Lines changed: 140 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.hedera.hashgraph.sdk.AccountId;
44
import com.hedera.hashgraph.sdk.PrivateKey;
55
import com.hedera.hashgraph.sdk.TokenId;
6+
import java.nio.charset.StandardCharsets;
7+
import java.util.Arrays;
68
import java.util.List;
79
import java.util.Objects;
810
import java.util.Set;
@@ -41,6 +43,22 @@ public interface NftClient {
4143
TokenId createNftType(@NonNull String name, @NonNull String symbol, @NonNull PrivateKey supplierKey)
4244
throws HederaException;
4345

46+
/**
47+
* Create a new NFT type. The operator account is used as treasury account for the NFT type.
48+
*
49+
* @param name the name of the NFT type
50+
* @param symbol the symbol of the NFT type
51+
* @param supplierKey the private key of the supplier account
52+
* @return the ID of the new NFT type
53+
* @throws HederaException if the NFT type could not be created
54+
*/
55+
@NonNull
56+
default TokenId createNftType(@NonNull String name, @NonNull String symbol, @NonNull String supplierKey)
57+
throws HederaException {
58+
Objects.requireNonNull(supplierKey, "supplierKey must not be null");
59+
return createNftType(name, symbol, PrivateKey.fromString(supplierKey));
60+
}
61+
4462
/**
4563
* Create a new NFT type. The operator account is used as supplier account for the NFT type.
4664
*
@@ -55,6 +73,24 @@ TokenId createNftType(@NonNull String name, @NonNull String symbol, @NonNull Pri
5573
TokenId createNftType(@NonNull String name, @NonNull String symbol, @NonNull AccountId treasuryAccountId,
5674
@NonNull PrivateKey treasuryKey) throws HederaException;
5775

76+
/**
77+
* Create a new NFT type. The operator account is used as supplier account for the NFT type.
78+
*
79+
* @param name the name of the NFT type
80+
* @param symbol the symbol of the NFT type
81+
* @param treasuryAccountId the ID of the treasury account
82+
* @param treasuryKey the private key of the treasury account
83+
* @return the ID of the new NFT type
84+
* @throws HederaException if the NFT type could not be created
85+
*/
86+
@NonNull
87+
default TokenId createNftType(@NonNull String name, @NonNull String symbol, @NonNull String treasuryAccountId,
88+
@NonNull String treasuryKey) throws HederaException {
89+
Objects.requireNonNull(treasuryAccountId, "treasuryAccountId must not be null");
90+
Objects.requireNonNull(treasuryKey, "treasuryKey must not be null");
91+
return createNftType(name, symbol, AccountId.fromString(treasuryAccountId), PrivateKey.fromString(treasuryKey));
92+
}
93+
5894
/**
5995
* Create a new NFT type. The operator account is used as supplier account for the NFT type.
6096
*
@@ -87,6 +123,27 @@ default TokenId createNftType(@NonNull String name, @NonNull String symbol, @Non
87123
TokenId createNftType(@NonNull String name, @NonNull String symbol, @NonNull AccountId treasuryAccountId,
88124
@NonNull PrivateKey treasuryKey, @NonNull PrivateKey supplierKey) throws HederaException;
89125

126+
/**
127+
* Create a new NFT type.
128+
*
129+
* @param name the name of the NFT type
130+
* @param symbol the symbol of the NFT type
131+
* @param treasuryAccountId the ID of the treasury account
132+
* @param treasuryKey the private key of the treasury account
133+
* @param supplierKey the private key of the supplier account
134+
* @return the ID of the new NFT type
135+
* @throws HederaException if the NFT type could not be created
136+
*/
137+
@NonNull
138+
default TokenId createNftType(@NonNull String name, @NonNull String symbol, @NonNull String treasuryAccountId,
139+
@NonNull String treasuryKey, @NonNull String supplierKey) throws HederaException {
140+
Objects.requireNonNull(treasuryAccountId, "treasuryAccountId must not be null");
141+
Objects.requireNonNull(treasuryKey, "treasuryKey must not be null");
142+
Objects.requireNonNull(supplierKey, "supplierKey must not be null");
143+
return createNftType(name, symbol, AccountId.fromString(treasuryAccountId), PrivateKey.fromString(treasuryKey),
144+
PrivateKey.fromString(supplierKey));
145+
}
146+
90147
/**
91148
* Create a new NFT type.
92149
*
@@ -117,6 +174,23 @@ default TokenId createNftType(@NonNull String name, @NonNull String symbol, @Non
117174
void associateNft(@NonNull TokenId tokenId, @NonNull AccountId accountId, @NonNull PrivateKey accountKey)
118175
throws HederaException;
119176

177+
/**
178+
* Associate an account with an NFT type. If an account is associated with an NFT type, the account can hold NFTs of
179+
* that type. Otherwise, the account cannot hold NFTs of that type and tranfer NFTs of that type will fail.
180+
*
181+
* @param tokenId the ID of the NFT type
182+
* @param accountId the ID of the account
183+
* @param accountKey the private key of the account
184+
* @throws HederaException if the account could not be associated with the NFT type
185+
*/
186+
default void associateNft(@NonNull String tokenId, @NonNull String accountId, @NonNull String accountKey)
187+
throws HederaException {
188+
Objects.requireNonNull(tokenId, "tokenId must not be null");
189+
Objects.requireNonNull(accountId, "accountId must not be null");
190+
Objects.requireNonNull(accountKey, "accountKey must not be null");
191+
associateNft(TokenId.fromString(tokenId), AccountId.fromString(accountId), PrivateKey.fromString(accountKey));
192+
}
193+
120194
/**
121195
* Associate an account with an NFT type. If an account is associated with an NFT type, the account can hold NFTs of
122196
* that type. Otherwise, the account cannot hold NFTs of that type and tranfer NFTs of that type will fail.
@@ -139,7 +213,21 @@ default void associateNft(@NonNull TokenId tokenId, @NonNull Account account) th
139213
* @return the serial number of the new NFT
140214
* @throws HederaException if the NFT could not be minted
141215
*/
142-
long mintNft(@NonNull TokenId tokenId, @NonNull String metadata) throws HederaException;
216+
long mintNft(@NonNull TokenId tokenId, @NonNull byte[] metadata) throws HederaException;
217+
218+
/**
219+
* Mint a new NFT of the given type. The NFT is minted by the operator account. The operator account is used as
220+
* supply account for the NFT.
221+
*
222+
* @param tokenId the ID of the NFT type
223+
* @param metadata the metadata of the NFT
224+
* @return the serial number of the new NFT
225+
* @throws HederaException if the NFT could not be minted
226+
*/
227+
default long mintNft(@NonNull String tokenId, @NonNull byte[] metadata) throws HederaException {
228+
Objects.requireNonNull(tokenId, "tokenId must not be null");
229+
return mintNft(TokenId.fromString(tokenId), metadata);
230+
}
143231

144232
/**
145233
* Mint a new NFT of the given type.
@@ -150,9 +238,25 @@ default void associateNft(@NonNull TokenId tokenId, @NonNull Account account) th
150238
* @return the serial number of the new NFT
151239
* @throws HederaException if the NFT could not be minted
152240
*/
153-
long mintNft(@NonNull TokenId tokenId, @NonNull String metadata, @NonNull PrivateKey supplyKey)
241+
long mintNft(@NonNull TokenId tokenId, @NonNull PrivateKey supplyKey, @NonNull byte[] metadata)
154242
throws HederaException;
155243

244+
/**
245+
* Mint a new NFT of the given type.
246+
*
247+
* @param tokenId the ID of the NFT type
248+
* @param metadata the metadata of the NFT
249+
* @param supplyKey the private key of the supply account
250+
* @return the serial number of the new NFT
251+
* @throws HederaException if the NFT could not be minted
252+
*/
253+
default long mintNft(@NonNull String tokenId, @NonNull String supplyKey, @NonNull byte[] metadata)
254+
throws HederaException {
255+
Objects.requireNonNull(tokenId, "tokenId must not be null");
256+
Objects.requireNonNull(supplyKey, "supplyKey must not be null");
257+
return mintNft(TokenId.fromString(tokenId), PrivateKey.fromString(supplyKey), metadata);
258+
}
259+
156260
/**
157261
* Mint new NFTs of the given type. The NFTs are minted by the operator account. The operator account is used as
158262
* supply account for the NFTs.
@@ -163,7 +267,22 @@ long mintNft(@NonNull TokenId tokenId, @NonNull String metadata, @NonNull Privat
163267
* @throws HederaException if the NFTs could not be minted
164268
*/
165269
@NonNull
166-
List<Long> mintNfts(@NonNull TokenId tokenId, @NonNull List<String> metadata) throws HederaException;
270+
List<Long> mintNfts(@NonNull TokenId tokenId, @NonNull byte[]... metadata) throws HederaException;
271+
272+
/**
273+
* Mint new NFTs of the given type. The NFTs are minted by the operator account. The operator account is used as
274+
* supply account for the NFTs.
275+
*
276+
* @param tokenId the ID of the NFT type
277+
* @param metadata the metadata of the NFTs
278+
* @return the serial numbers of the new NFTs
279+
* @throws HederaException if the NFTs could not be minted
280+
*/
281+
@NonNull
282+
default List<Long> mintNfts(@NonNull String tokenId, @NonNull byte[]... metadata) throws HederaException {
283+
Objects.requireNonNull(tokenId, "tokenId must not be null");
284+
return mintNfts(TokenId.fromString(tokenId), metadata);
285+
}
167286

168287
/**
169288
* Mint new NFTs of the given type.
@@ -175,9 +294,26 @@ long mintNft(@NonNull TokenId tokenId, @NonNull String metadata, @NonNull Privat
175294
* @throws HederaException if the NFTs could not be minted
176295
*/
177296
@NonNull
178-
List<Long> mintNfts(@NonNull TokenId tokenId, @NonNull List<String> metadata, @NonNull PrivateKey supplyKey)
297+
List<Long> mintNfts(@NonNull TokenId tokenId, @NonNull PrivateKey supplyKey, @NonNull byte[]... metadata)
179298
throws HederaException;
180299

300+
/**
301+
* Mint new NFTs of the given type.
302+
*
303+
* @param tokenId the ID of the NFT type
304+
* @param metadata the metadata of the NFTs
305+
* @param supplyKey the private key of the supply account
306+
* @return the serial numbers of the new NFTs
307+
* @throws HederaException if the NFTs could not be minted
308+
*/
309+
@NonNull
310+
default List<Long> mintNfts(@NonNull String tokenId, @NonNull String supplyKey, @NonNull byte[]... metadata)
311+
throws HederaException {
312+
Objects.requireNonNull(tokenId, "tokenId must not be null");
313+
Objects.requireNonNull(supplyKey, "supplyKey must not be null");
314+
return mintNfts(TokenId.fromString(tokenId), PrivateKey.fromString(supplyKey), metadata);
315+
}
316+
181317
default void burnNft(@NonNull TokenId tokenId, long serialNumber) throws HederaException {
182318
burnNfts(tokenId, Set.of(serialNumber));
183319
}

hedera-base/src/main/java/com/openelements/hedera/base/NftRepository.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.hedera.hashgraph.sdk.TokenId;
55
import com.openelements.hedera.base.mirrornode.Page;
66
import java.util.List;
7+
import java.util.Objects;
78
import java.util.Optional;
89
import org.jspecify.annotations.NonNull;
910

@@ -22,6 +23,19 @@ public interface NftRepository {
2223
@NonNull
2324
Page<Nft> findByOwner(@NonNull AccountId ownerId) throws HederaException;
2425

26+
/**
27+
* Return all NFTs that are owned by the given owner.
28+
*
29+
* @param ownerId id of the owner account
30+
* @return list of NFTs
31+
* @throws HederaException if the search fails
32+
*/
33+
@NonNull
34+
default List<Nft> findByOwner(@NonNull String ownerId) throws HederaException {
35+
Objects.requireNonNull(ownerId, "ownerId must not be null");
36+
return findByOwner(AccountId.fromString(ownerId));
37+
}
38+
2539
/**
2640
* Return all NFTs of a given type.
2741
*
@@ -32,6 +46,19 @@ public interface NftRepository {
3246
@NonNull
3347
Page<Nft> findByType(@NonNull TokenId tokenId) throws HederaException;
3448

49+
/**
50+
* Return all NFTs of a given type.
51+
*
52+
* @param tokenId id of the token type
53+
* @return list of NFTs
54+
* @throws HederaException if the search fails
55+
*/
56+
@NonNull
57+
default Page<Nft> findByType(@NonNull String tokenId) throws HederaException {
58+
Objects.requireNonNull(tokenId, "tokenId must not be null");
59+
return findByType(TokenId.fromString(tokenId));
60+
}
61+
3562
/**
3663
* Return the NFTs of a given type with the given serial.
3764
*
@@ -43,6 +70,20 @@ public interface NftRepository {
4370
@NonNull
4471
Optional<Nft> findByTypeAndSerial(@NonNull TokenId tokenId, long serialNumber) throws HederaException;
4572

73+
/**
74+
* Return the NFTs of a given type with the given serial.
75+
*
76+
* @param tokenId id of the token type
77+
* @param serialNumber serial of the nft instance
78+
* @return {@link Optional} containing the found NFT or null
79+
* @throws HederaException if the search fails
80+
*/
81+
@NonNull
82+
default Optional<Nft> findByTypeAndSerial(@NonNull String tokenId, long serialNumber) throws HederaException {
83+
Objects.requireNonNull(tokenId, "tokenId must not be null");
84+
return findByTypeAndSerial(TokenId.fromString(tokenId), serialNumber);
85+
}
86+
4687
/**
4788
* Return all NFTs of a given type owned by a specific account.
4889
*
@@ -54,6 +95,21 @@ public interface NftRepository {
5495
@NonNull
5596
Page<Nft> findByOwnerAndType(@NonNull AccountId ownerId, @NonNull TokenId tokenId) throws HederaException;
5697

98+
/**
99+
* Return all NFTs of a given type owned by a specific account.
100+
*
101+
* @param ownerId id of the owner
102+
* @param tokenId id of the token type
103+
* @return list of NFTs
104+
* @throws HederaException if the search fails
105+
*/
106+
@NonNull
107+
default List<Nft> findByOwnerAndType(@NonNull String ownerId, @NonNull String tokenId) throws HederaException {
108+
Objects.requireNonNull(ownerId, "ownerId must not be null");
109+
Objects.requireNonNull(tokenId, "tokenId must not be null");
110+
return findByOwnerAndType(AccountId.fromString(ownerId), TokenId.fromString(tokenId));
111+
}
112+
57113
/**
58114
* Return the NFT of a given type and serial owned by a specific account.
59115
*
@@ -66,4 +122,21 @@ public interface NftRepository {
66122
@NonNull
67123
Optional<Nft> findByOwnerAndTypeAndSerial(@NonNull AccountId owner, @NonNull TokenId tokenId, long serialNumber)
68124
throws HederaException;
125+
126+
/**
127+
* Return the NFT of a given type and serial owned by a specific account.
128+
*
129+
* @param owner id of the owner
130+
* @param tokenId id of the token type
131+
* @param serialNumber serial of the nft instance
132+
* @return {@link Optional} containing the found NFT or null
133+
* @throws HederaException if the search fails
134+
*/
135+
@NonNull
136+
default Optional<Nft> findByOwnerAndTypeAndSerial(@NonNull String owner, @NonNull String tokenId, long serialNumber)
137+
throws HederaException {
138+
Objects.requireNonNull(owner, "owner must not be null");
139+
Objects.requireNonNull(tokenId, "tokenId must not be null");
140+
return findByOwnerAndTypeAndSerial(AccountId.fromString(owner), TokenId.fromString(tokenId), serialNumber);
141+
}
69142
}

0 commit comments

Comments
 (0)