From 35d5495d3904a5d93cb3f2e3a4f1bcade7e68462 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sat, 24 Aug 2024 12:35:51 +0300 Subject: [PATCH] wallet: simplify signature handling Don't use an additional buffer, drop one branch. Signed-off-by: Roman Khimov --- pkg/wallet/account.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/wallet/account.go b/pkg/wallet/account.go index 558e4449a..50a5d91f1 100644 --- a/pkg/wallet/account.go +++ b/pkg/wallet/account.go @@ -150,14 +150,12 @@ func (a *Account) SignTx(net netmode.Magic, t *transaction.Transaction) error { if a.privateKey == nil { return errors.New("account key is not available (need to decrypt?)") } - sign := a.privateKey.SignHashable(uint32(net), t) - invoc := append([]byte{byte(opcode.PUSHDATA1), keys.SignatureLen}, sign...) - if len(a.Contract.Parameters) == 1 { - t.Scripts[pos].InvocationScript = invoc - } else { - t.Scripts[pos].InvocationScript = append(t.Scripts[pos].InvocationScript, invoc...) + if len(a.Contract.Parameters) == 1 && t.Scripts[pos].InvocationScript != nil { + t.Scripts[pos].InvocationScript = t.Scripts[pos].InvocationScript[:0] } + t.Scripts[pos].InvocationScript = append(t.Scripts[pos].InvocationScript, byte(opcode.PUSHDATA1), keys.SignatureLen) + t.Scripts[pos].InvocationScript = append(t.Scripts[pos].InvocationScript, a.privateKey.SignHashable(uint32(net), t)...) return nil }