From 269950891462565d1984cb69420e859f5451b037 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 17 Aug 2020 11:49:43 +0300 Subject: [PATCH] wallet: emit proper multisignature In case when a signature needs to be added to multisig we must first find corresponding signer, not append new witness. --- pkg/rpc/server/client_test.go | 9 +++++---- pkg/wallet/account.go | 12 ++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/rpc/server/client_test.go b/pkg/rpc/server/client_test.go index 9bcff6063..dea10aabe 100644 --- a/pkg/rpc/server/client_test.go +++ b/pkg/rpc/server/client_test.go @@ -109,10 +109,10 @@ func TestAddNetworkFee(t *testing.T) { t.Run("Multi", func(t *testing.T) { tx := transaction.New(testchain.Network(), []byte{byte(opcode.PUSH1)}, 0) - accs := getAccounts(t, 3) - pubs := keys.PublicKeys{accs[1].PrivateKey().PublicKey(), accs[2].PrivateKey().PublicKey()} - require.NoError(t, accs[1].ConvertMultisig(1, pubs)) - require.NoError(t, accs[2].ConvertMultisig(1, pubs)) + accs := getAccounts(t, 4) + pubs := keys.PublicKeys{accs[1].PrivateKey().PublicKey(), accs[2].PrivateKey().PublicKey(), accs[3].PrivateKey().PublicKey()} + require.NoError(t, accs[1].ConvertMultisig(2, pubs)) + require.NoError(t, accs[2].ConvertMultisig(2, pubs)) tx.Signers = []transaction.Signer{ { Account: accs[0].PrivateKey().GetScriptHash(), @@ -126,6 +126,7 @@ func TestAddNetworkFee(t *testing.T) { require.NoError(t, c.AddNetworkFee(tx, 10, accs[0], accs[1])) require.NoError(t, accs[0].SignTx(tx)) require.NoError(t, accs[1].SignTx(tx)) + require.NoError(t, accs[2].SignTx(tx)) cFee, _ := core.CalculateNetworkFee(accs[0].Contract.Script) cFeeM, _ := core.CalculateNetworkFee(accs[1].Contract.Script) require.Equal(t, int64(io.GetVarSize(tx))*feePerByte+cFee+cFeeM+10, tx.NetworkFee) diff --git a/pkg/wallet/account.go b/pkg/wallet/account.go index 6ec829f21..393bf22a7 100644 --- a/pkg/wallet/account.go +++ b/pkg/wallet/account.go @@ -104,9 +104,17 @@ func (a *Account) SignTx(t *transaction.Transaction) error { } sign := a.privateKey.Sign(data) + verif := a.getVerificationScript() + invoc := append([]byte{byte(opcode.PUSHDATA1), 64}, sign...) + for i := range t.Scripts { + if bytes.Equal(t.Scripts[i].VerificationScript, verif) { + t.Scripts[i].InvocationScript = append(t.Scripts[i].InvocationScript, invoc...) + return nil + } + } t.Scripts = append(t.Scripts, transaction.Witness{ - InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, sign...), - VerificationScript: a.getVerificationScript(), + InvocationScript: invoc, + VerificationScript: verif, }) return nil