github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/token_update_nfts_transaction.go (about)

     1  package hedera
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/hashgraph/hedera-protobufs-go/services"
     7  	"google.golang.org/protobuf/types/known/wrapperspb"
     8  )
     9  
    10  type TokenUpdateNfts struct {
    11  	Transaction
    12  	tokenID       *TokenID
    13  	serialNumbers []int64
    14  	metadata      *[]byte
    15  }
    16  
    17  func NewTokenUpdateNftsTransaction() *TokenUpdateNfts {
    18  	return &TokenUpdateNfts{
    19  		Transaction: _NewTransaction(),
    20  	}
    21  }
    22  
    23  func _NewTokenUpdateNftsTransactionFromProtobuf(tx Transaction, pb *services.TransactionBody) *TokenUpdateNfts {
    24  	return &TokenUpdateNfts{
    25  		Transaction:   tx,
    26  		tokenID:       _TokenIDFromProtobuf(pb.GetTokenUpdateNfts().GetToken()),
    27  		serialNumbers: append([]int64{}, pb.GetTokenUpdateNfts().GetSerialNumbers()...),
    28  	}
    29  }
    30  
    31  // Getter for tokenID
    32  func (t *TokenUpdateNfts) GetTokenID() *TokenID {
    33  	return t.tokenID
    34  }
    35  
    36  // Setter for tokenID
    37  func (t *TokenUpdateNfts) SetTokenID(tokenID TokenID) *TokenUpdateNfts {
    38  	t._RequireNotFrozen()
    39  	t.tokenID = &tokenID
    40  	return t
    41  }
    42  
    43  // Getter for serialNumbers
    44  func (t *TokenUpdateNfts) GetSerialNumbers() []int64 {
    45  	return t.serialNumbers
    46  }
    47  
    48  // Setter for serialNumbers
    49  func (t *TokenUpdateNfts) SetSerialNumbers(serialNumbers []int64) *TokenUpdateNfts {
    50  	t._RequireNotFrozen()
    51  	t.serialNumbers = serialNumbers
    52  	return t
    53  }
    54  
    55  // Getter for metadata
    56  func (t *TokenUpdateNfts) GetMetadata() *[]byte {
    57  	return t.metadata
    58  }
    59  
    60  // Setter for metadata
    61  func (t *TokenUpdateNfts) SetMetadata(metadata []byte) *TokenUpdateNfts {
    62  	t._RequireNotFrozen()
    63  	t.metadata = &metadata
    64  	return t
    65  }
    66  
    67  // ---- Required Interfaces ---- //
    68  
    69  // Sign uses the provided privateKey to sign the transaction.
    70  func (tx *TokenUpdateNfts) Sign(privateKey PrivateKey) *TokenUpdateNfts {
    71  	tx.Transaction.Sign(privateKey)
    72  	return tx
    73  }
    74  
    75  // SignWithOperator signs the transaction with client's operator privateKey.
    76  func (tx *TokenUpdateNfts) SignWithOperator(client *Client) (*TokenUpdateNfts, error) {
    77  	_, err := tx.Transaction.signWithOperator(client, tx)
    78  	if err != nil {
    79  		return nil, err
    80  	}
    81  	return tx, nil
    82  }
    83  
    84  // SignWith executes the TransactionSigner and adds the resulting signature data to the Transaction's signature map
    85  // with the publicKey as the map key.
    86  func (tx *TokenUpdateNfts) SignWith(
    87  	publicKey PublicKey,
    88  	signer TransactionSigner,
    89  ) *TokenUpdateNfts {
    90  	tx.Transaction.SignWith(publicKey, signer)
    91  	return tx
    92  }
    93  
    94  // AddSignature adds a signature to the transaction.
    95  func (tx *TokenUpdateNfts) AddSignature(publicKey PublicKey, signature []byte) *TokenUpdateNfts {
    96  	tx.Transaction.AddSignature(publicKey, signature)
    97  	return tx
    98  }
    99  
   100  // When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
   101  func (tx *TokenUpdateNfts) SetGrpcDeadline(deadline *time.Duration) *TokenUpdateNfts {
   102  	tx.Transaction.SetGrpcDeadline(deadline)
   103  	return tx
   104  }
   105  
   106  func (tx *TokenUpdateNfts) Freeze() (*TokenUpdateNfts, error) {
   107  	return tx.FreezeWith(nil)
   108  }
   109  
   110  func (tx *TokenUpdateNfts) FreezeWith(client *Client) (*TokenUpdateNfts, error) {
   111  	_, err := tx.Transaction.freezeWith(client, tx)
   112  	return tx, err
   113  }
   114  
   115  // SetMaxTransactionFee sets the max transaction fee for this TokenUpdateNfts.
   116  func (tx *TokenUpdateNfts) SetMaxTransactionFee(fee Hbar) *TokenUpdateNfts {
   117  	tx.Transaction.SetMaxTransactionFee(fee)
   118  	return tx
   119  }
   120  
   121  // SetRegenerateTransactionID sets if transaction IDs should be regenerated when `TRANSACTION_EXPIRED` is received
   122  func (tx *TokenUpdateNfts) SetRegenerateTransactionID(regenerateTransactionID bool) *TokenUpdateNfts {
   123  	tx.Transaction.SetRegenerateTransactionID(regenerateTransactionID)
   124  	return tx
   125  }
   126  
   127  // SetTransactionMemo sets the memo for this TokenUpdateNfts.
   128  func (tx *TokenUpdateNfts) SetTransactionMemo(memo string) *TokenUpdateNfts {
   129  	tx.Transaction.SetTransactionMemo(memo)
   130  	return tx
   131  }
   132  
   133  // SetTransactionValidDuration sets the valid duration for this TokenUpdateNfts.
   134  func (tx *TokenUpdateNfts) SetTransactionValidDuration(duration time.Duration) *TokenUpdateNfts {
   135  	tx.Transaction.SetTransactionValidDuration(duration)
   136  	return tx
   137  }
   138  
   139  // ToBytes serialise the tx to bytes, no matter if it is signed (locked), or not
   140  func (tx *TokenUpdateNfts) ToBytes() ([]byte, error) {
   141  	bytes, err := tx.Transaction.toBytes(tx)
   142  	if err != nil {
   143  		return nil, err
   144  	}
   145  	return bytes, nil
   146  }
   147  
   148  // SetTransactionID sets the TransactionID for this TokenUpdateNfts.
   149  func (tx *TokenUpdateNfts) SetTransactionID(transactionID TransactionID) *TokenUpdateNfts {
   150  	tx.Transaction.SetTransactionID(transactionID)
   151  	return tx
   152  }
   153  
   154  // SetNodeAccountIDs sets the _Node AccountID for this TokenUpdateNfts.
   155  func (tx *TokenUpdateNfts) SetNodeAccountIDs(nodeID []AccountID) *TokenUpdateNfts {
   156  	tx.Transaction.SetNodeAccountIDs(nodeID)
   157  	return tx
   158  }
   159  
   160  // SetMaxRetry sets the max number of errors before execution will fail.
   161  func (tx *TokenUpdateNfts) SetMaxRetry(count int) *TokenUpdateNfts {
   162  	tx.Transaction.SetMaxRetry(count)
   163  	return tx
   164  }
   165  
   166  // SetMaxBackoff The maximum amount of time to wait between retries.
   167  // Every retry attempt will increase the wait time exponentially until it reaches this time.
   168  func (tx *TokenUpdateNfts) SetMaxBackoff(max time.Duration) *TokenUpdateNfts {
   169  	tx.Transaction.SetMaxBackoff(max)
   170  	return tx
   171  }
   172  
   173  // SetMinBackoff sets the minimum amount of time to wait between retries.
   174  func (tx *TokenUpdateNfts) SetMinBackoff(min time.Duration) *TokenUpdateNfts {
   175  	tx.Transaction.SetMinBackoff(min)
   176  	return tx
   177  }
   178  
   179  func (tx *TokenUpdateNfts) SetLogLevel(level LogLevel) *TokenUpdateNfts {
   180  	tx.Transaction.SetLogLevel(level)
   181  	return tx
   182  }
   183  
   184  func (tx *TokenUpdateNfts) Execute(client *Client) (TransactionResponse, error) {
   185  	return tx.Transaction.execute(client, tx)
   186  }
   187  
   188  func (tx *TokenUpdateNfts) Schedule() (*ScheduleCreateTransaction, error) {
   189  	return tx.Transaction.schedule(tx)
   190  }
   191  
   192  func (tx *TokenUpdateNfts) getName() string {
   193  	return "TokenUpdateNfts"
   194  }
   195  
   196  func (tx *TokenUpdateNfts) validateNetworkOnIDs(client *Client) error {
   197  	if client == nil || !client.autoValidateChecksums {
   198  		return nil
   199  	}
   200  
   201  	if tx.tokenID != nil {
   202  		if err := tx.tokenID.ValidateChecksum(client); err != nil {
   203  			return err
   204  		}
   205  	}
   206  	return nil
   207  }
   208  
   209  func (tx *TokenUpdateNfts) build() *services.TransactionBody {
   210  	return &services.TransactionBody{
   211  		TransactionFee:           tx.transactionFee,
   212  		Memo:                     tx.Transaction.memo,
   213  		TransactionValidDuration: _DurationToProtobuf(tx.GetTransactionValidDuration()),
   214  		TransactionID:            tx.transactionID._ToProtobuf(),
   215  		Data: &services.TransactionBody_TokenUpdateNfts{
   216  			TokenUpdateNfts: tx.buildProtoBody(),
   217  		},
   218  	}
   219  }
   220  
   221  func (tx *TokenUpdateNfts) buildScheduled() (*services.SchedulableTransactionBody, error) {
   222  	return &services.SchedulableTransactionBody{
   223  		TransactionFee: tx.transactionFee,
   224  		Memo:           tx.Transaction.memo,
   225  		Data: &services.SchedulableTransactionBody_TokenUpdateNfts{
   226  			TokenUpdateNfts: tx.buildProtoBody(),
   227  		},
   228  	}, nil
   229  }
   230  
   231  func (tx *TokenUpdateNfts) buildProtoBody() *services.TokenUpdateNftsTransactionBody {
   232  	body := &services.TokenUpdateNftsTransactionBody{}
   233  
   234  	if tx.tokenID != nil {
   235  		body.Token = tx.tokenID._ToProtobuf()
   236  	}
   237  	serialNumbers := make([]int64, 0)
   238  	if len(tx.serialNumbers) != 0 {
   239  		for _, serialNumber := range tx.serialNumbers {
   240  			serialNumbers = append(serialNumbers, serialNumber)
   241  			body.SerialNumbers = serialNumbers
   242  		}
   243  	}
   244  	if tx.metadata != nil {
   245  		body.Metadata = wrapperspb.Bytes(*tx.metadata)
   246  	}
   247  	return body
   248  }
   249  
   250  func (tx *TokenUpdateNfts) getMethod(channel *_Channel) _Method {
   251  	return _Method{
   252  		transaction: channel._GetToken().UpdateNfts,
   253  	}
   254  }
   255  
   256  func (tx *TokenUpdateNfts) _ConstructScheduleProtobuf() (*services.SchedulableTransactionBody, error) {
   257  	return tx.buildScheduled()
   258  }