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