Skip to content

Commit

Permalink
feat: making gettokeninfo a view function (#194)
Browse files Browse the repository at this point in the history
Signed-off-by: Mariusz Jasuwienas <[email protected]>
  • Loading branch information
arianejasuwienas committed Jan 30, 2025
1 parent e4a7e92 commit 70077a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions contracts/HtsSystemContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -361,27 +361,27 @@ contract HtsSystemContract is IHederaTokenService {

function getTokenCustomFees(
address token
) htsCall external returns (int64, FixedFee[] memory, FractionalFee[] memory, RoyaltyFee[] memory) {
) htsCall external view returns (int64, FixedFee[] memory, FractionalFee[] memory, RoyaltyFee[] memory) {
(int64 responseCode, TokenInfo memory tokenInfo) = getTokenInfo(token);
return (responseCode, tokenInfo.fixedFees, tokenInfo.fractionalFees, tokenInfo.royaltyFees);
}

function getTokenDefaultFreezeStatus(address token) htsCall external returns (int64, bool) {
function getTokenDefaultFreezeStatus(address token) htsCall external view returns (int64, bool) {
(int64 responseCode, TokenInfo memory tokenInfo) = getTokenInfo(token);
return (responseCode, tokenInfo.token.freezeDefault);
}

function getTokenDefaultKycStatus(address token) htsCall external returns (int64, bool) {
function getTokenDefaultKycStatus(address token) htsCall external view returns (int64, bool) {
(int64 responseCode, TokenInfo memory tokenInfo) = getTokenInfo(token);
return (responseCode, tokenInfo.defaultKycStatus);
}

function getTokenExpiryInfo(address token) htsCall external returns (int64, Expiry memory expiry) {
function getTokenExpiryInfo(address token) htsCall external view returns (int64, Expiry memory expiry) {
(int64 responseCode, TokenInfo memory tokenInfo) = getTokenInfo(token);
return (responseCode, tokenInfo.token.expiry);
}

function getFungibleTokenInfo(address token) htsCall external returns (int64, FungibleTokenInfo memory) {
function getFungibleTokenInfo(address token) htsCall external view returns (int64, FungibleTokenInfo memory) {
(int64 responseCode, TokenInfo memory tokenInfo) = getTokenInfo(token);
require(responseCode == HederaResponseCodes.SUCCESS, "getFungibleTokenInfo: failed to get token data");
FungibleTokenInfo memory fungibleTokenInfo;
Expand All @@ -391,13 +391,13 @@ contract HtsSystemContract is IHederaTokenService {
return (responseCode, fungibleTokenInfo);
}

function getTokenInfo(address token) htsCall public returns (int64, TokenInfo memory) {
function getTokenInfo(address token) htsCall public view returns (int64, TokenInfo memory) {
require(token != address(0), "getTokenInfo: invalid token");

return IHederaTokenService(token).getTokenInfo(token);
}

function getTokenKey(address token, uint keyType) htsCall external returns (int64, KeyValue memory) {
function getTokenKey(address token, uint keyType) htsCall view external returns (int64, KeyValue memory) {
(int64 responseCode, TokenInfo memory tokenInfo) = getTokenInfo(token);
require(responseCode == HederaResponseCodes.SUCCESS, "getTokenKey: failed to get token data");
for (uint256 i = 0; i < tokenInfo.token.tokenKeys.length; i++) {
Expand All @@ -410,7 +410,7 @@ contract HtsSystemContract is IHederaTokenService {
}

function getNonFungibleTokenInfo(address token, int64 serialNumber)
htsCall external
htsCall external view
returns (int64, NonFungibleTokenInfo memory) {
(int64 responseCode, TokenInfo memory tokenInfo) = getTokenInfo(token);
require(responseCode == HederaResponseCodes.SUCCESS, "getNonFungibleTokenInfo: failed to get token data");
Expand All @@ -427,13 +427,13 @@ contract HtsSystemContract is IHederaTokenService {
return (responseCode, nonFungibleTokenInfo);
}

function isToken(address token) htsCall external returns (int64, bool) {
function isToken(address token) htsCall external view returns (int64, bool) {
bytes memory payload = abi.encodeWithSignature("getTokenType(address)", token);
(bool success, bytes memory returnData) = token.call(payload);
(bool success, bytes memory returnData) = token.staticcall(payload);
return (HederaResponseCodes.SUCCESS, success && returnData.length > 0);
}

function getTokenType(address token) htsCall external returns (int64, int32) {
function getTokenType(address token) htsCall external view returns (int64, int32) {
require(token != address(0), "getTokenType: invalid address");
return IHederaTokenService(token).getTokenType(token);
}
Expand Down
26 changes: 13 additions & 13 deletions contracts/IHederaTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ interface IHederaTokenService {
address token,
address owner,
address spender
) external returns (int64 responseCode, uint256 allowance);
) external view returns (int64 responseCode, uint256 allowance);

/// Allow or reaffirm the approved address to transfer an NFT the approved address does not own.
/// Only Applicable to NFT Tokens
Expand Down Expand Up @@ -572,7 +572,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
Expand All @@ -598,7 +598,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
Expand Down Expand Up @@ -630,47 +630,47 @@ 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
/// @param token The token address to check
/// @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
/// @param token The token address to check
/// @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
/// @param token The token address to check
/// @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
/// @param token The token address to check
/// @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
/// @param token The token address to check
/// @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
Expand All @@ -679,7 +679,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
Expand All @@ -688,7 +688,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
Expand Down Expand Up @@ -784,15 +784,15 @@ 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
/// @param token The token address
/// @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
Expand Down

0 comments on commit 70077a9

Please sign in to comment.