Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/tck/include/account/params/TransferCryptoParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#ifndef HIERO_TCK_CPP_TRANSFER_CRYPTO_PARAMS_H_
#define HIERO_TCK_CPP_TRANSFER_CRYPTO_PARAMS_H_

#include "account/params/transfer/TransferParams.h"
#include "common/CommonTransactionParams.h"
#include "common/transfer/TransferParams.h"
#include "json/JsonUtils.h"

#include <optional>
Expand All @@ -17,7 +17,7 @@ namespace Hiero::TCK::AccountService
struct TransferCryptoParams
{
/**
* The desired key for the account.
* The transfer information.
*/
std::optional<std::vector<TransferParams>> mTransfers;

Expand Down Expand Up @@ -45,8 +45,8 @@ struct [[maybe_unused]] adl_serializer<Hiero::TCK::AccountService::TransferCrypt
*/
static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::TransferCryptoParams& params)
{
params.mTransfers = Hiero::TCK::getOptionalJsonParameter<std::vector<Hiero::TCK::AccountService::TransferParams>>(
jsonFrom, "transfers");
params.mTransfers =
Hiero::TCK::getOptionalJsonParameter<std::vector<Hiero::TCK::TransferParams>>(jsonFrom, "transfers");
params.mCommonTxParams =
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::CommonTransactionParams>(jsonFrom, "commonTransactionParams");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <string>
#include <vector>

namespace Hiero::TCK::AccountService
namespace Hiero::TCK
{
/**
* Struct that contains the parameters of an Hbar transfer.
Expand All @@ -33,23 +33,23 @@ struct HbarTransferParams
std::string mAmount;
};

} // namespace Hiero::TCK::AccountService
} // namespace Hiero::TCK

namespace nlohmann
{
/**
* JSON serializer template specialization required to convert HbarTransferParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::AccountService::HbarTransferParams>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::HbarTransferParams>
{
/**
* Convert a JSON object to a HbarTransferParams.
*
* @param jsonFrom The JSON object with which to fill the HbarTransferParams.
* @param params The HbarTransferParams to fill with the JSON object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::HbarTransferParams& params)
static void from_json(const json& jsonFrom, Hiero::TCK::HbarTransferParams& params)
{
params.mAccountId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "accountId");
params.mEvmAddress = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "evmAddress");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <optional>
#include <string>

namespace Hiero::TCK::AccountService
namespace Hiero::TCK
{
/**
* Struct that contains the parameters of an NFT transfer.
Expand Down Expand Up @@ -35,23 +35,23 @@ struct NftTransferParams
std::string mSerialNumber;
};

} // namespace Hiero::TCK::AccountService
} // namespace Hiero::TCK

namespace nlohmann
{
/**
* JSON serializer template specialization required to convert NftTransferParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::AccountService::NftTransferParams>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::NftTransferParams>
{
/**
* Convert a JSON object to a NftTransferParams.
*
* @param jsonFrom The JSON object with which to fill the NftTransferParams.
* @param params The NftTransferParams to fill with the JSON object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::NftTransferParams& params)
static void from_json(const json& jsonFrom, Hiero::TCK::NftTransferParams& params)
{
params.mSenderAccountId = Hiero::TCK::getRequiredJsonParameter<std::string>(jsonFrom, "senderAccountId");
params.mReceiverAccountId = Hiero::TCK::getRequiredJsonParameter<std::string>(jsonFrom, "receiverAccountId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <optional>
#include <string>

namespace Hiero::TCK::AccountService
namespace Hiero::TCK
{
/**
* Struct that contains the parameters of a token transfer.
Expand Down Expand Up @@ -35,23 +35,23 @@ struct TokenTransferParams
std::optional<uint32_t> mDecimals;
};

} // namespace Hiero::TCK::AccountService
} // namespace Hiero::TCK

namespace nlohmann
{
/**
* JSON serializer template specialization required to convert TokenTransferParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::AccountService::TokenTransferParams>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TokenTransferParams>
{
/**
* Convert a JSON object to a TokenTransferParams.
*
* @param jsonFrom The JSON object with which to fill the TokenTransferParams.
* @param params The TokenTransferParams to fill with the JSON object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::TokenTransferParams& params)
static void from_json(const json& jsonFrom, Hiero::TCK::TokenTransferParams& params)
{
params.mAccountId = Hiero::TCK::getRequiredJsonParameter<std::string>(jsonFrom, "accountId");
params.mTokenId = Hiero::TCK::getRequiredJsonParameter<std::string>(jsonFrom, "tokenId");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#ifndef HIERO_TCK_CPP_TRANSFER_PARAMS_H_
#define HIERO_TCK_CPP_TRANSFER_PARAMS_H_

#include "account/params/transfer/HbarTransferParams.h"
#include "account/params/transfer/NftTransferParams.h"
#include "account/params/transfer/TokenTransferParams.h"
#include "common/transfer/HbarTransferParams.h"
#include "common/transfer/NftTransferParams.h"
#include "common/transfer/TokenTransferParams.h"
#include "json/JsonErrorType.h"
#include "json/JsonRpcException.h"
#include "json/JsonUtils.h"

#include <optional>

namespace Hiero::TCK::AccountService
namespace Hiero::TCK
{
/**
* Struct that contains the parameters of a transfer.
Expand Down Expand Up @@ -39,29 +39,27 @@
std::optional<bool> mApproved;
};

} // namespace Hiero::TCK::AccountService
} // namespace Hiero::TCK

namespace nlohmann
{
/**
* JSON serializer template specialization required to convert TransferParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::AccountService::TransferParams>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TransferParams>
{
/**
* Convert a JSON object to a TransferParams.
*
* @param jsonFrom The JSON object with which to fill the TransferParams.
* @param params The TransferParams to fill with the JSON object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::TransferParams& params)
static void from_json(const json& jsonFrom, Hiero::TCK::TransferParams& params)

Check warning on line 58 in src/tck/include/common/transfer/TransferParams.h

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/tck/include/common/transfer/TransferParams.h#L58

Method nlohmann::adl_serializer::from_json has a cyclomatic complexity of 10 (limit is 8)
{
params.mHbar =
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::AccountService::HbarTransferParams>(jsonFrom, "hbar");
params.mToken =
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::AccountService::TokenTransferParams>(jsonFrom, "token");
params.mNft = Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::AccountService::NftTransferParams>(jsonFrom, "nft");
params.mHbar = Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::HbarTransferParams>(jsonFrom, "hbar");
params.mToken = Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::TokenTransferParams>(jsonFrom, "token");
params.mNft = Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::NftTransferParams>(jsonFrom, "nft");
params.mApproved = Hiero::TCK::getOptionalJsonParameter<bool>(jsonFrom, "approved");

// Only one allowance type should be allowed.
Expand Down
9 changes: 9 additions & 0 deletions src/tck/include/token/TokenService.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Hiero::TCK::TokenService
/**
* Forward declarations.
*/
struct AirdropTokenParams;
struct AssociateTokenParams;
struct BurnTokenParams;
struct CreateTokenParams;
Expand All @@ -25,6 +26,14 @@ struct UpdateTokenFeeScheduleParams;
struct UpdateTokenParams;
struct WipeTokenParams;

/**
* Airdrop tokens to accounts.
*
* @params params The parameters to use to airdrop tokens.
* @return A JSON response containing the status of the token airdrop.
*/
nlohmann::json airdropToken(const AirdropTokenParams& params);

/**
* Associate an account with tokens.
*
Expand Down
74 changes: 74 additions & 0 deletions src/tck/include/token/params/AirdropTokenParams.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_AIRDROP_TOKEN_PARAMS_H_
#define HIERO_TCK_CPP_AIRDROP_TOKEN_PARAMS_H_

#include "common/CommonTransactionParams.h"
#include "common/transfer/TransferParams.h"
#include "json/JsonErrorType.h"
#include "json/JsonRpcException.h"
#include "json/JsonUtils.h"

#include <optional>
#include <vector>

namespace Hiero::TCK::TokenService
{
/**
* Struct to hold the arguments for a `airdropToken` JSON-RPC method call.
*/
struct AirdropTokenParams
{
/**
* The airdrop information.
*/
std::optional<std::vector<TransferParams>> mTokenTransfers;

/**
* Any parameters common to all transaction types.
*/
std::optional<CommonTransactionParams> mCommonTxParams;
};

} // namespace Hiero::TCK::TokenService

namespace nlohmann
{
/**
* JSON serializer template specialization required to convert AirdropTokenParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::TokenService::AirdropTokenParams>
{
/**
* Convert a JSON object to a AirdropTokenParams.
*
* @param jsonFrom The JSON object with which to fill the AirdropTokenParams.
* @param params The AirdropTokenParams to fill with the JSON object.
*/
static void from_json(const json& jsonFrom, Hiero::TCK::TokenService::AirdropTokenParams& params)
{
params.mTokenTransfers =
Hiero::TCK::getOptionalJsonParameter<std::vector<Hiero::TCK::TransferParams>>(jsonFrom, "tokenTransfers");

// Hbar transfer information is not allowed and calls for an INVALID_PARAMS response.
if (params.mTokenTransfers.has_value())
{
for (const Hiero::TCK::TransferParams& transfer : params.mTokenTransfers.value())
{
if (transfer.mHbar.has_value())
{
throw Hiero::TCK::JsonRpcException(Hiero::TCK::JsonErrorType::INVALID_PARAMS,
"invalid parameters: Hbar transfers are NOT allowed as part of a token"
"airdrop.");
}
}
}

params.mCommonTxParams =
Hiero::TCK::getOptionalJsonParameter<Hiero::TCK::CommonTransactionParams>(jsonFrom, "commonTransactionParams");
}
};

} // namespace nlohmann

