-
Notifications
You must be signed in to change notification settings - Fork 77
/
node.go
54 lines (48 loc) · 1.23 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package notary
import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"go.uber.org/zap"
)
// UpdateNotaryNodes implements Notary interface and updates current notary account.
func (n *Notary) UpdateNotaryNodes(notaryNodes keys.PublicKeys) {
n.accMtx.Lock()
defer n.accMtx.Unlock()
if n.currAccount != nil {
for _, node := range notaryNodes {
if node.Equal(n.currAccount.PublicKey()) {
return
}
}
}
var acc *wallet.Account
for _, node := range notaryNodes {
acc = n.wallet.GetAccount(node.GetScriptHash())
if acc != nil {
if acc.CanSign() {
break
}
err := acc.Decrypt(n.Config.MainCfg.UnlockWallet.Password, n.wallet.Scrypt)
if err != nil {
n.Config.Log.Warn("can't unlock notary node account",
zap.String("address", address.Uint160ToString(acc.Contract.ScriptHash())),
zap.Error(err))
acc = nil
}
break
}
}
n.currAccount = acc
if acc == nil {
n.reqMtx.Lock()
n.requests = make(map[util.Uint256]*request)
n.reqMtx.Unlock()
}
}
func (n *Notary) getAccount() *wallet.Account {
n.accMtx.RLock()
defer n.accMtx.RUnlock()
return n.currAccount
}