Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TokenNftAllowance #418

Merged
merged 4 commits into from
Jul 19, 2023
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
1 change: 0 additions & 1 deletion sdk/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ add_library(${PROJECT_NAME} STATIC
src/TokenNftAllowance.cc
src/TokenNftInfo.cc
src/TokenNftInfoQuery.cc
src/TokenNftRemoveAllowance.cc
src/TokenNftTransfer.cc
src/TokenPauseTransaction.cc
src/TokenRevokeKycTransaction.cc
Expand Down
6 changes: 3 additions & 3 deletions sdk/main/include/AccountAllowanceDeleteTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef HEDERA_SDK_CPP_ACCOUNT_ALLOWANCE_DELETE_TRANSACTION_H_
#define HEDERA_SDK_CPP_ACCOUNT_ALLOWANCE_DELETE_TRANSACTION_H_

#include "TokenNftRemoveAllowance.h"
#include "TokenNftAllowance.h"
#include "Transaction.h"

namespace proto
Expand Down Expand Up @@ -70,7 +70,7 @@ class AccountAllowanceDeleteTransaction : public Transaction<AccountAllowanceDel
*
* @return The list of a NFT allowance removals added to this AccountAllowanceDeleteTransaction.
*/
[[nodiscard]] inline std::vector<TokenNftRemoveAllowance> getTokenNftAllowanceDeletions() const
[[nodiscard]] inline std::vector<TokenNftAllowance> getTokenNftAllowanceDeletions() const
{
return mNftAllowanceDeletions;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ class AccountAllowanceDeleteTransaction : public Transaction<AccountAllowanceDel
/**
* The list of NFT allowances to be deleted.
*/
std::vector<TokenNftRemoveAllowance> mNftAllowanceDeletions;
std::vector<TokenNftAllowance> mNftAllowanceDeletions;
};

} // namespace Hedera
Expand Down
123 changes: 25 additions & 98 deletions sdk/main/include/TokenNftAllowance.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "AccountId.h"
#include "TokenId.h"

#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
Expand All @@ -31,6 +32,7 @@
namespace proto
{
class NftAllowance;
class NftRemoveAllowance;
}

namespace Hedera
Expand All @@ -56,12 +58,12 @@ class TokenNftAllowance
* @param delegatingSpender The ID of the account who has an 'approveForAll' allowance and is granting approval to
* spend an NFT to the spender.
*/
TokenNftAllowance(const TokenId& tokenId,
AccountId owner,
AccountId spender,
std::vector<uint64_t> serialNumbers,
std::optional<bool> allowAll = std::optional<bool>(),
std::optional<AccountId> delegatingSpender = std::optional<AccountId>());
TokenNftAllowance(const std::optional<TokenId>& tokenId,
const std::optional<AccountId>& owner,
const std::optional<AccountId>& spender,
const std::vector<uint64_t>& serialNumbers,
const std::optional<bool>& allowAll = std::optional<bool>(),
const std::optional<AccountId>& delegatingSpender = std::optional<AccountId>());

/**
* Construct a TokenNftAllowance object from a NftAllowance protobuf object.
Expand All @@ -72,124 +74,49 @@ class TokenNftAllowance
[[nodiscard]] static TokenNftAllowance fromProtobuf(const proto::NftAllowance& proto);

/**
* Construct a NftAllowance protobuf object from this TokenNftAllowance object.
* Construct a TokenNftAllowance object from a byte array.
*
* @return A pointer to a constructed NftAllowance protobuf object filled with this TokenNftAllowance object's data.
*/
[[nodiscard]] std::unique_ptr<proto::NftAllowance> toProtobuf() const;

/**
* Set the ID of the token NFT type that is being approved to be spent.
*
* @param tokenId The ID of the token NFT type that is being approved to be spent.
* @return A reference to this TokenNftAllowance object with the newly-set token ID.
*/
TokenNftAllowance& setTokenId(const TokenId& tokenId);

/**
* Set the ID of the account approving an allowance of its NFTs.
*
* @param accountId The ID of the account approving an allowance of its NFTs.
* @return A reference to this TokenNftAllowance object with the newly-set owner account ID.
*/
TokenNftAllowance& setOwnerAccountId(const AccountId& accountId);

/**
* Set the ID of the account being allowed to spend the NFTs.
*
* @param accountId The ID of the account being allowed to spend the NFTs.
* @return A reference to this TokenNftAllowance object with the newly-set spender account ID.
*/
TokenNftAllowance& setSpenderAccountId(const AccountId& accountId);

/**
* Add a serial number of one of the NFTs the spender is being allowed to spend.
*
* @param serialNumber The serial number of the NFT that is being allowed to be spent.
* @return A reference to this TokenNftAllowance object with the added NFT serial number.
*/
TokenNftAllowance& addSerialNumber(const uint64_t& serialNumber);

/**
* Allow the spender access to all of the owner's NFTs of the designated token ID (currently owned and any in the
* future).
*
* @param allowAll \c TRUE to allow the spender access to all of the owner's NFTs of the designated token ID,
* \c FALSE to revoke the spender's access to all of the owner's NFTs of the designated token ID.
* @return A reference to this TokenNftAllowance object with the newly-set NFT allowance policy.
*/
TokenNftAllowance& approveForAll(bool allowAll);

