Skip to content

Commit 768ccfb

Browse files
Merge pull request #118 from OpenElements/context
context interface added, tests based on modules
2 parents 09a33d2 + 7fdc44e commit 768ccfb

File tree

67 files changed

+315
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+315
-231
lines changed

hiero-base/src/main/java/com/openelements/hiero/base/AccountClient.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
import com.hedera.hashgraph.sdk.AccountId;
44
import com.hedera.hashgraph.sdk.Hbar;
5+
import com.openelements.hiero.base.data.Account;
56
import java.util.Objects;
67
import org.jspecify.annotations.NonNull;
78

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

1617
/**
17-
* Creates a new account. The account is created with an initial balance of 0 hbar. The account is created by
18-
* the operator account.
18+
* Creates a new account. The account is created with an initial balance of 0 hbar. The account is created by the
19+
* operator account.
1920
*
2021
* @return the created account
2122
* @throws HieroException if the account could not be created
@@ -36,8 +37,7 @@ default Account createAccount() throws HieroException {
3637
Account createAccount(@NonNull Hbar initialBalance) throws HieroException;
3738

3839
/**
39-
* Creates a new account with the given initial balance (in HBAR). The account is created by the operator
40-
* account.
40+
* Creates a new account with the given initial balance (in HBAR). The account is created by the operator account.
4141
*
4242
* @param initialBalanceInHbar the initial balance of the account in HBAR
4343
* @return the created account
Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.openelements.hiero.base;
22

33
import com.hedera.hashgraph.sdk.Client;
4-
import com.hedera.hashgraph.sdk.Hbar;
5-
import com.openelements.hiero.base.protocol.TransactionType;
6-
import java.time.Duration;
4+
import com.openelements.hiero.base.data.Account;
75
import org.jspecify.annotations.NonNull;
86

97
public interface HieroContext {
@@ -13,25 +11,4 @@ public interface HieroContext {
1311

1412
@NonNull
1513
Client getClient();
16-
17-
@NonNull
18-
Hbar getDefaultMaxTransactionFee();
19-
20-
@NonNull
21-
Duration getDefaultTransactionValidDuration();
22-
23-
void setDefaultMaxTransactionFee(@NonNull Hbar maxTransactionFee);
24-
25-
void setDefaultTransactionValidDuration(@NonNull Duration transactionValidDuration);
26-
27-
@NonNull
28-
Hbar getDefaultMaxTransactionFee(@NonNull TransactionType transactionType);
29-
30-
@NonNull
31-
Duration getDefaultTransactionValidDuration(@NonNull TransactionType transactionType);
32-
33-
void setDefaultMaxTransactionFee(@NonNull TransactionType transactionType, @NonNull Hbar maxTransactionFee);
34-
35-
void setDefaultTransactionValidDuration(@NonNull TransactionType transactionType,
36-
@NonNull Duration transactionValidDuration);
3714
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
import com.hedera.hashgraph.sdk.AccountId;
44
import com.hedera.hashgraph.sdk.PrivateKey;
55
import com.hedera.hashgraph.sdk.TokenId;
6+
import com.openelements.hiero.base.data.Account;
67
import java.util.List;
78
import java.util.Objects;
89
import java.util.Set;
910
import org.jspecify.annotations.NonNull;
1011

1112
/**
1213
* Interface for interacting with a Hiero network. This interface provides methods for interacting with Hedera NFTs,
13-
* like creating and deleting NFTs. An implementation of this interface is using an internal account to interact with
14-
* a Hiero network. That account is the account that is used to pay for the transactions that are sent to the Hedera
14+
* like creating and deleting NFTs. An implementation of this interface is using an internal account to interact with a
15+
* Hiero network. That account is the account that is used to pay for the transactions that are sent to the Hedera
1516
* network and called 'operator account'.
1617
*/
1718
public interface NftClient {

hiero-base/src/main/java/com/openelements/hiero/base/SmartContractClient.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import com.hedera.hashgraph.sdk.ContractId;
44
import com.hedera.hashgraph.sdk.FileId;
5+
import com.openelements.hiero.base.data.ContractParam;
56
import java.nio.file.Path;
67
import java.util.Objects;
78
import org.jspecify.annotations.NonNull;
89
import org.jspecify.annotations.Nullable;
910

1011
/**
11-
* A client for interacting with the smart contract service on a Hiero network. An implementation of this interface
12-
* is using an internal account to interact with a Hiero network. That account is the account that is used to pay for
13-
* the transactions that are sent to a Hiero network and called 'operator account'.
12+
* A client for interacting with the smart contract service on a Hiero network. An implementation of this interface is
13+
* using an internal account to interact with a Hiero network. That account is the account that is used to pay for the
14+
* transactions that are sent to a Hiero network and called 'operator account'.
1415
*/
1516
public interface SmartContractClient {
1617

hiero-base/src/main/java/com/openelements/hiero/base/config/HieroConfig.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import com.hedera.hashgraph.sdk.AccountId;
44
import com.hedera.hashgraph.sdk.Client;
5-
import com.openelements.hiero.base.Account;
5+
import com.openelements.hiero.base.HieroContext;
6+
import com.openelements.hiero.base.data.Account;
67
import com.openelements.hiero.base.implementation.HieroNetwork;
78
import java.util.List;
89
import java.util.Map;
@@ -17,15 +18,37 @@ public interface HieroConfig {
1718

1819
final static Logger log = LoggerFactory.getLogger(HieroConfig.class);
1920

20-
@NonNull Account getOperatorAccount();
21+
@NonNull
22+
Account getOperatorAccount();
23+
24+
@NonNull
25+
Optional<String> getNetworkName();
2126

22-
@NonNull Optional<String> getNetworkName();
27+
@NonNull
28+
List<String> getMirrornodeAddresses();
29+
30+
@NonNull
31+
Set<ConsensusNode> getConsensusNodes();
2332

24-
@NonNull List<String> getMirrornodeAddresses();
33+
@NonNull
34+
HieroNetwork getNetwork();
2535

26-
@NonNull Set<ConsensusNode> getConsensusNodes();
36+
@NonNull
37+
default HieroContext createHieroContext() {
38+
final Account operatorAccount = getOperatorAccount();
39+
final Client client = createClient();
40+
return new HieroContext() {
41+
@Override
42+
public @NonNull Account getOperatorAccount() {
43+
return operatorAccount;
44+
}
2745

28-
@NonNull HieroNetwork getNetwork();
46+
@Override
47+
public @NonNull Client getClient() {
48+
return client;
49+
}
50+
};
51+
}
2952

3053
@NonNull
3154
default Client createClient() {

hiero-base/src/main/java/com/openelements/hiero/base/Account.java renamed to hiero-base/src/main/java/com/openelements/hiero/base/data/Account.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.openelements.hiero.base;
1+
package com.openelements.hiero.base.data;
22

33
import com.hedera.hashgraph.sdk.AccountId;
44
import com.hedera.hashgraph.sdk.PrivateKey;

hiero-base/src/main/java/com/openelements/hiero/base/mirrornode/AccountInfo.java renamed to hiero-base/src/main/java/com/openelements/hiero/base/data/AccountInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.openelements.hiero.base.mirrornode;
1+
package com.openelements.hiero.base.data;
22

33
import com.hedera.hashgraph.sdk.AccountBalance;
44
import com.hedera.hashgraph.sdk.AccountId;

hiero-base/src/main/java/com/openelements/hiero/base/ContractParam.java renamed to hiero-base/src/main/java/com/openelements/hiero/base/data/ContractParam.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.openelements.hiero.base;
1+
package com.openelements.hiero.base.data;
22

33
import com.hedera.hashgraph.sdk.AccountId;
44
import com.hedera.hashgraph.sdk.ContractId;

hiero-base/src/main/java/com/openelements/hiero/base/mirrornode/ExchangeRate.java renamed to hiero-base/src/main/java/com/openelements/hiero/base/data/ExchangeRate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.openelements.hiero.base.mirrornode;
1+
package com.openelements.hiero.base.data;
22

33
import org.jspecify.annotations.NonNull;
44

hiero-base/src/main/java/com/openelements/hiero/base/mirrornode/ExchangeRates.java renamed to hiero-base/src/main/java/com/openelements/hiero/base/data/ExchangeRates.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.openelements.hiero.base.mirrornode;
1+
package com.openelements.hiero.base.data;
22

33
import org.jspecify.annotations.NonNull;
44

0 commit comments

Comments
 (0)