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

Implement TokenPauseTransaction #408

Merged
merged 4 commits into from
Jul 13, 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: 1 addition & 0 deletions sdk/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ add_library(${PROJECT_NAME} STATIC
src/TokenNftAllowance.cc
src/TokenNftRemoveAllowance.cc
src/TokenNftTransfer.cc
src/TokenPauseTransaction.cc
src/TokenRevokeKycTransaction.cc
src/TokenSupplyType.cc
src/TokenTransfer.cc
Expand Down
133 changes: 133 additions & 0 deletions sdk/main/include/TokenPauseTransaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*-
*
* Hedera C++ SDK
*
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef HEDERA_SDK_CPP_TOKEN_PAUSE_TRANSACTION_H_
#define HEDERA_SDK_CPP_TOKEN_PAUSE_TRANSACTION_H_

#include "TokenId.h"
#include "Transaction.h"

namespace proto
{
class TokenPauseTransactionBody;
class TransactionBody;
}

namespace Hedera
{
/**
* A token pause transaction prevents the token from being involved in any kind of operation. The token's pause key is
* required to sign the transaction. This is a key that is specified during the creation of a token. If a token has no
* pause key, you will not be able to pause the token. If the pause key was not set during the creation of a token, you
* will not be able to update the token to add this key.
*
* The following operations cannot be performed when a token is paused and will result in a TOKEN_IS_PAUSED status:
* - Updating the token
* - Transferring the token
* - Transferring any other token where it has its paused key in a custom fee schedule
* - Deleting the token
* - Minting or burning a token
* - Freezing or unfreezing an account that holds the token
* - Enabling or disabling KYC
* - Associating or disassociating a token
* - Wiping a token
*
* Once a token is paused, token status will update to paused. To verify if the token's status has been updated to
* paused, you can request the token info via the SDK or use the token info mirror node query. If the token is not
* paused the token status will be unpaused. The token status for tokens that do not have an assigned pause key will
* state PauseNotApplicable.
*
* Transaction Signing Requirements:
* - The pause key of the token.
* - Transaction fee payer account key.
*/
class TokenPauseTransaction : public Transaction<TokenPauseTransaction>
{
public:
TokenPauseTransaction() = default;

/**
* Construct from a TransactionBody protobuf object.
*
* @param transactionBody The TransactionBody protobuf object from which to construct.
* @throws std::invalid_argument If the input TransactionBody does not represent a TokenPause transaction.
*/
explicit TokenPauseTransaction(const proto::TransactionBody& transactionBody);

/**
* Set the ID of the tokens to pause.
*
* @param tokenId The ID of the tokens to pause.
* @return A reference to this TokenPauseTransaction object with the newly-set token ID.
* @throws IllegalStateException If this TokenPauseTransaction is frozen.
*/
TokenPauseTransaction& setTokenId(const TokenId& tokenId);

/**
* Get the ID of the tokens to pause.
*
* @return The ID of the tokens to pause.
*/
[[nodiscard]] inline TokenId getTokenId() const { return mTokenId; }

private:
/**
* Derived from Executable. Construct a Transaction protobuf object from this TokenPauseTransaction object.
*
* @param client The Client trying to construct this TokenPauseTransaction.
* @param node The Node to which this TokenPauseTransaction will be sent. This is unused.
* @return A Transaction protobuf object filled with this TokenPauseTransaction object's data.
* @throws UninitializedException If the input client has no operator with which to sign this
* TokenPauseTransaction.
*/
[[nodiscard]] proto::Transaction makeRequest(const Client& client,
const std::shared_ptr<internal::Node>& /*node*/) const override;

/**
* Derived from Executable. Submit this TokenPauseTransaction to a Node.
*
* @param client The Client submitting this TokenPauseTransaction.
* @param deadline The deadline for submitting this TokenPauseTransaction.
* @param node Pointer to the Node to which this TokenPauseTransaction should be submitted.
* @param response Pointer to the TransactionResponse protobuf object that gRPC should populate with the response
* information from the gRPC server.
* @return The gRPC status of the submission.
*/
[[nodiscard]] grpc::Status submitRequest(const Client& client,
const std::chrono::system_clock::time_point& deadline,
const std::shared_ptr<internal::Node>& node,
proto::TransactionResponse* response) const override;

/**
* Build a TokenPauseTransactionBody protobuf object from this TokenPauseTransaction object.
*
* @return A pointer to a TokenPauseTransactionBody protobuf object filled with this TokenPauseTransaction object's
* data.
*/
[[nodiscard]] proto::TokenPauseTransactionBody* build() const;

/**
* The ID of the token to pause.
*/
TokenId mTokenId;
};

} // namespace Hedera

#endif // HEDERA_SDK_CPP_TOKEN_PAUSE_TRANSACTION_H_
4 changes: 3 additions & 1 deletion sdk/main/include/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TokenDissociateTransaction;
class TokenFeeScheduleUpdateTransaction;
class TokenGrantKycTransaction;
class TokenMintTransaction;
class TokenPauseTransaction;
class TokenRevokeKycTransaction;
class TokenUpdateTransaction;
class TokenWipeTransaction;
Expand Down Expand Up @@ -142,7 +143,8 @@ class Transaction
TokenDissociateTransaction,
TokenFeeScheduleUpdateTransaction,
TokenGrantKycTransaction,
TokenRevokeKycTransaction>>
TokenRevokeKycTransaction,
TokenPauseTransaction>>
fromBytes(const std::vector<std::byte>& bytes);

/**
Expand Down
2 changes: 2 additions & 0 deletions sdk/main/src/Executable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "TokenInfo.h"
#include "TokenInfoQuery.h"
#include "TokenMintTransaction.h"
#include "TokenPauseTransaction.h"
#include "TokenRevokeKycTransaction.h"
#include "TokenUpdateTransaction.h"
#include "TokenWipeTransaction.h"
Expand Down Expand Up @@ -379,6 +380,7 @@ template class Executable<TokenGrantKycTransaction,
TransactionResponse>;
template class Executable<TokenInfoQuery, proto::Query, proto::Response, TokenInfo>;
template class Executable<TokenMintTransaction, proto::Transaction, proto::TransactionResponse, TransactionResponse>;
template class Executable<TokenPauseTransaction, proto::Transaction, proto::TransactionResponse, TransactionResponse>;
template class Executable<TokenRevokeKycTransaction,
proto::Transaction,
proto::TransactionResponse,
Expand Down
88 changes: 88 additions & 0 deletions sdk/main/src/TokenPauseTransaction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*-
*
* Hedera C++ SDK
*
* Copyright (C) 2020 - 2022 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "TokenPauseTransaction.h"
#include "impl/Node.h"

#include <grpcpp/client_context.h>
#include <proto/token_pause.pb.h>
#include <proto/transaction.pb.h>
#include <stdexcept>

namespace Hedera
{
//-----
TokenPauseTransaction::TokenPauseTransaction(const proto::TransactionBody& transactionBody)
: Transaction<TokenPauseTransaction>(transactionBody)
{
if (!transactionBody.has_token_pause())
{
throw std::invalid_argument("Transaction body doesn't contain TokenPause data");
}

const proto::TokenPauseTransactionBody& body = transactionBody.token_pause();

if (body.has_token())
{
mTokenId = TokenId::fromProtobuf(body.token());
}
}

//-----
TokenPauseTransaction& TokenPauseTransaction::setTokenId(const TokenId& tokenId)
{
requireNotFrozen();
mTokenId = tokenId;
return *this;
}

//-----
proto::Transaction TokenPauseTransaction::makeRequest(const Client& client,
const std::shared_ptr<internal::Node>&) const
{
proto::TransactionBody transactionBody = generateTransactionBody(client);
transactionBody.set_allocated_token_pause(build());

return signTransaction(transactionBody, client);
}

//-----
grpc::Status TokenPauseTransaction::submitRequest(const Client& client,
const std::chrono::system_clock::time_point& deadline,
const std::shared_ptr<internal::Node>& node,
proto::TransactionResponse* response) const
{
return node->submitTransaction(
proto::TransactionBody::DataCase::kTokenPause, makeRequest(client, node), deadline, response);
}

//-----
proto::TokenPauseTransactionBody* TokenPauseTransaction::build() const
{
auto body = std::make_unique<proto::TokenPauseTransactionBody>();

if (!(mTokenId == TokenId()))
{
body->set_allocated_token(mTokenId.toProtobuf().release());
}

return body.release();
}

} // namespace Hedera
7 changes: 6 additions & 1 deletion sdk/main/src/Transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "TokenFeeScheduleUpdateTransaction.h"
#include "TokenGrantKycTransaction.h"
#include "TokenMintTransaction.h"
#include "TokenPauseTransaction.h"
#include "TokenRevokeKycTransaction.h"
#include "TokenUpdateTransaction.h"
#include "TokenWipeTransaction.h"
Expand Down Expand Up @@ -93,7 +94,8 @@ std::pair<int,
TokenDissociateTransaction,
TokenFeeScheduleUpdateTransaction,
TokenGrantKycTransaction,
TokenRevokeKycTransaction>>
TokenRevokeKycTransaction,
TokenPauseTransaction>>
Transaction<SdkRequestType>::fromBytes(const std::vector<std::byte>& bytes)
{
proto::TransactionBody txBody;
Expand Down Expand Up @@ -187,6 +189,8 @@ Transaction<SdkRequestType>::fromBytes(const std::vector<std::byte>& bytes)
return { 24, TokenGrantKycTransaction(txBody) };
case proto::TransactionBody::kTokenRevokeKyc:
return { 25, TokenRevokeKycTransaction(txBody) };
case proto::TransactionBody::kTokenPause:
return { 26, TokenPauseTransaction(txBody) };
default:
throw std::invalid_argument("Type of transaction cannot be determined from input bytes");
}
Expand Down Expand Up @@ -510,6 +514,7 @@ template class Transaction<TokenDissociateTransaction>;
template class Transaction<TokenFeeScheduleUpdateTransaction>;
template class Transaction<TokenGrantKycTransaction>;
template class Transaction<TokenMintTransaction>;
template class Transaction<TokenPauseTransaction>;
template class Transaction<TokenRevokeKycTransaction>;
template class Transaction<TokenUpdateTransaction>;
template class Transaction<TokenWipeTransaction>;
Expand Down
2 changes: 2 additions & 0 deletions sdk/main/src/impl/Node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ grpc::Status Node::submitTransaction(proto::TransactionBody::DataCase funcEnum,
return mTokenStub->grantKycToTokenAccount(&context, transaction, response);
case proto::TransactionBody::DataCase::kTokenMint:
return mTokenStub->mintToken(&context, transaction, response);
case proto::TransactionBody::DataCase::kTokenPause:
return mTokenStub->pauseToken(&context, transaction, response);
case proto::TransactionBody::DataCase::kTokenRevokeKyc:
return mTokenStub->revokeKycFromTokenAccount(&context, transaction, response);
case proto::TransactionBody::DataCase::kTokenUpdate:
Expand Down
1 change: 1 addition & 0 deletions sdk/tests/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_executable(${TEST_PROJECT_NAME}
TokenGrantKycTransactionIntegrationTests.cc
TokenInfoQueryIntegrationTests.cc
TokenMintTransactionIntegrationTests.cc
TokenPauseTransactionIntegrationTests.cc
TokenRevokeKycTransactionIntegrationTests.cc
TokenUpdateTransactionIntegrationTests.cc
TokenWipeTransactionIntegrationTests.cc
Expand Down
Loading
Loading