/**
* Set the ID of the account that is delegating the allowance to spend the NFT. This account should have an
* 'approveForAll' allowance.
*
* @param accountId The ID of the account that is delegating a spending allowance to the spender account.
* @return A reference to this TokenNftAllowance object with the newly-set delegate spender account ID.
*/
TokenNftAllowance& setDelegatingSpenderAccountId(const AccountId& accountId);

/**
* Get the ID of the token NFT type that is being approved to be spent.
*
* @return The ID of the token NFT type that is being approved to be spent.
*/
[[nodiscard]] inline TokenId getTokenId() const { return mTokenId; }

/**
* Set the ID of the account approving an allowance of its tokens.
*
* @return The ID of the account approving an allowance of its tokens.
*/
[[nodiscard]] inline AccountId getOwnerAccountId() const { return mOwnerAccountId; }

/**
* Get the ID of the account being allowed to spend the tokens.
*
* @return The ID of the account being allowed to spend the tokens.
* @param bytes The byte array from which to construct an TokenNftAllowance object.
* @return The constructed TokenNftAllowance object.
*/
[[nodiscard]] inline AccountId getSpenderAccountId() const { return mSpenderAccountId; }
[[nodiscard]] static TokenNftAllowance fromBytes(const std::vector<std::byte>& bytes);

/**
* Get the list of NFT serial numbers that are being allowed to be spent.
* Construct an NftAllowance protobuf object from this TokenNftAllowance object.
*
* @return The list of NFT serial numbers that are being allowed to be spent.
* @return A pointer to a constructed NftAllowance protobuf object filled with this TokenNftAllowance object's data.
*/
[[nodiscard]] inline std::vector<uint64_t> getSerialNumbers() const { return mSerialNumbers; }
[[nodiscard]] std::unique_ptr<proto::NftAllowance> toProtobuf() const;

/**
* Determine if this allowance allows the spender access to all of the owner's NFTs (currently owned and in the
* future).
* Construct an NftRemoveAllowance protobuf object from this TokenNftAllowance object.
*
* @return \c TRUE if this TokenNftAllowance allows the spender access to all of the owner's NFTs (currently owned and
* in the future). Uninitialized if behavior has not been set.
* @return A pointer to a constructed NftRemoveAllowance protobuf object filled with this TokenNftAllowance object's
* data.
*/
[[nodiscard]] inline std::optional<bool> getApprovedForAll() const { return mApprovedForAll; }
[[nodiscard]] std::unique_ptr<proto::NftRemoveAllowance> toRemoveProtobuf() const;

/**
* Get the ID of the spender account who is granted approved-for-all access and is granting approval of an NFT serial
* number to another spender.
* Construct a representative byte array from this TokenNftAllowance object.
*
* @return The ID of the spender account who is granted approved-for-all access and is granting approval of an NFT
* serial number to another spender. Uninitialized if no delegating spender exists for this allowance.
* @return A representative byte array of this TokenNftAllowance object.
*/
[[nodiscard]] inline std::optional<AccountId> getDelegateSpender() const { return mDelegatingSpenderAccountId; }
[[nodiscard]] std::vector<std::byte> toBytes() const;

private:
/**
* The ID of the token that is being approved to be spent.
*/
TokenId mTokenId;
std::optional<TokenId> mTokenId;

/**
* The ID of the account approving an allowance of its tokens.
*/
AccountId mOwnerAccountId;
std::optional<AccountId> mOwnerAccountId;

/**
* The ID of the account being allowed to spend the tokens.
*/
AccountId mSpenderAccountId;
std::optional<AccountId> mSpenderAccountId;

/**
* The list of serial numbers that are being allowed to be spent.
Expand Down
135 changes: 0 additions & 135 deletions sdk/main/include/TokenNftRemoveAllowance.h

This file was deleted.

12 changes: 6 additions & 6 deletions sdk/main/src/AccountAllowanceApproveTransaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ AccountAllowanceApproveTransaction& AccountAllowanceApproveTransaction::approveT
// Add the serial number to the token allowance if there's already an allowance for this token ID, owner, and spender.
for (TokenNftAllowance& allowance : mNftAllowances)
{
if (allowance.getTokenId() == nftId.getTokenId() && allowance.getOwnerAccountId() == ownerAccountId &&
allowance.getSpenderAccountId() == spenderAccountId)
if (allowance.mTokenId == nftId.getTokenId() && allowance.mOwnerAccountId == ownerAccountId &&
allowance.mSpenderAccountId == spenderAccountId)
{
allowance.addSerialNumber(nftId.getSerialNum());
allowance.mSerialNumbers.push_back(nftId.getSerialNum());
return *this;
}
}
Expand All @@ -124,10 +124,10 @@ AccountAllowanceApproveTransaction& AccountAllowanceApproveTransaction::approveN

for (TokenNftAllowance& allowance : mNftAllowances)
{
if (allowance.getTokenId() == tokenId && allowance.getOwnerAccountId() == ownerAccountId &&
allowance.getSpenderAccountId() == spenderAccountId)
if (allowance.mTokenId == tokenId && allowance.mOwnerAccountId == ownerAccountId &&
allowance.mSpenderAccountId == spenderAccountId)
{
allowance.approveForAll(true);
allowance.mApprovedForAll = true;
return *this;
}
}
Expand Down
Loading
Loading