From 53edbd569fb8d410b546687d72966609f90b5cad Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 1 Sep 2022 16:39:48 +0300 Subject: [PATCH] wallet: don't allow to ConvertMultisig a locked account This stretched the definition of Locked somewhat, but still makes sense to me, locked accounts better not be touched. --- pkg/wallet/account.go | 3 +++ pkg/wallet/account_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/pkg/wallet/account.go b/pkg/wallet/account.go index 067d59e07..c3a0ba098 100644 --- a/pkg/wallet/account.go +++ b/pkg/wallet/account.go @@ -205,6 +205,9 @@ func NewAccountFromEncryptedWIF(wif string, pass string, scrypt keys.ScryptParam // ConvertMultisig sets a's contract to multisig contract with m sufficient signatures. func (a *Account) ConvertMultisig(m int, pubs []*keys.PublicKey) error { + if a.Locked { + return errors.New("account is locked") + } var found bool for i := range pubs { if bytes.Equal(a.publicKey, pubs[i].Bytes()) { diff --git a/pkg/wallet/account_test.go b/pkg/wallet/account_test.go index d2b0374de..841201edb 100644 --- a/pkg/wallet/account_test.go +++ b/pkg/wallet/account_test.go @@ -179,6 +179,12 @@ func TestAccount_ConvertMultisig(t *testing.T) { "03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699", } + t.Run("locked", func(t *testing.T) { + a.Locked = true + pubs := convertPubs(t, hexs) + require.Error(t, a.ConvertMultisig(1, pubs)) + a.Locked = false + }) t.Run("invalid number of signatures", func(t *testing.T) { pubs := convertPubs(t, hexs) require.Error(t, a.ConvertMultisig(0, pubs))