-
Notifications
You must be signed in to change notification settings - Fork 18
feat(account): add initial hook API support (#65) #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amkr6207
wants to merge
7
commits into
hiero-ledger:main
Choose a base branch
from
amkr6207:feat/issue-65-hooks-api-contracts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
706917e
feat(account): add initial hook API support (#65)
amkr6207 903b986
ci: unpin soloVersion and bump hiero-solo-action to v0.19.0
amkr6207 3cb6349
test(spring): stabilize network stake assertion for mirror-node empty…
amkr6207 8c29290
fix: address review feedback for hook API contracts
amkr6207 ece0b7e
test(spring): wait for network stake data in CI
amkr6207 7de5b52
test(spring): restore network stake test
amkr6207 51dc3e8
Use SDK HookExtensionPoint and add initial storage updates
amkr6207 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
hiero-enterprise-base/src/main/java/org/hiero/base/data/HookDetails.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.hiero.base.data; | ||
|
|
||
| import com.hedera.hashgraph.sdk.ContractId; | ||
| import com.hedera.hashgraph.sdk.EvmHookStorageUpdate; | ||
| import com.hedera.hashgraph.sdk.HookExtensionPoint; | ||
| import com.hedera.hashgraph.sdk.Key; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import org.jspecify.annotations.NonNull; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * High-level representation of a hook to attach to an account. | ||
| * | ||
| * @param extensionPoint the extension point where the hook should be attached | ||
| * @param hookId unique identifier of the hook on the owning entity | ||
| * @param evmHookContractId contract implementing the hook logic | ||
| * @param initialStorageUpdates initial EVM storage updates to apply on hook creation | ||
| * @param adminKey optional key used to authorize management operations for this hook | ||
| */ | ||
| public record HookDetails( | ||
| @NonNull HookExtensionPoint extensionPoint, | ||
| long hookId, | ||
| @NonNull ContractId evmHookContractId, | ||
| @NonNull List<EvmHookStorageUpdate> initialStorageUpdates, | ||
| @Nullable Key adminKey) { | ||
|
|
||
| public HookDetails { | ||
| Objects.requireNonNull(extensionPoint, "extensionPoint must not be null"); | ||
| Objects.requireNonNull(evmHookContractId, "evmHookContractId must not be null"); | ||
| Objects.requireNonNull(initialStorageUpdates, "initialStorageUpdates must not be null"); | ||
| initialStorageUpdates.forEach( | ||
| update -> Objects.requireNonNull(update, "initialStorageUpdates must not contain null")); | ||
| initialStorageUpdates = List.copyOf(initialStorageUpdates); | ||
| if (hookId < 0) { | ||
| throw new IllegalArgumentException("hookId must be non-negative"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...-enterprise-base/src/main/java/org/hiero/base/protocol/data/AccountHookUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package org.hiero.base.protocol.data; | ||
|
|
||
| import com.hedera.hashgraph.sdk.Hbar; | ||
| import java.time.Duration; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import org.hiero.base.data.Account; | ||
| import org.hiero.base.data.HookDetails; | ||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| public record AccountHookUpdateRequest( | ||
| @NonNull Hbar maxTransactionFee, | ||
| @NonNull Duration transactionValidDuration, | ||
| @NonNull Account account, | ||
| @NonNull List<HookDetails> hooksToCreate, | ||
| @NonNull List<Long> hooksToDelete) | ||
| implements TransactionRequest { | ||
|
|
||
| public AccountHookUpdateRequest { | ||
| Objects.requireNonNull(maxTransactionFee, "maxTransactionFee is required"); | ||
| Objects.requireNonNull(transactionValidDuration, "transactionValidDuration is required"); | ||
| Objects.requireNonNull(account, "account is required"); | ||
| Objects.requireNonNull(hooksToCreate, "hooksToCreate is required"); | ||
| Objects.requireNonNull(hooksToDelete, "hooksToDelete is required"); | ||
| if (maxTransactionFee.toTinybars() < 0) { | ||
| throw new IllegalArgumentException("maxTransactionFee must be non-negative"); | ||
| } | ||
| if (transactionValidDuration.isNegative() || transactionValidDuration.isZero()) { | ||
| throw new IllegalArgumentException("transactionValidDuration must be positive"); | ||
| } | ||
| hooksToDelete.forEach( | ||
| hookId -> { | ||
| Objects.requireNonNull(hookId, "hooksToDelete must not contain null values"); | ||
| if (hookId < 0) { | ||
| throw new IllegalArgumentException("hook IDs in hooksToDelete must be non-negative"); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @NonNull | ||
| public static AccountHookUpdateRequest addHook( | ||
| @NonNull Account account, @NonNull HookDetails hookToCreate) { | ||
| Objects.requireNonNull(hookToCreate, "hookToCreate is required"); | ||
| return new AccountHookUpdateRequest( | ||
| DEFAULT_MAX_TRANSACTION_FEE, | ||
| DEFAULT_TRANSACTION_VALID_DURATION, | ||
| account, | ||
| List.of(hookToCreate), | ||
| List.of()); | ||
| } | ||
|
|
||
| @NonNull | ||
| public static AccountHookUpdateRequest deleteHook(@NonNull Account account, long hookIdToDelete) { | ||
| if (hookIdToDelete < 0) { | ||
| throw new IllegalArgumentException("hookIdToDelete must be non-negative"); | ||
| } | ||
| return new AccountHookUpdateRequest( | ||
| DEFAULT_MAX_TRANSACTION_FEE, | ||
| DEFAULT_TRANSACTION_VALID_DURATION, | ||
| account, | ||
| List.of(), | ||
| List.of(hookIdToDelete)); | ||
| } | ||
|
|
||
| @NonNull | ||
| public static AccountHookUpdateRequest of( | ||
| @NonNull Account account, | ||
| @NonNull List<HookDetails> hooksToCreate, | ||
| @NonNull List<Long> hooksToDelete) { | ||
| return new AccountHookUpdateRequest( | ||
| DEFAULT_MAX_TRANSACTION_FEE, | ||
| DEFAULT_TRANSACTION_VALID_DURATION, | ||
| account, | ||
| hooksToCreate, | ||
| hooksToDelete); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...o-enterprise-base/src/main/java/org/hiero/base/protocol/data/AccountHookUpdateResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.hiero.base.protocol.data; | ||
|
|
||
| import com.hedera.hashgraph.sdk.Hbar; | ||
| import com.hedera.hashgraph.sdk.Status; | ||
| import com.hedera.hashgraph.sdk.TransactionId; | ||
| import java.time.Instant; | ||
| import java.util.Objects; | ||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| public record AccountHookUpdateResult( | ||
| @NonNull TransactionId transactionId, | ||
| @NonNull Status status, | ||
| @NonNull byte[] transactionHash, | ||
| @NonNull Instant consensusTimestamp, | ||
| @NonNull Hbar transactionFee) | ||
| implements TransactionRecord { | ||
|
|
||
| public AccountHookUpdateResult { | ||
| Objects.requireNonNull(transactionId, "transactionId must not be null"); | ||
| Objects.requireNonNull(status, "status must not be null"); | ||
| Objects.requireNonNull(transactionHash, "transactionHash must not be null"); | ||
| Objects.requireNonNull(consensusTimestamp, "consensusTimestamp must not be null"); | ||
| Objects.requireNonNull(transactionFee, "transactionFee must not be null"); | ||
| if (transactionFee.toTinybars() < 0) { | ||
| throw new IllegalArgumentException("transactionFee must be non-negative"); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also include
List<EvmHookStorageUpdate>to adds an EVM hook with initial storage updates.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated.