Skip to content

Commit

Permalink
fix: Transaction.ToBytes() to use EncodeMessage instead of Marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
janaakhterov committed Nov 11, 2020
1 parent b285319 commit cc651d5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TransactionFromBytes(bytes []byte) (interface{}, error) {

for {
tx := proto.Transaction{}
if err := buf.Unmarshal(&tx); err != nil {
if err := buf.DecodeMessage(&tx); err != nil {
break
}

Expand All @@ -81,8 +81,8 @@ func TransactionFromBytes(bytes []byte) (interface{}, error) {
first = &txBody
}

transactionID := transactionIDFromProtobuf(txBody.TransactionID)
nodeAccountID := accountIDFromProtobuf(txBody.NodeAccountID)
transactionID := transactionIDFromProtobuf(txBody.GetTransactionID())
nodeAccountID := accountIDFromProtobuf(txBody.GetNodeAccountID())

if _, ok := transactions[transactionID]; !ok {
transactions[transactionID] = make(map[AccountID]*proto.Transaction)
Expand Down Expand Up @@ -330,8 +330,12 @@ func (transaction *Transaction) String() string {
func (transaction *Transaction) ToBytes() ([]byte, error) {
buf := protobuf.NewBuffer(make([]byte, 0))

if len(transaction.transactions) == 0 {
return buf.Bytes(), errTransactionIsNotFrozen
}

for _, tx := range transaction.transactions {
err := buf.Marshal(tx)
err := buf.EncodeMessage(tx)
if err != nil {
return buf.Bytes(), err
}
Expand Down

0 comments on commit cc651d5

Please sign in to comment.