From 80e83f3a1844866fcacc63225731a0764b1b37c6 Mon Sep 17 00:00:00 2001 From: Luis Mastrangelo Date: Fri, 20 Dec 2024 18:37:45 -0300 Subject: [PATCH 1/2] Change `getTokenInfo` to view Signed-off-by: Luis Mastrangelo --- .../hedera-token-service/HederaTokenService.sol | 2 +- .../hedera-token-service/IHederaTokenService.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/system-contracts/hedera-token-service/HederaTokenService.sol b/contracts/system-contracts/hedera-token-service/HederaTokenService.sol index 92f47946d..f5df02caa 100644 --- a/contracts/system-contracts/hedera-token-service/HederaTokenService.sol +++ b/contracts/system-contracts/hedera-token-service/HederaTokenService.sol @@ -225,7 +225,7 @@ abstract contract HederaTokenService { /// @param token The ID of the token as a solidity address /// @dev This function reverts if the call is not successful function getTokenInfo(address token) internal returns (int responseCode, IHederaTokenService.TokenInfo memory tokenInfo) { - (bool success, bytes memory result) = precompileAddress.call( + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getTokenInfo.selector, token)); IHederaTokenService.TokenInfo memory defaultTokenInfo; (responseCode, tokenInfo) = success ? abi.decode(result, (int32, IHederaTokenService.TokenInfo)) : (HederaResponseCodes.UNKNOWN, defaultTokenInfo); diff --git a/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol b/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol index 2df5b7485..3475fbd2f 100644 --- a/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol +++ b/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol @@ -689,7 +689,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return tokenInfo TokenInfo info for `token` function getTokenInfo(address token) - external + external view returns (int64 responseCode, TokenInfo memory tokenInfo); /// Query token KeyValue From 0a617acfd804131e6f0ad5b7bc46019783f82bad Mon Sep 17 00:00:00 2001 From: Luis Mastrangelo Date: Fri, 20 Dec 2024 19:10:02 -0300 Subject: [PATCH 2/2] Convert rest of getters to `view` Signed-off-by: Luis Mastrangelo --- .../HederaTokenService.sol | 54 +++++++++---------- .../IHederaTokenService.sol | 26 ++++----- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/contracts/system-contracts/hedera-token-service/HederaTokenService.sol b/contracts/system-contracts/hedera-token-service/HederaTokenService.sol index f5df02caa..0e0323ad7 100644 --- a/contracts/system-contracts/hedera-token-service/HederaTokenService.sol +++ b/contracts/system-contracts/hedera-token-service/HederaTokenService.sol @@ -214,8 +214,8 @@ abstract contract HederaTokenService { /// Retrieves fungible specific token info for a fungible token /// @param token The ID of the token as a solidity address /// @dev This function reverts if the call is not successful - function getFungibleTokenInfo(address token) internal returns (int responseCode, IHederaTokenService.FungibleTokenInfo memory tokenInfo) { - (bool success, bytes memory result) = precompileAddress.call( + function getFungibleTokenInfo(address token) internal view returns (int responseCode, IHederaTokenService.FungibleTokenInfo memory tokenInfo) { + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getFungibleTokenInfo.selector, token)); IHederaTokenService.FungibleTokenInfo memory defaultTokenInfo; (responseCode, tokenInfo) = success ? abi.decode(result, (int32, IHederaTokenService.FungibleTokenInfo)) : (HederaResponseCodes.UNKNOWN, defaultTokenInfo); @@ -224,7 +224,7 @@ abstract contract HederaTokenService { /// Retrieves general token info for a given token /// @param token The ID of the token as a solidity address /// @dev This function reverts if the call is not successful - function getTokenInfo(address token) internal returns (int responseCode, IHederaTokenService.TokenInfo memory tokenInfo) { + function getTokenInfo(address token) internal view returns (int responseCode, IHederaTokenService.TokenInfo memory tokenInfo) { (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getTokenInfo.selector, token)); IHederaTokenService.TokenInfo memory defaultTokenInfo; @@ -234,8 +234,8 @@ abstract contract HederaTokenService { /// Retrieves non-fungible specific token info for a given NFT /// @param token The ID of the token as a solidity address /// @dev This function reverts if the call is not successful - function getNonFungibleTokenInfo(address token, int64 serialNumber) internal returns (int responseCode, IHederaTokenService.NonFungibleTokenInfo memory tokenInfo) { - (bool success, bytes memory result) = precompileAddress.call( + function getNonFungibleTokenInfo(address token, int64 serialNumber) internal view returns (int responseCode, IHederaTokenService.NonFungibleTokenInfo memory tokenInfo) { + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getNonFungibleTokenInfo.selector, token, serialNumber)); IHederaTokenService.NonFungibleTokenInfo memory defaultTokenInfo; (responseCode, tokenInfo) = success ? abi.decode(result, (int32, IHederaTokenService.NonFungibleTokenInfo)) : (HederaResponseCodes.UNKNOWN, defaultTokenInfo); @@ -248,11 +248,11 @@ abstract contract HederaTokenService { /// @return fractionalFees Set of fractional fees for `token` /// @return royaltyFees Set of royalty fees for `token` /// @dev This function reverts if the call is not successful - function getTokenCustomFees(address token) internal returns (int64 responseCode, + function getTokenCustomFees(address token) internal view returns (int64 responseCode, IHederaTokenService.FixedFee[] memory fixedFees, IHederaTokenService.FractionalFee[] memory fractionalFees, IHederaTokenService.RoyaltyFee[] memory royaltyFees) { - (bool success, bytes memory result) = precompileAddress.call( + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getTokenCustomFees.selector, token)); IHederaTokenService.FixedFee[] memory defaultFixedFees; IHederaTokenService.FractionalFee[] memory defaultFractionalFees; @@ -343,9 +343,9 @@ abstract contract HederaTokenService { /// @param serialNumber The NFT to find the approved address for /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return approved The approved address for this NFT, or the zero address if there is none - function getApproved(address token, uint256 serialNumber) internal returns (int responseCode, address approved) + function getApproved(address token, uint256 serialNumber) internal view returns (int responseCode, address approved) { - (bool success, bytes memory result) = precompileAddress.call( + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getApproved.selector, token, serialNumber)); (responseCode, approved) = @@ -360,8 +360,8 @@ abstract contract HederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return frozen True if `account` is frozen for `token` /// @dev This function reverts if the call is not successful - function isFrozen(address token, address account) internal returns (int64 responseCode, bool frozen){ - (bool success, bytes memory result) = precompileAddress.call( + function isFrozen(address token, address account) internal view returns (int64 responseCode, bool frozen){ + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.isFrozen.selector, token, account)); (responseCode, frozen) = success ? abi.decode(result, (int32, bool)) : (HederaResponseCodes.UNKNOWN, false); } @@ -372,8 +372,8 @@ abstract contract HederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return kycGranted True if `account` has kyc granted for `token` /// @dev This function reverts if the call is not successful - function isKyc(address token, address account) internal returns (int64 responseCode, bool kycGranted){ - (bool success, bytes memory result) = precompileAddress.call( + function isKyc(address token, address account) internal view returns (int64 responseCode, bool kycGranted){ + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.isKyc.selector, token, account)); (responseCode, kycGranted) = success ? abi.decode(result, (int32, bool)) : (HederaResponseCodes.UNKNOWN, false); } @@ -439,9 +439,9 @@ abstract contract HederaTokenService { /// @param operator The address that acts on behalf of the owner /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return approved True if `operator` is an approved operator for `owner`, false otherwise - function isApprovedForAll(address token, address owner, address operator) internal returns (int responseCode, bool approved) + function isApprovedForAll(address token, address owner, address operator) internal view returns (int responseCode, bool approved) { - (bool success, bytes memory result) = precompileAddress.call( + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.isApprovedForAll.selector, token, owner, operator)); (responseCode, approved) = @@ -455,8 +455,8 @@ abstract contract HederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return defaultFreezeStatus True if `token` default freeze status is frozen. /// @dev This function reverts if the call is not successful - function getTokenDefaultFreezeStatus(address token) internal returns (int responseCode, bool defaultFreezeStatus) { - (bool success, bytes memory result) = precompileAddress.call( + function getTokenDefaultFreezeStatus(address token) internal view returns (int responseCode, bool defaultFreezeStatus) { + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getTokenDefaultFreezeStatus.selector, token)); (responseCode, defaultFreezeStatus) = success ? abi.decode(result, (int32, bool)) : (HederaResponseCodes.UNKNOWN, false); } @@ -466,8 +466,8 @@ abstract contract HederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return defaultKycStatus True if `token` default kyc status is KycNotApplicable and false if Revoked. /// @dev This function reverts if the call is not successful - function getTokenDefaultKycStatus(address token) internal returns (int responseCode, bool defaultKycStatus) { - (bool success, bytes memory result) = precompileAddress.call( + function getTokenDefaultKycStatus(address token) internal view returns (int responseCode, bool defaultKycStatus) { + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getTokenDefaultKycStatus.selector, token)); (responseCode, defaultKycStatus) = success ? abi.decode(result, (int32, bool)) : (HederaResponseCodes.UNKNOWN, false); } @@ -608,8 +608,8 @@ abstract contract HederaTokenService { /// @return key KeyValue info for key of type `keyType` /// @dev This function reverts if the call is not successful function getTokenKey(address token, uint keyType) - internal returns (int64 responseCode, IHederaTokenService.KeyValue memory key){ - (bool success, bytes memory result) = precompileAddress.call( + internal view returns (int64 responseCode, IHederaTokenService.KeyValue memory key){ + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getTokenKey.selector, token, keyType)); IHederaTokenService.KeyValue memory defaultKeyValueInfo; (responseCode, key) = success ? abi.decode(result, (int32,IHederaTokenService.KeyValue) ) : (HederaResponseCodes.UNKNOWN, defaultKeyValueInfo); @@ -621,8 +621,8 @@ abstract contract HederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return isTokenFlag True if valid token found for the given address /// @dev This function reverts if the call is not successful - function isToken(address token) internal returns (int64 responseCode, bool isTokenFlag) { - (bool success, bytes memory result) = precompileAddress.call( + function isToken(address token) internal view returns (int64 responseCode, bool isTokenFlag) { + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.isToken.selector, token)); (responseCode, isTokenFlag) = success ? abi.decode(result, (int32, bool)) : (HederaResponseCodes.UNKNOWN, false); } @@ -632,8 +632,8 @@ abstract contract HederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return tokenType the token type. 0 is FUNGIBLE_COMMON, 1 is NON_FUNGIBLE_UNIQUE, -1 is UNRECOGNIZED /// @dev This function reverts if the call is not successful - function getTokenType(address token) internal returns (int64 responseCode, int32 tokenType) { - (bool success, bytes memory result) = precompileAddress.call( + function getTokenType(address token) internal view returns (int64 responseCode, int32 tokenType) { + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getTokenType.selector, token)); (responseCode, tokenType) = success ? abi.decode(result, (int32, int32)) : (HederaResponseCodes.UNKNOWN, - 1); } @@ -643,8 +643,8 @@ abstract contract HederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return expiryInfo The expiry info of the token /// @dev This function reverts if the call is not successful - function getTokenExpiryInfo(address token) internal returns (int responseCode, IHederaTokenService.Expiry memory expiryInfo){ - (bool success, bytes memory result) = precompileAddress.call( + function getTokenExpiryInfo(address token) internal view returns (int responseCode, IHederaTokenService.Expiry memory expiryInfo){ + (bool success, bytes memory result) = precompileAddress.staticcall( abi.encodeWithSelector(IHederaTokenService.getTokenExpiryInfo.selector, token)); IHederaTokenService.Expiry memory defaultExpiryInfo; (responseCode, expiryInfo) = success ? abi.decode(result, (int32, IHederaTokenService.Expiry)) : (HederaResponseCodes.UNKNOWN, defaultExpiryInfo); diff --git a/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol b/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol index 3475fbd2f..1a35a7402 100644 --- a/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol +++ b/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol @@ -591,7 +591,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return approved The approved address for this NFT, or the zero address if there is none function getApproved(address token, uint256 serialNumber) - external + external view returns (int64 responseCode, address approved); /// Enable or disable approval for a third party ("operator") to manage @@ -617,7 +617,7 @@ interface IHederaTokenService { address token, address owner, address operator - ) external returns (int64 responseCode, bool approved); + ) external view returns (int64 responseCode, bool approved); /// Query if token account is frozen /// @param token The token address to check @@ -625,7 +625,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return frozen True if `account` is frozen for `token` function isFrozen(address token, address account) - external + external view returns (int64 responseCode, bool frozen); /// Query if token account has kyc granted @@ -634,7 +634,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return kycGranted True if `account` has kyc granted for `token` function isKyc(address token, address account) - external + external view returns (int64 responseCode, bool kycGranted); /// Operation to delete token @@ -649,7 +649,7 @@ interface IHederaTokenService { /// @return fractionalFees Set of fractional fees for `token` /// @return royaltyFees Set of royalty fees for `token` function getTokenCustomFees(address token) - external + external view returns (int64 responseCode, FixedFee[] memory fixedFees, FractionalFee[] memory fractionalFees, RoyaltyFee[] memory royaltyFees); /// Query token default freeze status @@ -657,7 +657,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return defaultFreezeStatus True if `token` default freeze status is frozen. function getTokenDefaultFreezeStatus(address token) - external + external view returns (int64 responseCode, bool defaultFreezeStatus); /// Query token default kyc status @@ -665,7 +665,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return defaultKycStatus True if `token` default kyc status is KycNotApplicable and false if Revoked. function getTokenDefaultKycStatus(address token) - external + external view returns (int64 responseCode, bool defaultKycStatus); /// Query token expiry info @@ -673,7 +673,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return expiry Expiry info for `token` function getTokenExpiryInfo(address token) - external + external view returns (int64 responseCode, Expiry memory expiry); /// Query fungible token info @@ -681,7 +681,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return fungibleTokenInfo FungibleTokenInfo info for `token` function getFungibleTokenInfo(address token) - external + external view returns (int64 responseCode, FungibleTokenInfo memory fungibleTokenInfo); /// Query token info @@ -698,7 +698,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return key KeyValue info for key of type `keyType` function getTokenKey(address token, uint keyType) - external + external view returns (int64 responseCode, KeyValue memory key); /// Query non fungible token info @@ -707,7 +707,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return nonFungibleTokenInfo NonFungibleTokenInfo info for `token` `serialNumber` function getNonFungibleTokenInfo(address token, int64 serialNumber) - external + external view returns (int64 responseCode, NonFungibleTokenInfo memory nonFungibleTokenInfo); /// Operation to freeze token account @@ -803,7 +803,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return isToken True if valid token found for the given address function isToken(address token) - external returns + external view returns (int64 responseCode, bool isToken); /// Query to return the token type for a given address @@ -811,7 +811,7 @@ interface IHederaTokenService { /// @return responseCode The response code for the status of the request. SUCCESS is 22. /// @return tokenType the token type. 0 is FUNGIBLE_COMMON, 1 is NON_FUNGIBLE_UNIQUE, -1 is UNRECOGNIZED function getTokenType(address token) - external returns + external view returns (int64 responseCode, int32 tokenType); /// Initiates a Redirect For Token