Skip to content

Commit

Permalink
feat: Added frozen check to Transaction.AddSignature for consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrix10 committed Apr 16, 2021
1 parent 58c9461 commit ee17ee9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ func (transaction *Transaction) GetSignatures() (map[AccountID]map[*PublicKey][]
func (transaction *Transaction) AddSignature(publicKey PublicKey, signature []byte) *Transaction {
transaction.requireOneNodeAccountID()

if !transaction.isFrozen(){
transaction.freeze()
}

if transaction.keyAlreadySigned(publicKey) {
return transaction
}
Expand Down Expand Up @@ -363,6 +367,25 @@ func transaction_freezeWith(
return nil
}

func (transaction *Transaction) freeze() {
for _, nodeAccountID := range transaction.nodeIDs {
transaction.pbBody.NodeAccountID = nodeAccountID.toProtobuf()
bodyBytes, err := protobuf.Marshal(transaction.pbBody)
if err != nil {
// This should be unreachable
// From the documentation this appears to only be possible if there are missing proto types
panic(err)
}

transaction.signedTransactions = append(transaction.signedTransactions, &proto.SignedTransaction{
BodyBytes: bodyBytes,
SigMap: &proto.SignatureMap{
SigPair: make([]*proto.SignaturePair, 0),
},
})
}
}

func (transaction *Transaction) keyAlreadySigned(
pk PublicKey,
) bool {
Expand Down

0 comments on commit ee17ee9

Please sign in to comment.