forked from TrueCloudLab/neoneo-go
wallet: drop publicKey from Account
It's not very useful and it's only available when we have a private key anyway.
This commit is contained in:
parent
53edbd569f
commit
a30e73a0d7
3 changed files with 13 additions and 11 deletions
|
@ -1,7 +1,6 @@
|
|||
package wallet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
|
@ -21,9 +20,6 @@ type Account struct {
|
|||
// NEO private key.
|
||||
privateKey *keys.PrivateKey
|
||||
|
||||
// NEO public key.
|
||||
publicKey []byte
|
||||
|
||||
// NEO public address.
|
||||
Address string `json:"address"`
|
||||
|
||||
|
@ -160,8 +156,6 @@ func (a *Account) Decrypt(passphrase string, scrypt keys.ScryptParams) error {
|
|||
return err
|
||||
}
|
||||
|
||||
a.publicKey = a.privateKey.PublicKey().Bytes()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -208,9 +202,13 @@ func (a *Account) ConvertMultisig(m int, pubs []*keys.PublicKey) error {
|
|||
if a.Locked {
|
||||
return errors.New("account is locked")
|
||||
}
|
||||
if a.privateKey == nil {
|
||||
return errors.New("account key is not available (need to decrypt?)")
|
||||
}
|
||||
var found bool
|
||||
accKey := a.privateKey.PublicKey()
|
||||
for i := range pubs {
|
||||
if bytes.Equal(a.publicKey, pubs[i].Bytes()) {
|
||||
if accKey.Equal(pubs[i]) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
@ -240,7 +238,6 @@ func NewAccountFromPrivateKey(p *keys.PrivateKey) *Account {
|
|||
pubAddr := p.Address()
|
||||
|
||||
a := &Account{
|
||||
publicKey: pubKey.Bytes(),
|
||||
privateKey: p,
|
||||
Address: pubAddr,
|
||||
Contract: &Contract{
|
||||
|
|
|
@ -185,6 +185,13 @@ func TestAccount_ConvertMultisig(t *testing.T) {
|
|||
require.Error(t, a.ConvertMultisig(1, pubs))
|
||||
a.Locked = false
|
||||
})
|
||||
t.Run("no private key", func(t *testing.T) {
|
||||
pk := a.privateKey
|
||||
a.privateKey = nil
|
||||
pubs := convertPubs(t, hexs)
|
||||
require.Error(t, a.ConvertMultisig(0, pubs))
|
||||
a.privateKey = pk
|
||||
})
|
||||
t.Run("invalid number of signatures", func(t *testing.T) {
|
||||
pubs := convertPubs(t, hexs)
|
||||
require.Error(t, a.ConvertMultisig(0, pubs))
|
||||
|
@ -223,7 +230,7 @@ func compareFields(t *testing.T, tk keytestcases.Ktype, acc *Account) {
|
|||
require.Equalf(t, want, have, "expected address %s got %s", want, have)
|
||||
want, have = tk.Wif, acc.privateKey.WIF()
|
||||
require.Equalf(t, want, have, "expected wif %s got %s", want, have)
|
||||
want, have = tk.PublicKey, hex.EncodeToString(acc.publicKey)
|
||||
want, have = tk.PublicKey, hex.EncodeToString(acc.privateKey.PublicKey().Bytes())
|
||||
require.Equalf(t, want, have, "expected pub key %s got %s", want, have)
|
||||
want, have = tk.PrivateKey, acc.privateKey.String()
|
||||
require.Equalf(t, want, have, "expected priv key %s got %s", want, have)
|
||||
|
|
|
@ -48,7 +48,6 @@ func TestAddAccount(t *testing.T) {
|
|||
|
||||
wallet.AddAccount(&Account{
|
||||
privateKey: nil,
|
||||
publicKey: nil,
|
||||
Address: "real",
|
||||
EncryptedWIF: "",
|
||||
Label: "",
|
||||
|
@ -77,7 +76,6 @@ func TestSave(t *testing.T) {
|
|||
|
||||
wallet.AddAccount(&Account{
|
||||
privateKey: nil,
|
||||
publicKey: nil,
|
||||
Address: "",
|
||||
EncryptedWIF: "",
|
||||
Label: "",
|
||||
|
|
Loading…
Reference in a new issue