[#807] ir: Merge ContractProcessor and NotaryContractProcessor interfaces

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-09-08 11:28:41 +03:00 committed by Pavel Karpy
parent 539da27ccb
commit ba77bb44e4
9 changed files with 94 additions and 44 deletions

View file

@ -10,39 +10,39 @@ import (
const emitMethod = "emit"
func (np *Processor) processEmit() {
index := np.irList.AlphabetIndex()
func (ap *Processor) processEmit() {
index := ap.irList.AlphabetIndex()
if index < 0 {
np.log.Info("non alphabet mode, ignore gas emission event")
ap.log.Info("non alphabet mode, ignore gas emission event")
return
}
contract, ok := np.alphabetContracts.GetByIndex(index)
contract, ok := ap.alphabetContracts.GetByIndex(index)
if !ok {
np.log.Debug("node is out of alphabet range, ignore gas emission event",
ap.log.Debug("node is out of alphabet range, ignore gas emission event",
zap.Int("index", index))
return
}
// there is no signature collecting, so we don't need extra fee
err := np.morphClient.Invoke(contract, 0, emitMethod)
err := ap.morphClient.Invoke(contract, 0, emitMethod)
if err != nil {
np.log.Warn("can't invoke alphabet emit method")
ap.log.Warn("can't invoke alphabet emit method")
return
}
if np.storageEmission == 0 {
np.log.Info("storage node emission is off")
if ap.storageEmission == 0 {
ap.log.Info("storage node emission is off")
return
}
networkMap, err := np.netmapClient.Snapshot()
networkMap, err := ap.netmapClient.Snapshot()
if err != nil {
np.log.Warn("can't get netmap snapshot to emit gas to storage nodes",
ap.log.Warn("can't get netmap snapshot to emit gas to storage nodes",
zap.String("error", err.Error()))
return
@ -50,27 +50,27 @@ func (np *Processor) processEmit() {
ln := len(networkMap.Nodes)
if ln == 0 {
np.log.Debug("empty network map, do not emit gas")
ap.log.Debug("empty network map, do not emit gas")
return
}
gasPerNode := fixedn.Fixed8(np.storageEmission / uint64(ln))
gasPerNode := fixedn.Fixed8(ap.storageEmission / uint64(ln))
for i := range networkMap.Nodes {
keyBytes := networkMap.Nodes[i].PublicKey()
key, err := keys.NewPublicKeyFromBytes(keyBytes, elliptic.P256())
if err != nil {
np.log.Warn("can't convert node public key to address",
ap.log.Warn("can't convert node public key to address",
zap.String("error", err.Error()))
continue
}
err = np.morphClient.TransferGas(key.GetScriptHash(), gasPerNode)
err = ap.morphClient.TransferGas(key.GetScriptHash(), gasPerNode)
if err != nil {
np.log.Warn("can't transfer gas",
ap.log.Warn("can't transfer gas",
zap.String("receiver", key.Address()),
zap.Int64("amount", int64(gasPerNode)),
zap.String("error", err.Error()),