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.
This commit is contained in:
Evgenii Stratonikov 2020-08-17 11:49:43 +03:00
parent 8699a4c1a9
commit 2699508914
2 changed files with 15 additions and 6 deletions

View file

@ -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)

View file

@ -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