mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-04-01 23:58:15 +00:00
wallet: add (*Account).CanSign API
This commit is contained in:
parent
8b132cba0c
commit
fe50879bb7
2 changed files with 10 additions and 0 deletions
|
@ -136,6 +136,12 @@ func (a *Account) SignTx(net netmode.Magic, t *transaction.Transaction) error {
|
||||||
return nil
|
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.
|
// GetVerificationScript returns account's verification script.
|
||||||
func (a *Account) GetVerificationScript() []byte {
|
func (a *Account) GetVerificationScript() []byte {
|
||||||
if a.Contract != nil {
|
if a.Contract != nil {
|
||||||
|
|
|
@ -86,6 +86,7 @@ func TestContract_MarshalJSON(t *testing.T) {
|
||||||
func TestContractSignTx(t *testing.T) {
|
func TestContractSignTx(t *testing.T) {
|
||||||
acc, err := NewAccount()
|
acc, err := NewAccount()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.True(t, acc.CanSign())
|
||||||
|
|
||||||
accNoContr := *acc
|
accNoContr := *acc
|
||||||
accNoContr.Contract = nil
|
accNoContr.Contract = nil
|
||||||
|
@ -100,6 +101,7 @@ func TestContractSignTx(t *testing.T) {
|
||||||
|
|
||||||
acc2, err := NewAccount()
|
acc2, err := NewAccount()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.True(t, acc2.CanSign())
|
||||||
|
|
||||||
require.Error(t, acc2.SignTx(0, tx))
|
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))
|
require.Equal(t, 66, len(tx.Scripts[0].InvocationScript))
|
||||||
|
|
||||||
acc2.Locked = true
|
acc2.Locked = true
|
||||||
|
require.False(t, acc2.CanSign())
|
||||||
require.Error(t, acc2.SignTx(0, tx)) // Locked account.
|
require.Error(t, acc2.SignTx(0, tx)) // Locked account.
|
||||||
|
|
||||||
acc2.Locked = false
|
acc2.Locked = false
|
||||||
acc2.privateKey = nil
|
acc2.privateKey = nil
|
||||||
|
require.False(t, acc2.CanSign())
|
||||||
require.Error(t, acc2.SignTx(0, tx)) // No private key.
|
require.Error(t, acc2.SignTx(0, tx)) // No private key.
|
||||||
|
|
||||||
tx.Scripts = append(tx.Scripts, transaction.Witness{
|
tx.Scripts = append(tx.Scripts, transaction.Witness{
|
||||||
|
|
Loading…
Add table
Reference in a new issue