Skip to content

Commit

Permalink
Adding logs for Node account IDs for which a scheduled transaction is… (
Browse files Browse the repository at this point in the history
#732)

* Adding logs for Node account IDs for which a scheduled transaction is being signed. And on which node was executed when there is an error.

Signed-off-by: Nikolay Nedkov <[email protected]>

* Fixing statickcheck errors.

Signed-off-by: Nikolay Nedkov <[email protected]>

* Adding logs on failed scheduled burn and mint transactions.

Signed-off-by: Nikolay Nedkov <[email protected]>

Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Nikolay Nedkov authored Sep 9, 2022
1 parent 09a39de commit 0b93e4a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
34 changes: 21 additions & 13 deletions app/clients/hedera/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,49 @@ import (
type Node struct {
client *hedera.Client
maxRetry int
logger *log.Entry
}

// NewNodeClient creates new instance of hedera.Client based on the provided client configuration
func NewNodeClient(config config.Hedera) *Node {
func NewNodeClient(cfg config.Hedera) *Node {
var client *hedera.Client
switch config.Network {
switch cfg.Network {
case "mainnet":
client = hedera.ClientForMainnet()
case "testnet":
client = hedera.ClientForTestnet()
case "previewnet":
client = hedera.ClientForPreviewnet()
default:
log.Fatalf("Invalid Client Network provided: [%s]", config.Network)
log.Fatalf("Invalid Client Network provided: [%s]", cfg.Network)
}
if len(config.Rpc) > 0 {
log.Infof("Setting provided RPC nodes for [%s].", config.Network)
err := client.SetNetwork(config.Rpc)
if len(cfg.Rpc) > 0 {
log.Infof("Setting provided RPC nodes for [%s].", cfg.Network)
err := client.SetNetwork(cfg.Rpc)
if err != nil {
log.Fatalf("Could not set rpc nodes [%s]. Error: [%s]", config.Rpc, err)
log.Fatalf("Could not set rpc nodes [%s]. Error: [%s]", cfg.Rpc, err)
}
} else {
log.Infof("Setting default node rpc urls for [%s].", config.Network)
log.Infof("Setting default node rpc urls for [%s].", cfg.Network)
}

accID, err := hedera.AccountIDFromString(config.Operator.AccountId)
accID, err := hedera.AccountIDFromString(cfg.Operator.AccountId)
if err != nil {
log.Fatalf("Invalid Operator AccountId provided: [%s]", config.Operator.AccountId)
log.Fatalf("Invalid Operator AccountId provided: [%s]", cfg.Operator.AccountId)
}

privateKey, err := hedera.PrivateKeyFromString(config.Operator.PrivateKey)
privateKey, err := hedera.PrivateKeyFromString(cfg.Operator.PrivateKey)
if err != nil {
log.Fatalf("Invalid Operator PrivateKey provided: [%s]", config.Operator.PrivateKey)
log.Fatalf("Invalid Operator PrivateKey provided: [%s]", cfg.Operator.PrivateKey)
}

client.SetOperator(accID, privateKey)

return &Node{client: client, maxRetry: config.MaxRetry}
return &Node{
client: client,
maxRetry: cfg.MaxRetry,
logger: config.GetLoggerFor("Hedera Node Client"),
}
}

// GetClient returns the hedera.Client
Expand All @@ -86,6 +91,7 @@ func (hc Node) SubmitScheduledTokenMintTransaction(tokenID hedera.TokenID, amoun
return nil, err
}

hc.logger.Infof("[%s] Signing transaction with ID: [%s] and Node Account IDs: %v", memo, tx.GetTransactionID().String(), tx.GetNodeAccountIDs())
signedTransaction, err := tx.
SignWithOperator(hc.GetClient())
if err != nil {
Expand All @@ -106,6 +112,7 @@ func (hc Node) SubmitScheduledTokenBurnTransaction(tokenID hedera.TokenID, amoun
return nil, err
}

hc.logger.Infof("[%s] Signing transaction with ID: [%s] and Node Account IDs: %v", memo, tx.GetTransactionID().String(), tx.GetNodeAccountIDs())
signedTransaction, err := tx.
SignWithOperator(hc.GetClient())
if err != nil {
Expand Down Expand Up @@ -202,6 +209,7 @@ func (hc Node) submitScheduledTransferTransaction(payerAccountID hedera.AccountI
return nil, err
}

hc.logger.Infof("[%s] Signing transaction with ID: [%s] and Node Account IDs: %v", memo, tx.GetTransactionID().String(), tx.GetNodeAccountIDs())
signedTransaction, err := tx.
SignWithOperator(hc.GetClient())
if err != nil {
Expand Down
16 changes: 12 additions & 4 deletions app/services/scheduled/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ func (s *Service) ExecuteScheduledTransferTransaction(
onExecutionSuccess func(transactionID, scheduleID string), onExecutionFail, onSuccess, onFail func(transactionID string)) {
transactionResponse, err := s.executeScheduledTransfersTransaction(id, nativeAsset, transfers)
if err != nil {
s.logger.Errorf("[%s] - Failed to submit scheduled transfer transaction. Error [%s].", id, err)
if transactionResponse != nil {
onExecutionFail(hederahelper.ToMirrorNodeTransactionID(transactionResponse.TransactionID.String()))
s.logger.Errorf("[%s] - Failed to submit scheduled transfer transaction at Node Account [%s]. Error [%s].", id, transactionResponse.NodeID, err)
} else {
s.logger.Errorf("[%s] - Failed to submit scheduled transfer transaction. Error [%s].", id, err)
}
return
}
Expand All @@ -63,9 +65,11 @@ func (s *Service) ExecuteScheduledNftTransferTransaction(
onExecutionSuccess func(transactionID, scheduleID string), onExecutionFail, onSuccess, onFail func(transactionID string)) {
transactionResponse, err := s.hederaNodeClient.SubmitScheduledNftTransferTransaction(nftID, s.payerAccount, sender, receiving, id)
if err != nil {
s.logger.Errorf("[%s] - Failed to submit scheduled transfer transaction. Error [%s].", id, err)
if transactionResponse != nil {
onExecutionFail(hederahelper.ToMirrorNodeTransactionID(transactionResponse.TransactionID.String()))
s.logger.Errorf("[%s] - Failed to submit scheduled transfer transaction at Node Account [%s]. Error [%s].", id, transactionResponse.NodeID.String(), err)
} else {
s.logger.Errorf("[%s] - Failed to submit scheduled transfer transaction. Error [%s].", id, err)
}
return
}
Expand Down Expand Up @@ -99,9 +103,11 @@ func (s *Service) executeScheduledTransfersTransaction(id, nativeAsset string, t
func (s *Service) ExecuteScheduledMintTransaction(id, asset string, amount int64, status *chan string, onExecutionSuccess func(transactionID, scheduleID string), onExecutionFail, onSuccess, onFail func(transactionID string)) {
transactionResponse, err := s.executeScheduledTokenMintTransaction(id, asset, amount)
if err != nil {
s.logger.Errorf("[%s] - Failed to submit scheduled mint transaction. Error [%s].", id, err)
if transactionResponse != nil {
onExecutionFail(hederahelper.ToMirrorNodeTransactionID(transactionResponse.TransactionID.String()))
s.logger.Errorf("[%s] - Failed to submit scheduled mint transaction at Node Account [%s]. Error [%s].", id, transactionResponse.NodeID.String(), err)
} else {
s.logger.Errorf("[%s] - Failed to submit scheduled mint transaction. Error [%s].", id, err)
}
*status <- sync.FAIL
return
Expand All @@ -118,9 +124,11 @@ func (s *Service) ExecuteScheduledMintTransaction(id, asset string, amount int64
func (s *Service) ExecuteScheduledBurnTransaction(id, asset string, amount int64, status *chan string, onExecutionSuccess func(transactionID, scheduleID string), onExecutionFail, onSuccess, onFail func(transactionID string)) {
transactionResponse, err := s.executeScheduledTokenBurnTransaction(id, asset, amount)
if err != nil {
s.logger.Errorf("[%s] - Failed to submit scheduled burn transaction. Error [%s].", id, err)
if transactionResponse != nil {
onExecutionFail(hederahelper.ToMirrorNodeTransactionID(transactionResponse.TransactionID.String()))
s.logger.Errorf("[%s] - Failed to submit scheduled burn transaction at Node Account [%s]. Error [%s].", id, transactionResponse.NodeID.String(), err)
} else {
s.logger.Errorf("[%s] - Failed to submit scheduled burn transaction. Error [%s].", id, err)
}
*status <- sync.FAIL
return
Expand Down

0 comments on commit 0b93e4a

Please sign in to comment.