diff --git a/pkg/wallet/account.go b/pkg/wallet/account.go index 946ea4335..4abc659f1 100644 --- a/pkg/wallet/account.go +++ b/pkg/wallet/account.go @@ -136,6 +136,12 @@ func (a *Account) SignTx(net netmode.Magic, t *transaction.Transaction) error { return nil } +// CanSign returns true when account is not locked and has a decrypted private +// key inside, so it's ready to create real signatures. +func (a *Account) CanSign() bool { + return !a.Locked && a.privateKey != nil +} + // GetVerificationScript returns account's verification script. func (a *Account) GetVerificationScript() []byte { if a.Contract != nil { diff --git a/pkg/wallet/account_test.go b/pkg/wallet/account_test.go index eeaa9a3f8..2d0a798df 100644 --- a/pkg/wallet/account_test.go +++ b/pkg/wallet/account_test.go @@ -86,6 +86,7 @@ func TestContract_MarshalJSON(t *testing.T) { func TestContractSignTx(t *testing.T) { acc, err := NewAccount() require.NoError(t, err) + require.True(t, acc.CanSign()) accNoContr := *acc accNoContr.Contract = nil @@ -100,6 +101,7 @@ func TestContractSignTx(t *testing.T) { acc2, err := NewAccount() require.NoError(t, err) + require.True(t, acc2.CanSign()) require.Error(t, acc2.SignTx(0, tx)) @@ -135,10 +137,12 @@ func TestContractSignTx(t *testing.T) { require.Equal(t, 66, len(tx.Scripts[0].InvocationScript)) acc2.Locked = true + require.False(t, acc2.CanSign()) require.Error(t, acc2.SignTx(0, tx)) // Locked account. acc2.Locked = false acc2.privateKey = nil + require.False(t, acc2.CanSign()) require.Error(t, acc2.SignTx(0, tx)) // No private key. tx.Scripts = append(tx.Scripts, transaction.Witness{