#endif // HIERO_TCK_CPP_AIRDROP_TOKEN_PARAMS_H_
3 changes: 3 additions & 0 deletions src/tck/src/TckServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "key/params/GenerateKeyParams.h"
#include "sdk/params/ResetParams.h"
#include "sdk/params/SetupParams.h"
#include "token/params/AirdropTokenParams.h"
#include "token/params/AssociateTokenParams.h"
#include "token/params/BurnTokenParams.h"
#include "token/params/CreateTokenParams.h"
Expand Down Expand Up @@ -370,6 +371,8 @@ template TckServer::MethodHandle TckServer::getHandle<SdkClient::ResetParams>(
template TckServer::MethodHandle TckServer::getHandle<SdkClient::SetupParams>(
nlohmann::json (*method)(const SdkClient::SetupParams&));

template TckServer::MethodHandle TckServer::getHandle<TokenService::AirdropTokenParams>(
nlohmann::json (*method)(const TokenService::AirdropTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::AssociateTokenParams>(
nlohmann::json (*method)(const TokenService::AssociateTokenParams&));
template TckServer::MethodHandle TckServer::getHandle<TokenService::BurnTokenParams>(
Expand Down
2 changes: 1 addition & 1 deletion src/tck/src/account/AccountService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "account/params/UpdateAccountParams.h"
#include "account/params/allowance/AllowanceParams.h"
#include "account/params/allowance/RemoveAllowanceParams.h"
#include "account/params/transfer/TransferParams.h"
#include "common/CommonTransactionParams.h"
#include "common/transfer/TransferParams.h"
#include "key/KeyService.h"
#include "sdk/SdkClient.h"

Expand Down
1 change: 1 addition & 0 deletions src/tck/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ int main(int argc, char** argv)
tckServer.add("updateAccount", tckServer.getHandle(&AccountService::updateAccount));

// Add the TokenService functions.
tckServer.add("airdropToken", tckServer.getHandle(&TokenService::airdropToken));
tckServer.add("associateToken", tckServer.getHandle(&TokenService::associateToken));
tckServer.add("burnToken", tckServer.getHandle(&TokenService::burnToken));
tckServer.add("createToken", tckServer.getHandle(&TokenService::createToken));
Expand Down
Loading
Loading