Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
This project provides Java modules to integrate [Hedera network](https://hedera.com) smoothless in a Spring Boot or Eclipse Microprofile (like Quarkus) application.
This module is based on the [Hedera Java SDK](https://github.com/hashgraph/hedera-sdk-java).

> [!NOTE]
> The repo is currently transformed to be compatible with the vendor neutral [Hiero](hiero.org) project.
> Hedera is 100% compatible with Hiero and the transformation is just a renaming of the packages, classes, documentation, and so on.
> The transformation is still in progress and not all is renamed yet.

## Spring Boot support

To use this module, you need to add the following dependency to your project:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.jspecify.annotations.NonNull;

/**
* Represents a Hedera account.
* Represents an account of a Hiero network.
*
* @param accountId the ID of the account
* @param publicKey the public key of the account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@
import org.jspecify.annotations.NonNull;

/**
* Interface for interacting with a Hedera network. This interface provides methods for interacting with Hedera
* Interface for interacting with a Hiero network. This interface provides methods for interacting with Hedera
* accounts, like creating and deleting accounts. An implementation of this interface is using an internal account to
* interact with the Hedera network. That account is the account that is used to pay for the transactions that are sent
* to the Hedera network and called 'operator account'.
* interact with a Hiero network. That account is the account that is used to pay for the transactions that are sent
* to the network and called 'operator account'.
*/
public interface AccountClient {

/**
* Creates a new Hedera account. The account is created with an initial balance of 0 hbar. The account is created by
* Creates a new account. The account is created with an initial balance of 0 hbar. The account is created by
* the operator account.
*
* @return the created account
* @throws HederaException if the account could not be created
* @throws HieroException if the account could not be created
*/
@NonNull
default Account createAccount() throws HederaException {
default Account createAccount() throws HieroException {
return createAccount(Hbar.ZERO);
}

/**
* Creates a new Hedera account with the given initial balance. The account is created by the operator account.
* Creates a new account with the given initial balance. The account is created by the operator account.
*
* @param initialBalance the initial balance of the account
* @return the created account
* @throws HederaException if the account could not be created
* @throws HieroException if the account could not be created
*/
@NonNull
Account createAccount(@NonNull Hbar initialBalance) throws HederaException;
Account createAccount(@NonNull Hbar initialBalance) throws HieroException;

/**
* Creates a new Hedera account with the given initial balance (in HBAR). The account is created by the operator
* Creates a new account with the given initial balance (in HBAR). The account is created by the operator
* account.
*
* @param initialBalanceInHbar the initial balance of the account in HBAR
* @return the created account
* @throws HederaException if the account could not be created
* @throws HieroException if the account could not be created
*/
@NonNull
default Account createAccount(long initialBalanceInHbar) throws HederaException {
default Account createAccount(long initialBalanceInHbar) throws HieroException {
if (initialBalanceInHbar < 0) {
throw new IllegalArgumentException("initialBalanceInHbar must be non-negative");
}
Expand All @@ -55,38 +55,38 @@ default Account createAccount(long initialBalanceInHbar) throws HederaException
* Deletes the account with the given ID. All fees of that account are transferred to the operator account.
*
* @param account the account to delete
* @throws HederaException if the account could not be deleted
* @throws HieroException if the account could not be deleted
*/
void deleteAccount(@NonNull Account account) throws HederaException;
void deleteAccount(@NonNull Account account) throws HieroException;

/**
* Deletes the account with the given ID. All fees of that account are transferred to the given toAccount.
*
* @param account the account to delete
* @param toAccount the account to transfer the fees to
* @throws HederaException if the account could not be deleted
* @throws HieroException if the account could not be deleted
*/
void deleteAccount(@NonNull Account account, @NonNull Account toAccount) throws HederaException;
void deleteAccount(@NonNull Account account, @NonNull Account toAccount) throws HieroException;

/**
* Returns the balance of the given account.
*
* @param accountId the ID of the account
* @return the balance of the account
* @throws HederaException if the balance could not be retrieved
* @throws HieroException if the balance could not be retrieved
*/
@NonNull
Hbar getAccountBalance(@NonNull AccountId accountId) throws HederaException;
Hbar getAccountBalance(@NonNull AccountId accountId) throws HieroException;

/**
* Returns the balance of the given account.
*
* @param accountId the ID of the account
* @return the balance of the account
* @throws HederaException if the balance could not be retrieved
* @throws HieroException if the balance could not be retrieved
*/
@NonNull
default Hbar getAccountBalance(@NonNull String accountId) throws HederaException {
default Hbar getAccountBalance(@NonNull String accountId) throws HieroException {
Objects.requireNonNull(accountId, "newAccountId must not be null");
return getAccountBalance(AccountId.fromString(accountId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
import org.jspecify.annotations.NonNull;

/**
* Interface for interacting with a Hedera network. This interface provides methods for searching for Accounts.
* Interface for interacting with a Hiero network. This interface provides methods for searching for Accounts.
*/
public interface AccountRepository {
/**
* Return the AccountInfo of a given accountId.
*
* @param accountId id of the account
* @return {@link Optional} containing the found AccountInfo or null
* @throws HederaException if the search fails
* @throws HieroException if the search fails
*/
Optional<AccountInfo> findById(@NonNull AccountId accountId) throws HederaException;
Optional<AccountInfo> findById(@NonNull AccountId accountId) throws HieroException;

/**
* Return the AccountInfo of a given accountId.
*
* @param accountId id of the account
* @return {@link Optional} containing the found AccountInfo or null
* @throws HederaException if the search fails
* @throws HieroException if the search fails
*/
default Optional<AccountInfo> findById(@NonNull String accountId) throws HederaException {
default Optional<AccountInfo> findById(@NonNull String accountId) throws HieroException {
Objects.requireNonNull(accountId, "accountId must not be null");
return findById(AccountId.fromString(accountId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.jspecify.annotations.NonNull;

/**
* Client for verifying contracts on the Hedera network. This client is used to check the verification state of a smart
* Client for verifying contracts on a Hiero network. This client is used to check the verification state of a smart
* contract and to verify a smart contract. Currently only the Hedera mainnet, testnet and previewnet is supported.
*/
public interface ContractVerificationClient {
Expand All @@ -15,10 +15,10 @@ public interface ContractVerificationClient {
*
* @param contractId contract to check
* @return verification state
* @throws HederaException if an error happens in communication with the Hedera network
* @throws HieroException if an error happens in communication with a Hiero network
*/
@NonNull
ContractVerificationState checkVerification(@NonNull ContractId contractId) throws HederaException;
ContractVerificationState checkVerification(@NonNull ContractId contractId) throws HieroException;

/**
* Check the verification state of a file that is part of a contract.
Expand All @@ -28,10 +28,10 @@ public interface ContractVerificationClient {
* @param fileContent file content
* @return true if the contract contains is verified and contains a file with the given name and content
* @throws IllegalStateException if contract is not verified
* @throws HederaException if an error happens in communication with the Hedera network
* @throws HieroException if an error happens in communication with a Hiero network
*/
boolean checkVerification(@NonNull ContractId contractId, @NonNull String fileName, @NonNull String fileContent)
throws HederaException;
throws HieroException;

/**
* Try to verify a contract.
Expand All @@ -42,11 +42,11 @@ boolean checkVerification(@NonNull ContractId contractId, @NonNull String fileNa
* @param contractMetadata contract metadata
* @return verification state
* @throws IllegalStateException if contract is already verified
* @throws HederaException if an error happens in communication with the Hedera network
* @throws HieroException if an error happens in communication with a Hiero network
*/
@NonNull
default ContractVerificationState verify(@NonNull final ContractId contractId, @NonNull final String contractName,
@NonNull final String contractSource, final String contractMetadata) throws HederaException {
@NonNull final String contractSource, final String contractMetadata) throws HieroException {
return verify(contractId, contractName,
Map.of(contractName + ".sol", contractSource, "metadata.json", contractMetadata));
}
Expand All @@ -59,9 +59,9 @@ default ContractVerificationState verify(@NonNull final ContractId contractId, @
* @param files contract files
* @return verification state
* @throws IllegalStateException if contract is already verified
* @throws HederaException if an error happens in communication with the Hedera network
* @throws HieroException if an error happens in communication with a Hiero network
*/
@NonNull
ContractVerificationState verify(@NonNull ContractId contractId, @NonNull String contractName,
@NonNull Map<String, String> files) throws HederaException;
@NonNull Map<String, String> files) throws HieroException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import org.jspecify.annotations.NonNull;

/**
* A client for interacting with the file service on the Hedera network. An implementation of this interface is using an
* internal account to interact with the Hedera network. That account is the account that is used to pay for the
* transactions that are sent to the Hedera network and called 'operator account'.
* A client for interacting with the file 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 FileClient {

Expand All @@ -17,22 +17,22 @@ public interface FileClient {
*
* @param contents the contents of the file
* @return the ID of the new file
* @throws HederaException if the file could not be created
* @throws HieroException if the file could not be created
*/
@NonNull
FileId createFile(@NonNull byte[] contents) throws HederaException;
FileId createFile(@NonNull byte[] contents) throws HieroException;

FileId createFile(@NonNull byte[] contents, @NonNull Instant expirationTime) throws HederaException;
FileId createFile(@NonNull byte[] contents, @NonNull Instant expirationTime) throws HieroException;

/**
* Create a new file with the given contents.
*
* @param fileId the ID of the file to update
* @return the ID of the new file
* @throws HederaException if the file could not be created
* @throws HieroException if the file could not be created
*/
@NonNull
default byte[] readFile(@NonNull String fileId) throws HederaException {
default byte[] readFile(@NonNull String fileId) throws HieroException {
Objects.requireNonNull(fileId, "fileId must not be null");
return readFile(FileId.fromString(fileId));
}
Expand All @@ -42,71 +42,71 @@ default byte[] readFile(@NonNull String fileId) throws HederaException {
*
* @param fileId the ID of the file to read
* @return the contents of the file
* @throws HederaException if the file could not be read
* @throws HieroException if the file could not be read
*/
@NonNull
byte[] readFile(@NonNull FileId fileId) throws HederaException;
byte[] readFile(@NonNull FileId fileId) throws HieroException;

/**
* Delete a file.
*
* @param fileId the ID of the file to delete
* @throws HederaException if the file could not be deleted
* @throws HieroException if the file could not be deleted
*/
default void deleteFile(@NonNull String fileId) throws HederaException {
default void deleteFile(@NonNull String fileId) throws HieroException {
deleteFile(FileId.fromString(fileId));
}

/**
* Delete a file.
*
* @param fileId the ID of the file to delete
* @throws HederaException if the file could not be deleted
* @throws HieroException if the file could not be deleted
*/
void deleteFile(@NonNull FileId fileId) throws HederaException;
void deleteFile(@NonNull FileId fileId) throws HieroException;

/**
* Update the contents of a file.
*
* @param fileId the ID of the file to update
* @param content the new contents of the file
* @throws HederaException if the file could not be updated
* @throws HieroException if the file could not be updated
*/
void updateFile(@NonNull FileId fileId, byte[] content) throws HederaException;
void updateFile(@NonNull FileId fileId, byte[] content) throws HieroException;

/**
* Update the expiration time of a file.
*
* @param fileId the ID of the file to update
* @param expirationTime the new expiration time of the file
* @throws HederaException if the file could not be updated
* @throws HieroException if the file could not be updated
*/
void updateExpirationTime(@NonNull FileId fileId, @NonNull Instant expirationTime) throws HederaException;
void updateExpirationTime(@NonNull FileId fileId, @NonNull Instant expirationTime) throws HieroException;

/**
* Check if a file is deleted.
*
* @param fileId the ID of the file to check
* @return true if the file is deleted, false otherwise
* @throws HederaException if the file could not be checked
* @throws HieroException if the file could not be checked
*/
boolean isDeleted(@NonNull FileId fileId) throws HederaException;
boolean isDeleted(@NonNull FileId fileId) throws HieroException;

/**
* Get the size of a file.
*
* @param fileId the ID of the file to check
* @return the size of the file
* @throws HederaException if the file could not be checked
* @throws HieroException if the file could not be checked
*/
int getSize(@NonNull FileId fileId) throws HederaException;
int getSize(@NonNull FileId fileId) throws HieroException;

/**
* Get the expiration time of a file.
*
* @param fileId the ID of the file to check
* @return the expiration time of the file
* @throws HederaException if the file could not be checked
* @throws HieroException if the file could not be checked
*/
Instant getExpirationTime(@NonNull FileId fileId) throws HederaException;
Instant getExpirationTime(@NonNull FileId fileId) throws HieroException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.time.Duration;
import org.jspecify.annotations.NonNull;

public interface HederaContext {
public interface HieroContext {

@NonNull
Account getOperatorAccount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
import org.jspecify.annotations.NonNull;

/**
* Represents an exception that occurred while interacting with the Hedera network.
* Represents an exception that occurred while interacting with a Hiero network.
*/
public class HederaException extends Exception {
public class HieroException extends Exception {

/**
* Constructs a new HederaException with the specified detail message.
* Constructs a new Exception with the specified detail message.
*
* @param message The detail message.
*/
public HederaException(@NonNull String message) {
public HieroException(@NonNull String message) {
super(message);
}

/**
* Constructs a new HederaException with the specified detail message and cause.
* Constructs a new Exception with the specified detail message and cause.
*
* @param message The detail message.
* @param cause The cause.
*/
public HederaException(@NonNull String message, @NonNull Throwable cause) {
public HieroException(@NonNull String message, @NonNull Throwable cause) {
super(message, cause);
}
}
Loading