github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_grant_kyc_transaction.go (about) 1 package hedera 2 3 /*- 4 * 5 * Hedera Go SDK 6 * 7 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 */ 22 23 import ( 24 "time" 25 26 "github.com/hashgraph/hedera-protobufs-go/services" 27 ) 28 29 // TokenGrantKycTransaction 30 // Grants KYC to the account for the given token. Must be signed by the Token's kycKey. 31 // If the provided account is not found, the transaction will resolve to INVALID_ACCOUNT_ID. 32 // If the provided account has been deleted, the transaction will resolve to ACCOUNT_DELETED. 33 // If the provided token is not found, the transaction will resolve to INVALID_TOKEN_ID. 34 // If the provided token has been deleted, the transaction will resolve to TOKEN_WAS_DELETED. 35 // If an Association between the provided token and account is not found, the transaction will 36 // resolve to TOKEN_NOT_ASSOCIATED_TO_ACCOUNT. 37 // If no KYC Key is defined, the transaction will resolve to TOKEN_HAS_NO_KYC_KEY. 38 // Once executed the Account is marked as KYC Granted. 39 type TokenGrantKycTransaction struct { 40 Transaction 41 tokenID *TokenID 42 accountID *AccountID 43 } 44 45 // NewTokenGrantKycTransaction creates TokenGrantKycTransaction which 46 // grants KYC to the account for the given token. Must be signed by the Token's kycKey. 47 // If the provided account is not found, the transaction will resolve to INVALID_ACCOUNT_ID. 48 // If the provided account has been deleted, the transaction will resolve to ACCOUNT_DELETED. 49 // If the provided token is not found, the transaction will resolve to INVALID_TOKEN_ID. 50 // If the provided token has been deleted, the transaction will resolve to TOKEN_WAS_DELETED. 51 // If an Association between the provided token and account is not found, the transaction will 52 // resolve to TOKEN_NOT_ASSOCIATED_TO_ACCOUNT. 53 // If no KYC Key is defined, the transaction will resolve to TOKEN_HAS_NO_KYC_KEY. 54 // Once executed the Account is marked as KYC Granted. 55 func NewTokenGrantKycTransaction() *TokenGrantKycTransaction { 56 tx := TokenGrantKycTransaction{ 57 Transaction: _NewTransaction(), 58 } 59 60 tx._SetDefaultMaxTransactionFee(NewHbar(30)) 61 62 return &tx 63 } 64 65 func _TokenGrantKycTransactionFromProtobuf(tx Transaction, pb *services.TransactionBody) *TokenGrantKycTransaction { 66 return &TokenGrantKycTransaction{ 67 Transaction: tx, 68 tokenID: _TokenIDFromProtobuf(pb.GetTokenGrantKyc().GetToken()), 69 accountID: _AccountIDFromProtobuf(pb.GetTokenGrantKyc().GetAccount()), 70 } 71 } 72 73 // SetTokenID Sets the token for which this account will be granted KYC. 74 // If token does not exist, transaction results in INVALID_TOKEN_ID 75 func (tx *TokenGrantKycTransaction) SetTokenID(tokenID TokenID) *TokenGrantKycTransaction { 76 tx._RequireNotFrozen() 77 tx.tokenID = &tokenID 78 return tx 79 } 80 81 // GetTokenID returns the token for which this account will be granted KYC. 82 func (tx *TokenGrantKycTransaction) GetTokenID() TokenID { 83 if tx.tokenID == nil { 84 return TokenID{} 85 } 86 87 return *tx.tokenID 88 } 89 90 // SetAccountID Sets the account to be KYCed 91 func (tx *TokenGrantKycTransaction) SetAccountID(accountID AccountID) *TokenGrantKycTransaction { 92 tx._RequireNotFrozen() 93 tx.accountID = &accountID 94 return tx 95 } 96 97 // GetAccountID returns the AccountID that is being KYCed 98 func (tx *TokenGrantKycTransaction) GetAccountID() AccountID { 99 if tx.accountID == nil { 100 return AccountID{} 101 } 102 103 return *tx.accountID 104 } 105 106 // ---- Required Interfaces ---- // 107 108 // Sign uses the provided privateKey to sign the transaction. 109 func (tx *TokenGrantKycTransaction) Sign(privateKey PrivateKey) *TokenGrantKycTransaction { 110 tx.Transaction.Sign(privateKey) 111 return tx 112 } 113 114 // SignWithOperator signs the transaction with client's operator privateKey. 115 func (tx *TokenGrantKycTransaction) SignWithOperator(client *Client) (*TokenGrantKycTransaction, error) { 116 _, err := tx.Transaction.signWithOperator(client, tx) 117 if err != nil { 118 return nil, err 119 } 120 return tx, nil 121 } 122 123 // SignWith executes the TransactionSigner and adds the resulting signature data to the Transaction's signature map 124 // with the publicKey as the map key. 125 func (tx *TokenGrantKycTransaction) SignWith( 126 publicKey PublicKey, 127 signer TransactionSigner, 128 ) *TokenGrantKycTransaction { 129 tx.Transaction.SignWith(publicKey, signer) 130 return tx 131 } 132 133 // AddSignature adds a signature to the transaction. 134 func (tx *TokenGrantKycTransaction) AddSignature(publicKey PublicKey, signature []byte) *TokenGrantKycTransaction { 135 tx.Transaction.AddSignature(publicKey, signature) 136 return tx 137 } 138 139 // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.) 140 func (tx *TokenGrantKycTransaction) SetGrpcDeadline(deadline *time.Duration) *TokenGrantKycTransaction { 141 tx.Transaction.SetGrpcDeadline(deadline) 142 return tx 143 } 144 145 func (tx *TokenGrantKycTransaction) Freeze() (*TokenGrantKycTransaction, error) { 146 return tx.FreezeWith(nil) 147 } 148 149 func (tx *TokenGrantKycTransaction) FreezeWith(client *Client) (*TokenGrantKycTransaction, error) { 150 _, err := tx.Transaction.freezeWith(client, tx) 151 return tx, err 152 } 153 154 // SetMaxTransactionFee sets the max transaction fee for this TokenGrantKycTransaction. 155 func (tx *TokenGrantKycTransaction) SetMaxTransactionFee(fee Hbar) *TokenGrantKycTransaction { 156 tx.Transaction.SetMaxTransactionFee(fee) 157 return tx 158 } 159 160 // SetRegenerateTransactionID sets if transaction IDs should be regenerated when `TRANSACTION_EXPIRED` is received 161 func (tx *TokenGrantKycTransaction) SetRegenerateTransactionID(regenerateTransactionID bool) *TokenGrantKycTransaction { 162 tx.Transaction.SetRegenerateTransactionID(regenerateTransactionID) 163 return tx 164 } 165 166 // SetTransactionMemo sets the memo for this TokenGrantKycTransaction. 167 func (tx *TokenGrantKycTransaction) SetTransactionMemo(memo string) *TokenGrantKycTransaction { 168 tx.Transaction.SetTransactionMemo(memo) 169 return tx 170 } 171 172 // SetTransactionValidDuration sets the valid duration for this TokenGrantKycTransaction. 173 func (tx *TokenGrantKycTransaction) SetTransactionValidDuration(duration time.Duration) *TokenGrantKycTransaction { 174 tx.Transaction.SetTransactionValidDuration(duration) 175 return tx 176 } 177 178 // ToBytes serialise the tx to bytes, no matter if it is signed (locked), or not 179 func (tx *TokenGrantKycTransaction) ToBytes() ([]byte, error) { 180 bytes, err := tx.Transaction.toBytes(tx) 181 if err != nil { 182 return nil, err 183 } 184 return bytes, nil 185 } 186 187 // SetTransactionID sets the TransactionID for this TokenGrantKycTransaction. 188 func (tx *TokenGrantKycTransaction) SetTransactionID(transactionID TransactionID) *TokenGrantKycTransaction { 189 tx.Transaction.SetTransactionID(transactionID) 190 return tx 191 } 192 193 // SetNodeAccountIDs sets the _Node AccountID for this TokenGrantKycTransaction. 194 func (tx *TokenGrantKycTransaction) SetNodeAccountIDs(nodeID []AccountID) *TokenGrantKycTransaction { 195 tx.Transaction.SetNodeAccountIDs(nodeID) 196 return tx 197 } 198 199 // SetMaxRetry sets the max number of errors before execution will fail. 200 func (tx *TokenGrantKycTransaction) SetMaxRetry(count int) *TokenGrantKycTransaction { 201 tx.Transaction.SetMaxRetry(count) 202 return tx 203 } 204 205 // SetMaxBackoff The maximum amount of time to wait between retries. 206 // Every retry attempt will increase the wait time exponentially until it reaches this time. 207 func (tx *TokenGrantKycTransaction) SetMaxBackoff(max time.Duration) *TokenGrantKycTransaction { 208 tx.Transaction.SetMaxBackoff(max) 209 return tx 210 } 211 212 // SetMinBackoff sets the minimum amount of time to wait between retries. 213 func (tx *TokenGrantKycTransaction) SetMinBackoff(min time.Duration) *TokenGrantKycTransaction { 214 tx.Transaction.SetMinBackoff(min) 215 return tx 216 } 217 218 func (tx *TokenGrantKycTransaction) SetLogLevel(level LogLevel) *TokenGrantKycTransaction { 219 tx.Transaction.SetLogLevel(level) 220 return tx 221 } 222 223 func (tx *TokenGrantKycTransaction) Execute(client *Client) (TransactionResponse, error) { 224 return tx.Transaction.execute(client, tx) 225 } 226 227 func (tx *TokenGrantKycTransaction) Schedule() (*ScheduleCreateTransaction, error) { 228 return tx.Transaction.schedule(tx) 229 } 230 231 // ----------- Overridden functions ---------------- 232 233 func (tx *TokenGrantKycTransaction) getName() string { 234 return "TokenGrantKycTransaction" 235 } 236 237 func (tx *TokenGrantKycTransaction) validateNetworkOnIDs(client *Client) error { 238 if client == nil || !client.autoValidateChecksums { 239 return nil 240 } 241 242 if tx.tokenID != nil { 243 if err := tx.tokenID.ValidateChecksum(client); err != nil { 244 return err 245 } 246 } 247 248 if tx.accountID != nil { 249 if err := tx.accountID.ValidateChecksum(client); err != nil { 250 return err 251 } 252 } 253 254 return nil 255 } 256 257 func (tx *TokenGrantKycTransaction) build() *services.TransactionBody { 258 return &services.TransactionBody{ 259 TransactionFee: tx.transactionFee, 260 Memo: tx.Transaction.memo, 261 TransactionValidDuration: _DurationToProtobuf(tx.GetTransactionValidDuration()), 262 TransactionID: tx.transactionID._ToProtobuf(), 263 Data: &services.TransactionBody_TokenGrantKyc{ 264 TokenGrantKyc: tx.buildProtoBody(), 265 }, 266 } 267 } 268 269 func (tx *TokenGrantKycTransaction) buildScheduled() (*services.SchedulableTransactionBody, error) { 270 return &services.SchedulableTransactionBody{ 271 TransactionFee: tx.transactionFee, 272 Memo: tx.Transaction.memo, 273 Data: &services.SchedulableTransactionBody_TokenGrantKyc{ 274 TokenGrantKyc: tx.buildProtoBody(), 275 }, 276 }, nil 277 } 278 279 func (tx *TokenGrantKycTransaction) buildProtoBody() *services.TokenGrantKycTransactionBody { 280 body := &services.TokenGrantKycTransactionBody{} 281 if tx.tokenID != nil { 282 body.Token = tx.tokenID._ToProtobuf() 283 } 284 285 if tx.accountID != nil { 286 body.Account = tx.accountID._ToProtobuf() 287 } 288 289 return body 290 } 291 292 func (tx *TokenGrantKycTransaction) getMethod(channel *_Channel) _Method { 293 return _Method{ 294 transaction: channel._GetToken().GrantKycToTokenAccount, 295 } 296 } 297 func (tx *TokenGrantKycTransaction) _ConstructScheduleProtobuf() (*services.SchedulableTransactionBody, error) { 298 return tx.buildScheduled() 299 }