Skip to content

Commit

Permalink
feat: allow maxAutomaticTokenAssociations values to be -1 (#723)
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Walworth <[email protected]>
Signed-off-by: gsstoykov <[email protected]>
Co-authored-by: gsstoykov <[email protected]>
  • Loading branch information
rwalworth and gsstoykov authored Jul 16, 2024
1 parent db92f94 commit 1dc458f
Show file tree
Hide file tree
Showing 25 changed files with 876 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/zxc-build-library.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
# run: tree /F build

- name: Start the local node
run: sudo npx @hashgraph/hedera-local start -d --network local --network-tag=0.51.0-alpha.3
run: sudo npx @hashgraph/hedera-local start -d --network local --network-tag=0.52.0-alpha.6

- name: Start CTest suite (Debug)
run: ctest -C Debug --test-dir build/${{ matrix.preset }}-debug --output-on-failure
Expand Down
4 changes: 2 additions & 2 deletions HederaApi.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(HAPI_LIBRARY_HASH "13f0309b97e9bfc73f2dfd2c10c7eb26b1a72ea11722d4863f6408b34edb0185" CACHE STRING "Use the configured hash to verify the Hedera API protobuf library release")
set(HAPI_LIBRARY_URL "https://github.com/hashgraph/hedera-protobufs-cpp/releases/download/v0.50.0/hapi-library-9638abc0.tar.gz" CACHE STRING "Use the configured URL to download the Hedera API protobuf library package")
set(HAPI_LIBRARY_HASH "e341cdc22c585423a3c9b15e4c13f5e5efb7ff563d4fc9cf7c49412cca974816" CACHE STRING "Use the configured hash to verify the Hedera API protobuf library release")
set(HAPI_LIBRARY_URL "https://github.com/hashgraph/hedera-protobufs-cpp/releases/download/v0.52.0/hapi-library-f7dd7abd.tar.gz" CACHE STRING "Use the configured URL to download the Hedera API protobuf library package")

set(HAPI_LOCAL_LIBRARY_PATH "" CACHE STRING "Overrides the configured HAPI_LIBRARY_URL setting and instead uses the local path to retrieve the artifacts")

Expand Down
11 changes: 6 additions & 5 deletions src/sdk/main/include/AccountCreateTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ class AccountCreateTransaction : public Transaction<AccountCreateTransaction>
/**
* Set the maximum automatic token associations the new account can have.
*
* @param associations The desired maximum amount of token associations for the new account.
* @param associations The desired maximum amount of token associations for the new account. A value of -1 means
* the new account can have unlimited automatic token associations.
* @return A reference to this AccountCreateTransaction object with the newly-set maximum automatic token
* associations.
* @throws IllegalStateException If this AccountCreateTransaction is frozen.
*/
AccountCreateTransaction& setMaxAutomaticTokenAssociations(uint32_t associations);
AccountCreateTransaction& setMaxAutomaticTokenAssociations(int32_t associations);

/**
* Set the account to which the new account should stake. This is mutually exclusive with mStakedNodeId, and will
Expand Down Expand Up @@ -229,7 +230,7 @@ class AccountCreateTransaction : public Transaction<AccountCreateTransaction>
*
* @return The maximum automatic token associations for the new account.
*/
[[nodiscard]] inline uint32_t getMaxAutomaticTokenAssociations() const { return mMaxAutomaticTokenAssociations; }
[[nodiscard]] inline int32_t getMaxAutomaticTokenAssociations() const { return mMaxAutomaticTokenAssociations; }

/**
* Get the ID of the account to which the new account will stake.
Expand Down Expand Up @@ -340,9 +341,9 @@ class AccountCreateTransaction : public Transaction<AccountCreateTransaction>

/**
* The maximum number of tokens with which the new account can be implicitly associated. Only allows values up to a
* maximum value of 5000.
* maximum value of 5000. A value of -1 means the new account can have unlimited automatic token associations.
*/
uint32_t mMaxAutomaticTokenAssociations = 0U;
int32_t mMaxAutomaticTokenAssociations = 0;

/**
* The ID of the account to which the new account will be staked. Mutually exclusive with mStakedNodeId.
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/main/include/AccountInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class AccountInfo
/**
* The maximum number of tokens with which the queried account can be associated.
*/
uint32_t mMaxAutomaticTokenAssociations = 0U;
int32_t mMaxAutomaticTokenAssociations = 0;

/**
* The PublicKey alias of the queried account.
Expand Down
10 changes: 5 additions & 5 deletions src/sdk/main/include/AccountUpdateTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class AccountUpdateTransaction : public Transaction<AccountUpdateTransaction>
* associations.
* @throws IllegalStateException If this AccountUpdateTransaction is frozen.
*/
AccountUpdateTransaction& setMaxAutomaticTokenAssociations(uint32_t associations);
AccountUpdateTransaction& setMaxAutomaticTokenAssociations(int32_t associations);

/**
* Set the new account to which the account should stake. This is mutually exclusive with mStakedNodeId, and will
Expand Down Expand Up @@ -241,7 +241,7 @@ class AccountUpdateTransaction : public Transaction<AccountUpdateTransaction>
*
* @return The new maximum automatic token associations for the account.
*/
[[nodiscard]] inline std::optional<uint32_t> getMaxAutomaticTokenAssociations() const
[[nodiscard]] inline std::optional<int32_t> getMaxAutomaticTokenAssociations() const
{
return mMaxAutomaticTokenAssociations;
}
Expand Down Expand Up @@ -350,10 +350,10 @@ class AccountUpdateTransaction : public Transaction<AccountUpdateTransaction>
std::optional<std::string> mAccountMemo;

/**
* The new maximum number of tokens with which the new account can be implicitly associated. Only allows values up to
* a maximum value of 5000.
* The new maximum number of tokens with which the account can be implicitly associated. Only allows values up to a
* maximum value of 5000. A value of -1 means the account can have unlimited token associations.
*/
std::optional<uint32_t> mMaxAutomaticTokenAssociations;
std::optional<int32_t> mMaxAutomaticTokenAssociations;

/**
* The ID of the new account to which this account will be staked. Mutually exclusive with mStakedNodeId.
Expand Down
6 changes: 3 additions & 3 deletions src/sdk/main/include/ContractCreateFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ContractCreateFlow
* @param associations The maximum amount of token associations for the new smart contract instance.
* @return A reference to this ContractCreateFlow object with the newly-set maximum automatic token associations.
*/
ContractCreateFlow& setMaxAutomaticTokenAssociations(uint32_t associations);
ContractCreateFlow& setMaxAutomaticTokenAssociations(int32_t associations);

/**
* Set the account to charge for auto-renewal of the new smart contract instance. If not set, or set to an account
Expand Down Expand Up @@ -302,7 +302,7 @@ class ContractCreateFlow
*
* @return The maximum number of tokens with which the new smart contract instance can be automatically associated.
*/
[[nodiscard]] inline uint32_t getMaxAutomaticTokenAssociations() const { return mMaxAutomaticTokenAssociations; }
[[nodiscard]] inline int32_t getMaxAutomaticTokenAssociations() const { return mMaxAutomaticTokenAssociations; }

/**
* Get the account to charge for auto-renewal of the new smart contract instance.
Expand Down Expand Up @@ -400,7 +400,7 @@ class ContractCreateFlow
/**
* The maximum number of tokens with which the new smart contract instance can be implicitly associated.
*/
uint32_t mMaxAutomaticTokenAssociations = 0U;
int32_t mMaxAutomaticTokenAssociations = 0;

/**
* The account to charge for auto-renewal of the new smart contract instance.
Expand Down
6 changes: 3 additions & 3 deletions src/sdk/main/include/ContractCreateTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class ContractCreateTransaction : public Transaction<ContractCreateTransaction>
* associations.
* @throws IllegalStateException If this ContractCreateTransaction is frozen.
*/
ContractCreateTransaction& setMaxAutomaticTokenAssociations(uint32_t associations);
ContractCreateTransaction& setMaxAutomaticTokenAssociations(int32_t associations);

/**
* Set the account to charge for auto-renewal of the new smart contract instance. If not set, or set to an account
Expand Down Expand Up @@ -312,7 +312,7 @@ class ContractCreateTransaction : public Transaction<ContractCreateTransaction>
*
* @return The maximum number of tokens with which the new smart contract instance can be automatically associated.
*/
[[nodiscard]] inline uint32_t getMaxAutomaticTokenAssociations() const { return mMaxAutomaticTokenAssociations; }
[[nodiscard]] inline int32_t getMaxAutomaticTokenAssociations() const { return mMaxAutomaticTokenAssociations; }

/**
* Get the account to charge for auto-renewal of the new smart contract instance.
Expand Down Expand Up @@ -440,7 +440,7 @@ class ContractCreateTransaction : public Transaction<ContractCreateTransaction>
/**
* The maximum number of tokens with which the new smart contract instance can be implicitly associated.
*/
uint32_t mMaxAutomaticTokenAssociations = 0U;
int32_t mMaxAutomaticTokenAssociations = 0;

/**
* The account to charge for auto-renewal of the new smart contract instance.
Expand Down
6 changes: 3 additions & 3 deletions src/sdk/main/include/ContractUpdateTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ContractUpdateTransaction : public Transaction<ContractUpdateTransaction>
* associations.
* @throws IllegalStateException If this ContractUpdateTransaction is frozen.
*/
ContractUpdateTransaction& setMaxAutomaticTokenAssociations(uint32_t associations);
ContractUpdateTransaction& setMaxAutomaticTokenAssociations(int32_t associations);

/**
* Set the ID of the account that will auto-renew this contract.
Expand Down Expand Up @@ -219,7 +219,7 @@ class ContractUpdateTransaction : public Transaction<ContractUpdateTransaction>
* @return The new maximum automatic token associations for the contract. Returns uninitialized if a new maximum
* automatic token associations amount has not yet been set.
*/
[[nodiscard]] inline std::optional<uint32_t> getMaxAutomaticTokenAssociations() const
[[nodiscard]] inline std::optional<int32_t> getMaxAutomaticTokenAssociations() const
{
return mMaxAutomaticTokenAssociations;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ class ContractUpdateTransaction : public Transaction<ContractUpdateTransaction>
/**
* The new maximum automatic token associations for the contract. Only allows values up to a maximum value of 5000.
*/
std::optional<uint32_t> mMaxAutomaticTokenAssociations;
std::optional<int32_t> mMaxAutomaticTokenAssociations;

/**
* The ID of the account that will auto-renew this contract.
Expand Down
8 changes: 7 additions & 1 deletion src/sdk/main/include/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,13 @@ enum class Status
/**
* NFT serial numbers are missing in the TokenUpdateNftsTransactionBody
*/
MISSING_SERIAL_NUMBERS
MISSING_SERIAL_NUMBERS,

/**
* The maximum automatic associations value is not valid. The most common cause for this error is a value less than
* `-1`.
*/
INVALID_MAX_AUTO_ASSOCIATIONS
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/sdk/main/src/AccountCreateTransaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ AccountCreateTransaction& AccountCreateTransaction::setAccountMemo(std::string_v
}

//-----
AccountCreateTransaction& AccountCreateTransaction::setMaxAutomaticTokenAssociations(uint32_t associations)
AccountCreateTransaction& AccountCreateTransaction::setMaxAutomaticTokenAssociations(int32_t associations)
{
requireNotFrozen();

Expand Down Expand Up @@ -198,7 +198,7 @@ void AccountCreateTransaction::initFromSourceTransactionBody()
}

mAccountMemo = body.memo();
mMaxAutomaticTokenAssociations = static_cast<uint32_t>(body.max_automatic_token_associations());
mMaxAutomaticTokenAssociations = body.max_automatic_token_associations();

if (body.has_staked_account_id())
{
Expand Down Expand Up @@ -232,7 +232,7 @@ proto::CryptoCreateTransactionBody* AccountCreateTransaction::build() const
body->set_receiversigrequired(mReceiverSignatureRequired);
body->set_allocated_autorenewperiod(internal::DurationConverter::toProtobuf(mAutoRenewPeriod));
body->set_memo(mAccountMemo);
body->set_max_automatic_token_associations(static_cast<int32_t>(mMaxAutomaticTokenAssociations));
body->set_max_automatic_token_associations(mMaxAutomaticTokenAssociations);

if (mStakedAccountId)
{
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/main/src/AccountInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ AccountInfo AccountInfo::fromProtobuf(const proto::CryptoGetInfoResponse_Account

accountInfo.mMemo = proto.memo();
accountInfo.mOwnedNfts = static_cast<uint64_t>(proto.ownednfts());
accountInfo.mMaxAutomaticTokenAssociations = static_cast<uint32_t>(proto.max_automatic_token_associations());
accountInfo.mMaxAutomaticTokenAssociations = proto.max_automatic_token_associations();

if (!proto.alias().empty())
{
Expand Down Expand Up @@ -123,7 +123,7 @@ std::unique_ptr<proto::CryptoGetInfoResponse_AccountInfo> AccountInfo::toProtobu
proto->set_allocated_autorenewperiod(internal::DurationConverter::toProtobuf(mAutoRenewPeriod));
proto->set_memo(mMemo);
proto->set_ownednfts(static_cast<int64_t>(mOwnedNfts));
proto->set_max_automatic_token_associations(static_cast<int32_t>(mMaxAutomaticTokenAssociations));
proto->set_max_automatic_token_associations(mMaxAutomaticTokenAssociations);

if (mPublicKeyAlias)
{
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/main/src/AccountUpdateTransaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ AccountUpdateTransaction& AccountUpdateTransaction::clearAccountMemo()
}

//-----
AccountUpdateTransaction& AccountUpdateTransaction::setMaxAutomaticTokenAssociations(uint32_t associations)
AccountUpdateTransaction& AccountUpdateTransaction::setMaxAutomaticTokenAssociations(int32_t associations)
{
requireNotFrozen();

Expand Down Expand Up @@ -297,7 +297,7 @@ proto::CryptoUpdateTransactionBody* AccountUpdateTransaction::build() const
if (mMaxAutomaticTokenAssociations.has_value())
{
auto value = std::make_unique<google::protobuf::Int32Value>();
value->set_value(static_cast<int32_t>(mMaxAutomaticTokenAssociations.value()));
value->set_value(mMaxAutomaticTokenAssociations.value());
body->set_allocated_max_automatic_token_associations(value.release());
}

Expand Down
2 changes: 1 addition & 1 deletion src/sdk/main/src/ContractCreateFlow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ ContractCreateFlow& ContractCreateFlow::setMemo(std::string_view memo)
}

//-----
ContractCreateFlow& ContractCreateFlow::setMaxAutomaticTokenAssociations(uint32_t associations)
ContractCreateFlow& ContractCreateFlow::setMaxAutomaticTokenAssociations(int32_t associations)
{
mMaxAutomaticTokenAssociations = associations;
return *this;
Expand Down
6 changes: 3 additions & 3 deletions src/sdk/main/src/ContractCreateTransaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ContractCreateTransaction& ContractCreateTransaction::setMemo(std::string_view m
}

//-----
ContractCreateTransaction& ContractCreateTransaction::setMaxAutomaticTokenAssociations(uint32_t associations)
ContractCreateTransaction& ContractCreateTransaction::setMaxAutomaticTokenAssociations(int32_t associations)
{
requireNotFrozen();
mMaxAutomaticTokenAssociations = associations;
Expand Down Expand Up @@ -236,7 +236,7 @@ void ContractCreateTransaction::initFromSourceTransactionBody()

mConstructorParameters = internal::Utilities::stringToByteVector(body.constructorparameters());
mMemo = body.memo();
mMaxAutomaticTokenAssociations = static_cast<uint32_t>(body.max_automatic_token_associations());
mMaxAutomaticTokenAssociations = body.max_automatic_token_associations();

if (body.has_auto_renew_account_id())
{
Expand Down Expand Up @@ -281,7 +281,7 @@ proto::ContractCreateTransactionBody* ContractCreateTransaction::build() const
body->set_allocated_autorenewperiod(internal::DurationConverter::toProtobuf(mAutoRenewPeriod));
body->set_constructorparameters(internal::Utilities::byteVectorToString(mConstructorParameters));
body->set_memo(mMemo);
body->set_max_automatic_token_associations(static_cast<int32_t>(mMaxAutomaticTokenAssociations));
body->set_max_automatic_token_associations(mMaxAutomaticTokenAssociations);

if (mAutoRenewAccountId.has_value())
{
Expand Down
6 changes: 3 additions & 3 deletions src/sdk/main/src/ContractUpdateTransaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ContractUpdateTransaction& ContractUpdateTransaction::setContractMemo(std::strin
}

//-----
ContractUpdateTransaction& ContractUpdateTransaction::setMaxAutomaticTokenAssociations(uint32_t associations)
ContractUpdateTransaction& ContractUpdateTransaction::setMaxAutomaticTokenAssociations(int32_t associations)
{
requireNotFrozen();
mMaxAutomaticTokenAssociations = associations;
Expand Down Expand Up @@ -205,7 +205,7 @@ void ContractUpdateTransaction::initFromSourceTransactionBody()

if (body.has_max_automatic_token_associations())
{
mMaxAutomaticTokenAssociations = static_cast<uint32_t>(body.max_automatic_token_associations().value());
mMaxAutomaticTokenAssociations = body.max_automatic_token_associations().value();
}

if (body.has_auto_renew_account_id())
Expand Down Expand Up @@ -261,7 +261,7 @@ proto::ContractUpdateTransactionBody* ContractUpdateTransaction::build() const
if (mMaxAutomaticTokenAssociations.has_value())
{
auto value = std::make_unique<google::protobuf::Int32Value>();
value->set_value(static_cast<int32_t>(mMaxAutomaticTokenAssociations.value()));
value->set_value(mMaxAutomaticTokenAssociations.value());
body->set_allocated_max_automatic_token_associations(value.release());
}

Expand Down
9 changes: 6 additions & 3 deletions src/sdk/main/src/Status.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ const std::unordered_map<proto::ResponseCodeEnum, Status> gProtobufResponseCodeT
{ proto::ResponseCodeEnum::ALIAS_ALREADY_ASSIGNED, Status::ALIAS_ALREADY_ASSIGNED },
{ proto::ResponseCodeEnum::INVALID_METADATA_KEY, Status::INVALID_METADATA_KEY },
{ proto::ResponseCodeEnum::MISSING_TOKEN_METADATA, Status::MISSING_TOKEN_METADATA },
{ proto::ResponseCodeEnum::MISSING_SERIAL_NUMBERS, Status::MISSING_SERIAL_NUMBERS }
{ proto::ResponseCodeEnum::MISSING_SERIAL_NUMBERS, Status::MISSING_SERIAL_NUMBERS },
{ proto::ResponseCodeEnum::INVALID_MAX_AUTO_ASSOCIATIONS, Status::INVALID_MAX_AUTO_ASSOCIATIONS }
};

//-----
Expand Down Expand Up @@ -646,7 +647,8 @@ const std::unordered_map<Status, proto::ResponseCodeEnum> gStatusToProtobufRespo
{ Status::ALIAS_ALREADY_ASSIGNED, proto::ResponseCodeEnum::ALIAS_ALREADY_ASSIGNED },
{ Status::INVALID_METADATA_KEY, proto::ResponseCodeEnum::INVALID_METADATA_KEY },
{ Status::MISSING_TOKEN_METADATA, proto::ResponseCodeEnum::MISSING_TOKEN_METADATA },
{ Status::MISSING_SERIAL_NUMBERS, proto::ResponseCodeEnum::MISSING_SERIAL_NUMBERS }
{ Status::MISSING_SERIAL_NUMBERS, proto::ResponseCodeEnum::MISSING_SERIAL_NUMBERS },
{ Status::INVALID_MAX_AUTO_ASSOCIATIONS, proto::ResponseCodeEnum::INVALID_MAX_AUTO_ASSOCIATIONS }
};

//-----
Expand Down Expand Up @@ -941,7 +943,8 @@ const std::unordered_map<Status, std::string> gStatusToString = {
{ Status::ALIAS_ALREADY_ASSIGNED, "ALIAS_ALREADY_ASSIGNED" },
{ Status::INVALID_METADATA_KEY, "INVALID_METADATA_KEY" },
{ Status::MISSING_TOKEN_METADATA, "MISSING_TOKEN_METADATA" },
{ Status::MISSING_SERIAL_NUMBERS, "MISSING_SERIAL_NUMBERS" }
{ Status::MISSING_SERIAL_NUMBERS, "MISSING_SERIAL_NUMBERS" },
{ Status::INVALID_MAX_AUTO_ASSOCIATIONS, "INVALID_MAX_AUTO_ASSOCIATIONS" }
};

} // namespace Hedera
Loading

0 comments on commit 1dc458f

Please sign in to comment.