From 4ad52333ef4e5c50c61e9d1562b92af065aab43a Mon Sep 17 00:00:00 2001 From: Daniel Akhterov Date: Wed, 18 Nov 2020 19:44:50 -0800 Subject: [PATCH] fix: make `PrivateKey.SignTransaction()` fallible --- crypto.go | 10 ++++------ errors.go | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/crypto.go b/crypto.go index c10e6bdd4..758f7964f 100644 --- a/crypto.go +++ b/crypto.go @@ -349,17 +349,15 @@ func (pk PublicKey) toSignaturePairProtobuf(signature []byte) *proto.SignaturePa } } -func (sk PrivateKey) SignTransaction(transaction Transaction) []byte { +func (sk PrivateKey) SignTransaction(transaction Transaction) ([]byte, error) { transaction.requireExactNode() if len(transaction.transactions) == 0 { - return make([]byte, 0) + return make([]byte, 0), errTransactionRequiresSingleNodeAccountID } - transactionToSign := transaction.transactions[0] - signature := sk.Sign(transactionToSign.GetBodyBytes()) - + signature := sk.Sign(transaction.transactions[0].GetBodyBytes()) transaction.AddSignature(sk.PublicKey(), signature) - return signature + return signature, nil } diff --git a/errors.go b/errors.go index 4f9fa74b0..f604e37b8 100644 --- a/errors.go +++ b/errors.go @@ -22,6 +22,7 @@ var errNoClientProvided = errors.New("`client` must be provided and have an oper var errTransactionIsNotFrozen = errors.New("transaction is not frozen") var errFailedToDeserializeBytes = errors.New("Failed to deserialize bytes") var errNoTransactionInBytes = errors.New("No transaction was found in bytes") +var errTransactionRequiresSingleNodeAccountID = errors.New("`PrivateKey.SignTransaction()` requires `Transaction` to have a single node `AccountID` set") type ErrInvalidNodeAccountIDSet struct { NodeAccountID AccountID