github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/schedule_info.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  	"github.com/pkg/errors"
    28  )
    29  
    30  type ScheduleInfo struct {
    31  	ScheduleID       ScheduleID
    32  	CreatorAccountID AccountID
    33  	PayerAccountID   AccountID
    34  	ExecutedAt       *time.Time
    35  	DeletedAt        *time.Time
    36  	ExpirationTime   time.Time
    37  	Signatories      *KeyList
    38  	// Deprecated: Use ScheduleInfo.Signatories instead
    39  	Signers                  *KeyList
    40  	AdminKey                 Key
    41  	Memo                     string
    42  	ScheduledTransactionID   *TransactionID
    43  	scheduledTransactionBody *services.SchedulableTransactionBody
    44  	LedgerID                 LedgerID
    45  	WaitForExpiry            bool
    46  }
    47  
    48  func _ScheduleInfoFromProtobuf(pb *services.ScheduleInfo) ScheduleInfo {
    49  	if pb == nil {
    50  		return ScheduleInfo{}
    51  	}
    52  	var adminKey Key
    53  	if pb.AdminKey != nil {
    54  		adminKey, _ = _KeyFromProtobuf(pb.AdminKey)
    55  	}
    56  
    57  	var signatories KeyList
    58  	if pb.Signers != nil {
    59  		signatories, _ = _KeyListFromProtobuf(pb.Signers)
    60  	}
    61  
    62  	var scheduledTransactionID TransactionID
    63  	if pb.ScheduledTransactionID != nil {
    64  		scheduledTransactionID = _TransactionIDFromProtobuf(pb.ScheduledTransactionID)
    65  	}
    66  
    67  	var executed *time.Time
    68  	var deleted *time.Time
    69  	switch t := pb.Data.(type) {
    70  	case *services.ScheduleInfo_ExecutionTime:
    71  		temp := _TimeFromProtobuf(t.ExecutionTime)
    72  		executed = &temp
    73  	case *services.ScheduleInfo_DeletionTime:
    74  		temp := _TimeFromProtobuf(t.DeletionTime)
    75  		deleted = &temp
    76  	}
    77  
    78  	creatorAccountID := AccountID{}
    79  	if pb.CreatorAccountID != nil {
    80  		creatorAccountID = *_AccountIDFromProtobuf(pb.CreatorAccountID)
    81  	}
    82  
    83  	payerAccountID := AccountID{}
    84  	if pb.PayerAccountID != nil {
    85  		payerAccountID = *_AccountIDFromProtobuf(pb.PayerAccountID)
    86  	}
    87  
    88  	scheduleID := ScheduleID{}
    89  	if pb.ScheduleID != nil {
    90  		scheduleID = *_ScheduleIDFromProtobuf(pb.ScheduleID)
    91  	}
    92  
    93  	return ScheduleInfo{
    94  		ScheduleID:               scheduleID,
    95  		CreatorAccountID:         creatorAccountID,
    96  		PayerAccountID:           payerAccountID,
    97  		ExecutedAt:               executed,
    98  		DeletedAt:                deleted,
    99  		ExpirationTime:           _TimeFromProtobuf(pb.ExpirationTime),
   100  		Signatories:              &signatories,
   101  		Signers:                  &signatories,
   102  		AdminKey:                 adminKey,
   103  		Memo:                     pb.Memo,
   104  		ScheduledTransactionID:   &scheduledTransactionID,
   105  		scheduledTransactionBody: pb.ScheduledTransactionBody,
   106  		LedgerID:                 LedgerID{pb.LedgerId},
   107  		WaitForExpiry:            pb.WaitForExpiry,
   108  	}
   109  }
   110  
   111  func (scheduleInfo *ScheduleInfo) _ToProtobuf() *services.ScheduleInfo { // nolint
   112  	var adminKey *services.Key
   113  	if scheduleInfo.AdminKey != nil {
   114  		adminKey = scheduleInfo.AdminKey._ToProtoKey()
   115  	}
   116  
   117  	var signatories *services.KeyList
   118  	if scheduleInfo.Signatories != nil {
   119  		signatories = scheduleInfo.Signatories._ToProtoKeyList()
   120  	} else if scheduleInfo.Signers != nil {
   121  		signatories = scheduleInfo.Signers._ToProtoKeyList()
   122  	}
   123  
   124  	info := &services.ScheduleInfo{
   125  		ScheduleID:               scheduleInfo.ScheduleID._ToProtobuf(),
   126  		ExpirationTime:           _TimeToProtobuf(scheduleInfo.ExpirationTime),
   127  		ScheduledTransactionBody: scheduleInfo.scheduledTransactionBody,
   128  		Memo:                     scheduleInfo.Memo,
   129  		AdminKey:                 adminKey,
   130  		Signers:                  signatories,
   131  		CreatorAccountID:         scheduleInfo.CreatorAccountID._ToProtobuf(),
   132  		PayerAccountID:           scheduleInfo.PayerAccountID._ToProtobuf(),
   133  		ScheduledTransactionID:   scheduleInfo.ScheduledTransactionID._ToProtobuf(),
   134  		LedgerId:                 scheduleInfo.LedgerID.ToBytes(),
   135  		WaitForExpiry:            scheduleInfo.WaitForExpiry,
   136  	}
   137  
   138  	if scheduleInfo.ExecutedAt != nil {
   139  		info.Data = &services.ScheduleInfo_DeletionTime{
   140  			DeletionTime: _TimeToProtobuf(*scheduleInfo.DeletedAt),
   141  		}
   142  	} else if scheduleInfo.DeletedAt != nil {
   143  		info.Data = &services.ScheduleInfo_ExecutionTime{
   144  			ExecutionTime: _TimeToProtobuf(*scheduleInfo.ExecutedAt),
   145  		}
   146  	}
   147  
   148  	return info
   149  }
   150  
   151  // GetScheduledTransaction returns the scheduled transaction associated with this schedule
   152  func (scheduleInfo *ScheduleInfo) GetScheduledTransaction() (ITransaction, error) { // nolint
   153  	pb := scheduleInfo.scheduledTransactionBody
   154  
   155  	pbBody := &services.TransactionBody{
   156  		TransactionFee: pb.TransactionFee,
   157  		Memo:           pb.Memo,
   158  	}
   159  
   160  	tx := Transaction{
   161  		transactionFee: pb.GetTransactionFee(),
   162  		memo:           pb.GetMemo(),
   163  	}
   164  
   165  	switch pb.Data.(type) {
   166  	case *services.SchedulableTransactionBody_ContractCall:
   167  		pbBody.Data = &services.TransactionBody_ContractCall{
   168  			ContractCall: pb.GetContractCall(),
   169  		}
   170  
   171  		tx2 := _ContractExecuteTransactionFromProtobuf(tx, pbBody)
   172  		return tx2, nil
   173  	case *services.SchedulableTransactionBody_ContractCreateInstance:
   174  		pbBody.Data = &services.TransactionBody_ContractCreateInstance{
   175  			ContractCreateInstance: pb.GetContractCreateInstance(),
   176  		}
   177  
   178  		tx2 := _ContractCreateTransactionFromProtobuf(tx, pbBody)
   179  		return tx2, nil
   180  	case *services.SchedulableTransactionBody_ContractUpdateInstance:
   181  		pbBody.Data = &services.TransactionBody_ContractUpdateInstance{
   182  			ContractUpdateInstance: pb.GetContractUpdateInstance(),
   183  		}
   184  
   185  		tx2 := _ContractUpdateTransactionFromProtobuf(tx, pbBody)
   186  		return tx2, nil
   187  	case *services.SchedulableTransactionBody_ContractDeleteInstance:
   188  		pbBody.Data = &services.TransactionBody_ContractDeleteInstance{
   189  			ContractDeleteInstance: pb.GetContractDeleteInstance(),
   190  		}
   191  
   192  		tx2 := _ContractDeleteTransactionFromProtobuf(tx, pbBody)
   193  		return tx2, nil
   194  	case *services.SchedulableTransactionBody_CryptoCreateAccount:
   195  		pbBody.Data = &services.TransactionBody_CryptoCreateAccount{
   196  			CryptoCreateAccount: pb.GetCryptoCreateAccount(),
   197  		}
   198  
   199  		tx2 := _AccountCreateTransactionFromProtobuf(tx, pbBody)
   200  		return tx2, nil
   201  	case *services.SchedulableTransactionBody_CryptoDelete:
   202  		pbBody.Data = &services.TransactionBody_CryptoDelete{
   203  			CryptoDelete: pb.GetCryptoDelete(),
   204  		}
   205  
   206  		tx2 := _AccountDeleteTransactionFromProtobuf(tx, pbBody)
   207  		return tx2, nil
   208  	case *services.SchedulableTransactionBody_CryptoTransfer:
   209  		pbBody.Data = &services.TransactionBody_CryptoTransfer{
   210  			CryptoTransfer: pb.GetCryptoTransfer(),
   211  		}
   212  
   213  		tx2 := _TransferTransactionFromProtobuf(tx, pbBody)
   214  		return tx2, nil
   215  	case *services.SchedulableTransactionBody_CryptoUpdateAccount:
   216  		pbBody.Data = &services.TransactionBody_CryptoUpdateAccount{
   217  			CryptoUpdateAccount: pb.GetCryptoUpdateAccount(),
   218  		}
   219  
   220  		tx2 := _AccountUpdateTransactionFromProtobuf(tx, pbBody)
   221  		return tx2, nil
   222  	case *services.SchedulableTransactionBody_CryptoApproveAllowance:
   223  		pbBody.Data = &services.TransactionBody_CryptoApproveAllowance{
   224  			CryptoApproveAllowance: pb.GetCryptoApproveAllowance(),
   225  		}
   226  
   227  		tx2 := _AccountAllowanceApproveTransactionFromProtobuf(tx, pbBody)
   228  		return tx2, nil
   229  	case *services.SchedulableTransactionBody_CryptoDeleteAllowance:
   230  		pbBody.Data = &services.TransactionBody_CryptoDeleteAllowance{
   231  			CryptoDeleteAllowance: pb.GetCryptoDeleteAllowance(),
   232  		}
   233  
   234  		tx2 := _AccountAllowanceDeleteTransactionFromProtobuf(tx, pbBody)
   235  		return tx2, nil
   236  	case *services.SchedulableTransactionBody_FileAppend:
   237  		pbBody.Data = &services.TransactionBody_FileAppend{
   238  			FileAppend: pb.GetFileAppend(),
   239  		}
   240  
   241  		tx2 := _FileAppendTransactionFromProtobuf(tx, pbBody)
   242  		return tx2, nil
   243  	case *services.SchedulableTransactionBody_FileCreate:
   244  		pbBody.Data = &services.TransactionBody_FileCreate{
   245  			FileCreate: pb.GetFileCreate(),
   246  		}
   247  
   248  		tx2 := _FileCreateTransactionFromProtobuf(tx, pbBody)
   249  		return tx2, nil
   250  	case *services.SchedulableTransactionBody_FileDelete:
   251  		pbBody.Data = &services.TransactionBody_FileDelete{
   252  			FileDelete: pb.GetFileDelete(),
   253  		}
   254  
   255  		tx2 := _FileDeleteTransactionFromProtobuf(tx, pbBody)
   256  		return tx2, nil
   257  	case *services.SchedulableTransactionBody_FileUpdate:
   258  		pbBody.Data = &services.TransactionBody_FileUpdate{
   259  			FileUpdate: pb.GetFileUpdate(),
   260  		}
   261  
   262  		tx2 := _FileUpdateTransactionFromProtobuf(tx, pbBody)
   263  		return tx2, nil
   264  	case *services.SchedulableTransactionBody_SystemDelete:
   265  		pbBody.Data = &services.TransactionBody_SystemDelete{
   266  			SystemDelete: pb.GetSystemDelete(),
   267  		}
   268  
   269  		tx2 := _SystemDeleteTransactionFromProtobuf(tx, pbBody)
   270  		return tx2, nil
   271  	case *services.SchedulableTransactionBody_SystemUndelete:
   272  		pbBody.Data = &services.TransactionBody_SystemUndelete{
   273  			SystemUndelete: pb.GetSystemUndelete(),
   274  		}
   275  
   276  		tx2 := _SystemUndeleteTransactionFromProtobuf(tx, pbBody)
   277  		return tx2, nil
   278  	case *services.SchedulableTransactionBody_Freeze:
   279  		pbBody.Data = &services.TransactionBody_Freeze{
   280  			Freeze: pb.GetFreeze(),
   281  		}
   282  
   283  		tx2 := _FreezeTransactionFromProtobuf(tx, pbBody)
   284  		return tx2, nil
   285  	case *services.SchedulableTransactionBody_ConsensusCreateTopic:
   286  		pbBody.Data = &services.TransactionBody_ConsensusCreateTopic{
   287  			ConsensusCreateTopic: pb.GetConsensusCreateTopic(),
   288  		}
   289  
   290  		tx2 := _TopicCreateTransactionFromProtobuf(tx, pbBody)
   291  		return tx2, nil
   292  	case *services.SchedulableTransactionBody_ConsensusUpdateTopic:
   293  		pbBody.Data = &services.TransactionBody_ConsensusUpdateTopic{
   294  			ConsensusUpdateTopic: pb.GetConsensusUpdateTopic(),
   295  		}
   296  
   297  		tx2 := _TopicUpdateTransactionFromProtobuf(tx, pbBody)
   298  		return tx2, nil
   299  	case *services.SchedulableTransactionBody_ConsensusDeleteTopic:
   300  		pbBody.Data = &services.TransactionBody_ConsensusDeleteTopic{
   301  			ConsensusDeleteTopic: pb.GetConsensusDeleteTopic(),
   302  		}
   303  
   304  		tx2 := _TopicDeleteTransactionFromProtobuf(tx, pbBody)
   305  		return tx2, nil
   306  	case *services.SchedulableTransactionBody_ConsensusSubmitMessage:
   307  		pbBody.Data = &services.TransactionBody_ConsensusSubmitMessage{
   308  			ConsensusSubmitMessage: pb.GetConsensusSubmitMessage(),
   309  		}
   310  
   311  		tx2 := _TopicMessageSubmitTransactionFromProtobuf(tx, pbBody)
   312  		return tx2, nil
   313  	case *services.SchedulableTransactionBody_TokenCreation:
   314  		pbBody.Data = &services.TransactionBody_TokenCreation{
   315  			TokenCreation: pb.GetTokenCreation(),
   316  		}
   317  
   318  		tx2 := _TokenCreateTransactionFromProtobuf(tx, pbBody)
   319  		return tx2, nil
   320  	case *services.SchedulableTransactionBody_TokenFreeze:
   321  		pbBody.Data = &services.TransactionBody_TokenFreeze{
   322  			TokenFreeze: pb.GetTokenFreeze(),
   323  		}
   324  
   325  		tx2 := _TokenFreezeTransactionFromProtobuf(tx, pbBody)
   326  		return tx2, nil
   327  	case *services.SchedulableTransactionBody_TokenUnfreeze:
   328  		pbBody.Data = &services.TransactionBody_TokenUnfreeze{
   329  			TokenUnfreeze: pb.GetTokenUnfreeze(),
   330  		}
   331  
   332  		tx2 := _TokenUnfreezeTransactionFromProtobuf(tx, pbBody)
   333  		return tx2, nil
   334  	case *services.SchedulableTransactionBody_TokenFeeScheduleUpdate:
   335  		pbBody.Data = &services.TransactionBody_TokenFeeScheduleUpdate{
   336  			TokenFeeScheduleUpdate: pb.GetTokenFeeScheduleUpdate(),
   337  		}
   338  
   339  		tx2 := _TokenFeeScheduleUpdateTransactionFromProtobuf(tx, pbBody)
   340  		return tx2, nil
   341  	case *services.SchedulableTransactionBody_TokenGrantKyc:
   342  		pbBody.Data = &services.TransactionBody_TokenGrantKyc{
   343  			TokenGrantKyc: pb.GetTokenGrantKyc(),
   344  		}
   345  
   346  		tx2 := _TokenGrantKycTransactionFromProtobuf(tx, pbBody)
   347  		return tx2, nil
   348  	case *services.SchedulableTransactionBody_TokenRevokeKyc:
   349  		pbBody.Data = &services.TransactionBody_TokenRevokeKyc{
   350  			TokenRevokeKyc: pb.GetTokenRevokeKyc(),
   351  		}
   352  
   353  		tx2 := _TokenRevokeKycTransactionFromProtobuf(tx, pbBody)
   354  		return tx2, nil
   355  	case *services.SchedulableTransactionBody_TokenDeletion:
   356  		pbBody.Data = &services.TransactionBody_TokenDeletion{
   357  			TokenDeletion: pb.GetTokenDeletion(),
   358  		}
   359  
   360  		tx2 := _TokenDeleteTransactionFromProtobuf(tx, pbBody)
   361  		return tx2, nil
   362  	case *services.SchedulableTransactionBody_TokenUpdate:
   363  		pbBody.Data = &services.TransactionBody_TokenUpdate{
   364  			TokenUpdate: pb.GetTokenUpdate(),
   365  		}
   366  
   367  		tx2 := _TokenUpdateTransactionFromProtobuf(tx, pbBody)
   368  		return tx2, nil
   369  	case *services.SchedulableTransactionBody_TokenMint:
   370  		pbBody.Data = &services.TransactionBody_TokenMint{
   371  			TokenMint: pb.GetTokenMint(),
   372  		}
   373  
   374  		tx2 := _TokenMintTransactionFromProtobuf(tx, pbBody)
   375  		return tx2, nil
   376  	case *services.SchedulableTransactionBody_TokenBurn:
   377  		pbBody.Data = &services.TransactionBody_TokenBurn{
   378  			TokenBurn: pb.GetTokenBurn(),
   379  		}
   380  
   381  		tx2 := _TokenBurnTransactionFromProtobuf(tx, pbBody)
   382  		return tx2, nil
   383  	case *services.SchedulableTransactionBody_TokenWipe:
   384  		pbBody.Data = &services.TransactionBody_TokenWipe{
   385  			TokenWipe: pb.GetTokenWipe(),
   386  		}
   387  
   388  		tx2 := _TokenWipeTransactionFromProtobuf(tx, pbBody)
   389  		return tx2, nil
   390  	case *services.SchedulableTransactionBody_TokenAssociate:
   391  		pbBody.Data = &services.TransactionBody_TokenAssociate{
   392  			TokenAssociate: pb.GetTokenAssociate(),
   393  		}
   394  
   395  		tx2 := _TokenAssociateTransactionFromProtobuf(tx, pbBody)
   396  		return tx2, nil
   397  	case *services.SchedulableTransactionBody_TokenDissociate:
   398  		pbBody.Data = &services.TransactionBody_TokenDissociate{
   399  			TokenDissociate: pb.GetTokenDissociate(),
   400  		}
   401  
   402  		tx2 := _TokenDissociateTransactionFromProtobuf(tx, pbBody)
   403  		return tx2, nil
   404  	case *services.SchedulableTransactionBody_ScheduleDelete:
   405  		pbBody.Data = &services.TransactionBody_ScheduleDelete{
   406  			ScheduleDelete: pb.GetScheduleDelete(),
   407  		}
   408  
   409  		tx2 := _ScheduleDeleteTransactionFromProtobuf(tx, pbBody)
   410  		return tx2, nil
   411  	case *services.SchedulableTransactionBody_UtilPrng:
   412  		pbBody.Data = &services.TransactionBody_UtilPrng{
   413  			UtilPrng: pb.GetUtilPrng(),
   414  		}
   415  
   416  		tx2 := _PrngTransactionFromProtobuf(tx, pbBody)
   417  		return tx2, nil
   418  	default:
   419  		return nil, errors.New("(BUG) non-exhaustive switch statement")
   420  	}
   421  }