-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathHbarTransferParams.h
More file actions
69 lines (59 loc) · 2.11 KB
/
HbarTransferParams.h
File metadata and controls
69 lines (59 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: Apache-2.0
#ifndef HIERO_TCK_CPP_HBAR_TRANSFER_PARAMS_H_
#define HIERO_TCK_CPP_HBAR_TRANSFER_PARAMS_H_
#include "json/JsonErrorType.h"
#include "json/JsonRpcException.h"
#include "json/JsonUtils.h"
#include <optional>
#include <string>
#include <vector>
namespace Hiero::TCK::AccountService
{
/**
* Struct that contains the parameters of an Hbar transfer.
*/
struct HbarTransferParams
{
/**
* REQUIRED if mEvmAddress is not provided. The ID of the account associated with the transfer.
*/
std::optional<std::string> mAccountId;
/**
* REQUIRED if mAccountId is not provided. The ID of the account associated with the transfer.
*/
std::optional<std::string> mEvmAddress;
/**
* The amount of Hbar transferred (in tinybars).
*/
std::string mAmount;
};
} // namespace Hiero::TCK::AccountService
namespace nlohmann
{
/**
* JSON serializer template specialization required to convert HbarTransferParams arguments properly.
*/
template<>
struct [[maybe_unused]] adl_serializer<Hiero::TCK::AccountService::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)
{
params.mAccountId = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "accountId");
params.mEvmAddress = Hiero::TCK::getOptionalJsonParameter<std::string>(jsonFrom, "evmAddress");
params.mAmount = Hiero::TCK::getRequiredJsonParameter<std::string>(jsonFrom, "amount");
if ((params.mAccountId.has_value() && params.mEvmAddress.has_value()) ||
(!params.mAccountId.has_value() && !params.mEvmAddress.has_value()))
{
throw Hiero::TCK::JsonRpcException(Hiero::TCK::JsonErrorType::INVALID_PARAMS,
"invalid parameters: only one of accountId or evmAddress SHALL be provided.");
}
}
};
} // namespace nlohmann
#endif // HIERO_TCK_CPP_HBAR_TRANSFER_PARAMS_H_