Skip to content

Commit

Permalink
feat: Added getBytes to transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
andrix10 committed Nov 10, 2020
1 parent 4eea031 commit 0c87a3d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ func TransactionFromBytes(bytes []byte) Transaction {
return tx
}

func (transaction *Transaction) ToBytes() ([]byte, error) {
data := make([]byte, len(transaction.transactions))

for i, _ := range transaction.nodeIDs {
marashaledBytes, err := protobuf.Marshal(transaction.transactions[i])
if err != nil {
// This should be unreachable
// From the documentation this appears to only be possible if there are missing proto types
return make([]byte, 0), err
}
data = append(data, marashaledBytes...)
}

return data, nil
}

func (transaction *Transaction) GetTransactionHash() (map[AccountID][]byte, error) {
transactionHash := make(map[AccountID][]byte)

Expand Down Expand Up @@ -217,10 +233,6 @@ func (transaction *Transaction) MarshalBinary() ([]byte, error) {
return protobuf.Marshal(transaction.transactions[0])
}

func (transaction *Transaction) ToBytes() ([]byte, error) {
return transaction.MarshalBinary()
}

// The protobuf stores the transaction body as raw bytes so we need to first
// decode what we have to inspect the Kind, TransactionID, and the NodeAccountID so we know how to
// properly execute it
Expand Down

0 comments on commit 0c87a3d

Please sign in to comment.