Skip to content
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

refactor: HIP-756 Rename Schedule Get Info Smart Contracts Query Functions #17429

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
refactor: rename query schedule info query functions
Signed-off-by: Stanimir Stoyanov <stanimir.stoyanov@limechain.tech>
  • Loading branch information
stoyanov-st committed Jan 17, 2025
commit 7d0c8da56c04f6d80ab6f80d75acd39a785de0f8
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ is to gather the required signatures for the scheduled transaction, the `waitFor

### New Solidity Functions

| Function Selector Hash | Short Selector | Function Signature | HAPI operation | Description |
|------------------------|---------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|------------------------------------------------------------------|
| `0xe780c5d3` | `getScheduledFungibleTokenCreateTransaction(address scheduleAddress)` | `function getScheduledFungibleTokenCreateTransaction(address scheduleAddress) returns (int64 responseCode, FungibleTokenInfo memory tokenInfo)` | ScheduleGetInfo | Retrieve information for the scheduled token create |
| `0x14749042` | `getScheduledNonFungibleTokenCreateTransaction(address scheduleAddress)` | `function getScheduledNonFungibleTokenCreateTransaction(address scheduleAddress) returns (int64 responseCode, NonFungibleTokenInfo memory tokenInfo)` | ScheduleGetInfo | Retrieve information for the scheduled nft create |
| `0xca829811` | `scheduleNative(address systemContractAddress, bytes callData, address payerAddress)` | `function scheduleNative(address systemContractAddress, bytes callData, address payerAddress) returns (int64 responseCode, address scheduleAddress)` | ScheduleCreate | Schedule a token create or update as determined by the call data |
| Function Selector Hash | Short Selector | Function Signature | HAPI operation | Description |
|------------------------|---------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|------------------------------------------------------------------|
| `0xda2d5f8f` | `getScheduledCreateFungibleTokenInfo(address scheduleAddress)` | `function getScheduledCreateFungibleTokenInfo(address scheduleAddress) returns (int64 responseCode, FungibleTokenInfo memory tokenInfo)` | ScheduleGetInfo | Retrieve information for the scheduled token create |
| `0xd68c902c` | `getScheduledCreateNonFungibleTokenInfo(address scheduleAddress)` | `function getScheduledCreateNonFungibleTokenInfo(address scheduleAddress) returns (int64 responseCode, NonFungibleTokenInfo memory tokenInfo)` | ScheduleGetInfo | Retrieve information for the scheduled nft create |
| `0xca829811` | `scheduleNative(address systemContractAddress, bytes callData, address payerAddress)` | `function scheduleNative(address systemContractAddress, bytes callData, address payerAddress) returns (int64 responseCode, address scheduleAddress)` | ScheduleCreate | Schedule a token create or update as determined by the call data |

### System Contract Module

- `ScheduleNativeTranslator` - This class will be responsible for handling the `scheduleCreateFungibleToken`, `scheduleCreateFungibleTokenWithCustomFees`, `scheduleCreateNonFungibleToken`, `scheduleCreateNonFungibleTokenWithCustomFees`, `scheduleUpdateTokenInfo` and selectors and dispatching them to the Schedule Service.
- `ScheduleNativeTranslator` - This class will be responsible for handling the `scheduleNative` selector and dispatching it to the Schedule Service.
- `ScheduleNativeCall` - This class provides methods and constants for decoding the given `HssCallAttempt` into the appropriate `TransactionBody` by using the `asSchedulableDispatchIn` method of the `Call` interfaced described below.
- `GetScheduledInfoTranslator` - This class will be responsible for handling the `getScheduledFungibleTokenCreateTransaction` and `getScheduledNonFungibleTokenCreateTransaction` selectors and dispatching them to the Schedule Service.
- `GetScheduledInfoTranslator` - This class will be responsible for handling the `getScheduledCreateFungibleTokenInfo` and `getScheduledCreateNonFungibleTokenInfo` selectors and dispatching them to the Schedule Service.
- `GetScheduledTokenInfoCall` - This class provides methods and constants for decoding the `ScheduleGetInfoResponse` into a `PricedResult`.
- `GetScheduledNonFungibleTokenInfoCall` - This class provides methods and constants for decoding the `ScheduleGetInfoResponse` into a `PricedResult`.

Expand Down Expand Up @@ -95,16 +95,16 @@ The throttles for `ScheduledCreate` and `ScheduledGetInfo` will be applied to th
## Phased Implementation

1. Implement the `scheduleNative` system contract function.
2. Implement the `getScheduledFungibleTokenCreateTransaction`, `getScheduledNonFungibleTokenCreateTransaction` system contract functions.
2. Implement the `getScheduledCreateFungibleTokenInfo`, `getScheduledCreateNonFungibleTokenInfo` system contract functions.

## Acceptance Tests

### BDD Tests

#### Positive Tests

- validate that `getScheduledFungibleTokenCreateTransaction` returns the correct token info for a given schedule address.
- validate that `getScheduledNonFungibleTokenCreateTransaction` returns the correct non-fungible token info for a given schedule address.
- validate that `getScheduledCreateFungibleTokenInfo` returns the correct token info for a given schedule address.
- validate that `getScheduledCreateNonFungibleTokenInfo` returns the correct non-fungible token info for a given schedule address.
- validate that `scheduleNative` successfully creates a schedule for create token and returns the schedule address.
- validate that `scheduleNative` successfully creates a schedule for create token with a designated payer and returns the schedule address.
- validate that `scheduleNative` successfully creates a schedule for create token with custom fees and returns the schedule address.
Expand All @@ -117,6 +117,6 @@ The throttles for `ScheduledCreate` and `ScheduledGetInfo` will be applied to th

#### Negative Tests

- validate that `getScheduledFungibleTokenCreateTransaction` returns an error for a non-existing schedule address.
- validate that `getScheduledNonFungibleTokenCreateTransaction` returns an error for a non-existing schedule address.
- validate that `getScheduledCreateFungibleTokenInfo` returns an error for a non-existing schedule address.
- validate that `getScheduledCreateNonFungibleTokenInfo` returns an error for a non-existing schedule address.
- validate that the create/update functions would not be executed if the required signers did not sign the schedules.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.FullResult.revertResult;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.FullResult.successResult;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call.PricedResult.gasOnly;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.getscheduledinfo.GetScheduledInfoTranslator.GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.getscheduledinfo.GetScheduledInfoTranslator.GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.TokenTupleUtils.fungibleTokenInfoTupleFor;

import com.hedera.hapi.node.base.ScheduleID;
Expand Down Expand Up @@ -77,7 +77,7 @@ public PricedResult execute(MessageFrame frame) {
final var ledgerId = Bytes.wrap(ledgerConfig.id().toByteArray()).toString();
return gasOnly(
successResult(
GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION
GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO
.getOutputs()
.encodeElements(
SUCCESS.protoOrdinal(), fungibleTokenInfoTupleFor(tokenCreation, ledgerId, 1)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@

@Singleton
public class GetScheduledInfoTranslator extends AbstractCallTranslator<HssCallAttempt> {
public static final Function GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION = new Function(
"getScheduledFungibleTokenCreateTransaction(address)", ReturnTypes.RESPONSE_CODE_FUNGIBLE_TOKEN_INFO);
public static final Function GET_SCHEDULED_NON_FUNGIBLE_TOKEN_CREATE_TRANSACTION = new Function(
"getScheduledNonFungibleTokenCreateTransaction(address)",
ReturnTypes.RESPONSE_CODE_NON_FUNGIBLE_TOKEN_INFO);
public static final Function GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO =
new Function("getScheduledCreateFungibleTokenInfo(address)", ReturnTypes.RESPONSE_CODE_FUNGIBLE_TOKEN_INFO);
public static final Function GET_SCHEDULED_CREATE_NON_FUNGIBLE_TOKEN_INFO = new Function(
"getScheduledCreateNonFungibleTokenInfo(address)", ReturnTypes.RESPONSE_CODE_NON_FUNGIBLE_TOKEN_INFO);

// Tuple index for the schedule address
private static final int SCHEDULE_ADDRESS = 0;
Expand All @@ -47,18 +46,18 @@ public GetScheduledInfoTranslator() {
@Override
public boolean matches(@NonNull final HssCallAttempt attempt) {
return attempt.isSelector(
GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION, GET_SCHEDULED_NON_FUNGIBLE_TOKEN_CREATE_TRANSACTION);
GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO, GET_SCHEDULED_CREATE_NON_FUNGIBLE_TOKEN_INFO);
}

@Override
public Call callFrom(@NonNull final HssCallAttempt attempt) {
return attempt.isSelector(GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION)
return attempt.isSelector(GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO)
? getFungibleTokenCreateCall(attempt)
: getNonFungibleTokenCreateCall(attempt);
}

private Call getFungibleTokenCreateCall(@NonNull final HssCallAttempt attempt) {
final var call = GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION.decodeCall(attempt.inputBytes());
final var call = GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO.decodeCall(attempt.inputBytes());
final Address scheduleAddress = call.get(SCHEDULE_ADDRESS);
return new GetScheduledFungibleTokenCreateCall(
attempt.systemContractGasCalculator(),
Expand All @@ -68,7 +67,7 @@ private Call getFungibleTokenCreateCall(@NonNull final HssCallAttempt attempt) {
}

private Call getNonFungibleTokenCreateCall(@NonNull final HssCallAttempt attempt) {
final var call = GET_SCHEDULED_NON_FUNGIBLE_TOKEN_CREATE_TRANSACTION.decodeCall(attempt.inputBytes());
final var call = GET_SCHEDULED_CREATE_NON_FUNGIBLE_TOKEN_INFO.decodeCall(attempt.inputBytes());
final Address scheduleAddress = call.get(SCHEDULE_ADDRESS);
return new GetScheduledNonFungibleTokenCreateCall(
attempt.systemContractGasCalculator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.FullResult.revertResult;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.FullResult.successResult;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.Call.PricedResult.gasOnly;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.getscheduledinfo.GetScheduledInfoTranslator.GET_SCHEDULED_NON_FUNGIBLE_TOKEN_CREATE_TRANSACTION;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hss.getscheduledinfo.GetScheduledInfoTranslator.GET_SCHEDULED_CREATE_NON_FUNGIBLE_TOKEN_INFO;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.TokenTupleUtils.nftTokenInfoTupleFor;

import com.hedera.hapi.node.base.ScheduleID;
Expand Down Expand Up @@ -77,7 +77,7 @@ public PricedResult execute(MessageFrame frame) {
final var ledgerId = Bytes.wrap(ledgerConfig.id().toByteArray()).toString();
return gasOnly(
successResult(
GET_SCHEDULED_NON_FUNGIBLE_TOKEN_CREATE_TRANSACTION
GET_SCHEDULED_CREATE_NON_FUNGIBLE_TOKEN_INFO
.getOutputs()
.encodeElements(
SUCCESS.protoOrdinal(), nftTokenInfoTupleFor(tokenCreation, ledgerId, 1)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void setUp() {
@Test
void matchesGetScheduledFungibleTokenTxn() {
attempt = prepareHssAttemptWithSelectorAndCustomConfig(
GetScheduledInfoTranslator.GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION,
GetScheduledInfoTranslator.GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO,
subject,
enhancement,
addressIdConverter,
Expand All @@ -87,7 +87,7 @@ void matchesGetScheduledFungibleTokenTxn() {
@Test
void matchesGetScheduledNonFungibleTokenTxn() {
attempt = prepareHssAttemptWithSelectorAndCustomConfig(
GetScheduledInfoTranslator.GET_SCHEDULED_NON_FUNGIBLE_TOKEN_CREATE_TRANSACTION,
GetScheduledInfoTranslator.GET_SCHEDULED_CREATE_NON_FUNGIBLE_TOKEN_INFO,
subject,
enhancement,
addressIdConverter,
Expand Down Expand Up @@ -120,10 +120,10 @@ void matchesFailsForOtherSelector() {

@Test
void createsFungibleTokenCall() {
given(attempt.isSelector(GetScheduledInfoTranslator.GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION))
given(attempt.isSelector(GetScheduledInfoTranslator.GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO))
.willReturn(true);
given(attempt.inputBytes())
.willReturn(GetScheduledInfoTranslator.GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION
.willReturn(GetScheduledInfoTranslator.GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO
.encodeCallWithArgs(ConversionUtils.headlongAddressOf(CALLED_SCHEDULE_ID))
.array());
given(attempt.systemContractGasCalculator()).willReturn(gasCalculator);
Expand All @@ -137,10 +137,10 @@ void createsFungibleTokenCall() {

@Test
void createsNonFungibleTokenCall() {
given(attempt.isSelector(GetScheduledInfoTranslator.GET_SCHEDULED_FUNGIBLE_TOKEN_CREATE_TRANSACTION))
given(attempt.isSelector(GetScheduledInfoTranslator.GET_SCHEDULED_CREATE_FUNGIBLE_TOKEN_INFO))
.willReturn(false);
given(attempt.inputBytes())
.willReturn(GetScheduledInfoTranslator.GET_SCHEDULED_NON_FUNGIBLE_TOKEN_CREATE_TRANSACTION
.willReturn(GetScheduledInfoTranslator.GET_SCHEDULED_CREATE_NON_FUNGIBLE_TOKEN_INFO
.encodeCallWithArgs(ConversionUtils.headlongAddressOf(CALLED_SCHEDULE_ID))
.array());
given(attempt.systemContractGasCalculator()).willReturn(gasCalculator);
Expand Down
Loading
Loading