mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 13:38:35 +00:00
43e4d3af88
1. Initialization is performed via `Blockchain` methods. 2. Native Oracle contract updates list of oracle nodes and in-fly requests in `PostPersist`. 3. RPC uses Oracle module directly.
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
package oracle
|
|
|
|
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/smartcontract"
|
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// UpdateOracleNodes updates oracle nodes list.
|
|
func (o *Oracle) UpdateOracleNodes(oracleNodes keys.PublicKeys) {
|
|
o.accMtx.Lock()
|
|
defer o.accMtx.Unlock()
|
|
|
|
old := o.oracleNodes
|
|
if isEqual := len(old) == len(oracleNodes); isEqual {
|
|
for i := range old {
|
|
if !old[i].Equal(oracleNodes[i]) {
|
|
isEqual = false
|
|
break
|
|
}
|
|
}
|
|
if isEqual {
|
|
return
|
|
}
|
|
}
|
|
|
|
var acc *wallet.Account
|
|
for i := range oracleNodes {
|
|
acc = o.wallet.GetAccount(oracleNodes[i].GetScriptHash())
|
|
if acc != nil {
|
|
if acc.PrivateKey() != nil {
|
|
break
|
|
}
|
|
err := acc.Decrypt(o.MainCfg.UnlockWallet.Password)
|
|
if err != nil {
|
|
o.Log.Error("can't unlock account",
|
|
zap.String("address", address.Uint160ToString(acc.Contract.ScriptHash())),
|
|
zap.Error(err))
|
|
o.currAccount = nil
|
|
return
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
o.currAccount = acc
|
|
o.oracleSignContract, _ = smartcontract.CreateDefaultMultiSigRedeemScript(oracleNodes)
|
|
o.oracleNodes = oracleNodes
|
|
}
|
|
|
|
func (o *Oracle) getAccount() *wallet.Account {
|
|
o.accMtx.RLock()
|
|
defer o.accMtx.RUnlock()
|
|
return o.currAccount
|
|
}
|
|
|
|
func (o *Oracle) getOracleNodes() keys.PublicKeys {
|
|
o.accMtx.RLock()
|
|
defer o.accMtx.RUnlock()
|
|
return o.oracleNodes
|
|
}
|
|
|
|
func (o *Oracle) getOracleSignContract() []byte {
|
|
o.accMtx.RLock()
|
|
defer o.accMtx.RUnlock()
|
|
return o.oracleSignContract
|
|
}
|