Skip to content

Commit

Permalink
fix: Made transaction_id String() include nonce and scheduled
Browse files Browse the repository at this point in the history
  • Loading branch information
andrix10 authored and janaakhterov committed Mar 8, 2021
1 parent 131e497 commit b480910
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions transaction_id.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hedera

import (
"encoding/hex"
"fmt"
protobuf "github.com/golang/protobuf/proto"
"math/rand"
Expand Down Expand Up @@ -67,13 +68,37 @@ func (id TransactionID) GetRecord(client *Client) (TransactionRecord, error) {
// String returns a string representation of the TransactionID in `AccountID@ValidStartSeconds.ValidStartNanos` format
func (id TransactionID) String() string {
var pb *proto.Timestamp
if id.ValidStart != nil {
pb = timeToProtobuf(*id.ValidStart)
if id.AccountID != nil{
if id.ValidStart != nil{
pb = timeToProtobuf(*id.ValidStart)
if id.Nonce != nil {
return fmt.Sprintf("%v@%v.%v, nonce: %s, scheduled: %t", id.AccountID, pb.Seconds, pb.Nanos, hex.EncodeToString(id.Nonce), id.scheduled)
}

return fmt.Sprintf("%v@%v.%v, scheduled: %t", id.AccountID, pb.Seconds, pb.Nanos, id.scheduled)
} else {
if id.Nonce != nil {
return fmt.Sprintf("%v@%v.%v, nonce: %s, scheduled: %t", id.AccountID, 0, 0, hex.EncodeToString(id.Nonce), id.scheduled)
}

return fmt.Sprintf("%v@%v.%v, scheduled: %t", id.AccountID, 0, 0, id.scheduled)
}
} else {
return fmt.Sprintf("%v@%v.%v", id.AccountID, 0, 0)
if id.ValidStart != nil{
pb = timeToProtobuf(*id.ValidStart)
if id.Nonce != nil {
return fmt.Sprintf("%s@%v.%v, nonce: %s, scheduled: %t", "0.0.0", pb.Seconds, pb.Nanos, hex.EncodeToString(id.Nonce), id.scheduled)
}

return fmt.Sprintf("%s@%v.%v, scheduled: %t", "0.0.0", pb.Seconds, pb.Nanos, id.scheduled)
} else {
if id.Nonce != nil {
return fmt.Sprintf("%s@%v.%v, nonce: %s, scheduled: %t", "0.0.0", 0, 0, hex.EncodeToString(id.Nonce), id.scheduled)
}

return fmt.Sprintf("%s@%v.%v, scheduled: %t", "0.0.0", 0, 0, id.scheduled)
}
}

return fmt.Sprintf("%v@%v.%v", id.AccountID, pb.Seconds, pb.Nanos)
}

func (id TransactionID) toProtobuf() *proto.TransactionID {
Expand Down

0 comments on commit b480910

Please sign in to comment.