2020-08-11 12:10:01 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2020-11-03 10:02:39 +00:00
|
|
|
containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/container"
|
2020-08-11 12:10:01 +00:00
|
|
|
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2021-05-21 07:45:15 +00:00
|
|
|
const (
|
|
|
|
deleteContainerMethod = "delete"
|
|
|
|
putContainerMethod = "put"
|
|
|
|
)
|
|
|
|
|
2020-08-11 12:10:01 +00:00
|
|
|
// Process new container from the user by checking container sanity
|
|
|
|
// and sending approve tx back to morph.
|
|
|
|
func (cp *Processor) processContainerPut(put *containerEvent.Put) {
|
2021-03-23 15:20:44 +00:00
|
|
|
if !cp.alphabetState.IsAlphabet() {
|
|
|
|
cp.log.Info("non alphabet mode, ignore container put")
|
2020-08-11 12:10:01 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-03 10:02:39 +00:00
|
|
|
cnrData := put.Container()
|
|
|
|
|
|
|
|
// unmarshal container structure
|
2020-11-16 10:26:35 +00:00
|
|
|
cnr := containerSDK.New()
|
|
|
|
if err := cnr.Unmarshal(cnrData); err != nil {
|
2020-11-03 10:02:39 +00:00
|
|
|
cp.log.Info("could not unmarshal container structure",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// perform format check
|
|
|
|
if err := container.CheckFormat(cnr); err != nil {
|
|
|
|
cp.log.Info("container with incorrect format detected",
|
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:45:15 +00:00
|
|
|
err := cp.morphClient.NotaryInvoke(cp.containerContract, cp.feeProvider.SideChainFee(), putContainerMethod,
|
|
|
|
cnrData,
|
|
|
|
put.Signature(),
|
2021-05-19 14:16:48 +00:00
|
|
|
put.PublicKey())
|
2020-08-11 12:10:01 +00:00
|
|
|
if err != nil {
|
|
|
|
cp.log.Error("can't invoke new container", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 16:04:29 +00:00
|
|
|
|
|
|
|
// Process delete container operation from the user by checking container sanity
|
|
|
|
// and sending approve tx back to morph.
|
|
|
|
func (cp *Processor) processContainerDelete(delete *containerEvent.Delete) {
|
2021-03-23 15:20:44 +00:00
|
|
|
if !cp.alphabetState.IsAlphabet() {
|
|
|
|
cp.log.Info("non alphabet mode, ignore container delete")
|
2020-09-02 16:04:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:45:15 +00:00
|
|
|
err := cp.morphClient.NotaryInvoke(cp.containerContract, cp.feeProvider.SideChainFee(), deleteContainerMethod,
|
|
|
|
delete.ContainerID(),
|
|
|
|
delete.Signature())
|
2020-09-02 16:04:29 +00:00
|
|
|
if err != nil {
|
|
|
|
cp.log.Error("can't invoke delete container", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|